forked from xpressengine/xe-module-wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwiki.view.php
More file actions
1154 lines (1035 loc) · 32.4 KB
/
wiki.view.php
File metadata and controls
1154 lines (1035 loc) · 32.4 KB
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
/**
* @class wikiView
* @developer NHN (developers@xpressengine.com)
* @brief wiki module View class
*/
class WikiView extends Wiki
{
var $list;
var $search_option = array('title', 'content', 'title_content', 'comment', 'user_name', 'nick_name', 'user_id', 'tag');
/**
* @brief Class initialization
* @developer NHN (developers@xpressengine.com)
* @access public
* @return void
*/
function init()
{
/*
* Set the path to skins folder
* If current selected skin does not exist, fallback to default skin: xe_wiki
*/
$template_path = sprintf("%sskins/%s/", $this->module_path, $this->module_info->skin);
if(!is_dir($template_path) || !$this->module_info->skin)
{
$this->module_info->skin = 'xe_wiki';
$template_path = sprintf("%sskins/%s/", $this->module_path, $this->module_info->skin);
}
$this->setTemplatePath($template_path);
$oModuleModel = &getModel('module');
$document_config = $oModuleModel->getModulePartConfig('document', $this->module_info->module_srl);
if(!isset($document_config->use_history))
{
$document_config->use_history = 'N';
}
$this->use_history = $document_config->use_history;
Context::set('use_history', $document_config->use_history);
Context::addJsFile($this->module_path . 'tpl/js/wiki.js');
Context::set('grant', $this->grant);
Context::set('langs', Context::loadLangSupported());
// Force simple textarea if markup is Markdown, Google Code or MediaWiki
$editor_config = $oModuleModel->getModulePartConfig('editor', $this->module_info->module_srl);
if($this->module_info->markup_type != 'xe_wiki_markup'
&& (!$editor_config || $editor_config->sel_editor_colorset != 'white_text_usehtml'))
{
$editor_config->editor_skin = 'xpresseditor';
$editor_config->sel_editor_colorset = 'white_text_usehtml';
$editor_config->content_style = 'default';
$oModuleController = &getController('module');
$oModuleController->insertModulePartConfig('editor', $this->module_info->module_srl, $editor_config);
}
// Load wiki title
if(!isset($this->module_info->title))
{
$this->module_info->title = $this->module_info->browser_title;
}
// Load left side tree, if tree skin is used
if($this->module_info->skin == 'xe_wiki_tree')
{
$this->getLeftMenu();
}
$security = new Security($this->module_info);
$security->encodeHTML('title');
}
/**
* @brief Displays wiki document view
* @developer NHN (developers@xpressengine.com)
* @access public
* @return
*/
function dispWikiContent()
{
$output = $this->dispWikiContentView();
if(!$output->toBool())
{
return ;
}
}
/**
* @brief Displays the history of the particular wiki page
* @developer NHN (developers@xpressengine.com)
* @access public
* @return Object
*/
function dispWikiHistory()
{
$oDocumentModel = &getModel('document');
$document_srl = Context::get('document_srl');
$page = Context::get('page');
$entry = Context::get('entry');
if(!$document_srl)
{
if(!$entry)
{
$oWikiModel = &getModel('wiki');
$root = $oWikiModel->getRootDocument($this->module_info->module_srl);
$document_srl = $root->document_srl;
$entry = $oDocumentModel->getAlias($document_srl);
Context::set('entry', $entry);
Context::set('document_srl', $document_srl);
}
$document_srl = $oDocumentModel->getDocumentSrlByAlias($this->module_info->mid, $entry);
if(!$document_srl)
{
$document_srl = $oDocumentModel->getDocumentSrlByTitle($this->module_info->module_srl, $entry);
}
}
$oDocument = $oDocumentModel->getDocument($document_srl);
if(!$oDocument->isExists())
{
return $this->stop('msg_invalid_request');
}
$output = $oDocumentModel->getHistories($document_srl, 10, $page);
if(!$output->toBool() || !$output->data)
{
Context::set('histories', array());
}
else
{
Context::set('histories', $output->data);
Context::set('page', $output->page);
Context::set('page_navigation', $output->page_navigation);
}
Context::set('oDocument', $oDocument);
$this->setTemplateFile('document_histories');
$security = new Security();
$security->encodeHTML('histories..nick_name');
return new Object(0, 'success');
}
/**
* @return Object
*/
function dispWikiHistoryCompare()
{
$old_history_srl = Context::get('old_history_srl');
$history_srl = Context::get('history_srl');
$document_srl = Context::get('document_srl');
if(!$old_history_srl || !$document_srl)
{
return new Object(-1, 'msg_invalid_request');
}
$oDocumentModel = &getModel('document');
$oDocument = $oDocumentModel->getDocument($document_srl);
Context::set('oDocument', $oDocument);
$entry = $oDocumentModel->getAlias($document_srl);
Context::set('entry', $entry);
// Set up old version
$output = $oDocumentModel->getHistory($old_history_srl);
$old_version = new stdClass;
$old_version->content = $output->content;
$old_version->regdate = $output->regdate;
// Set up new version (can be either history or document itself)
$new_version = new stdClass;
if(!$history_srl || $history_srl == $document_srl)
{
$new_version->content = $oDocument->get('content');
$new_version->regdate = $oDocument->get('last_update');
}
else
{
$output = $oDocumentModel->getHistory($history_srl);
$new_version->content = $output->content;
$new_version->regdate = $output->regdate;
}
// Include the diff class
require_once dirname(__FILE__).'/lib/Diff.php';
// Initialize the diff class
$a = explode("\n", str_replace("\r", '', $old_version->content));
$b = explode("\n", str_replace("\r", '', $new_version->content));
$diff = new Diff($a, $b, array());
// Generate a side by side diff
require_once dirname(__FILE__).'/lib/Diff/Renderer/Html/SideBySide.php';
$renderer = new Diff_Renderer_Html_SideBySide;
$diff_html = $diff->Render($renderer);
if($diff_html == "")
{
$diff_html = Context::getLang('diff_no_differences');
}
else
{
// Table header is hardcoded in the Renderer class, so we need to customize it
$old_version_header = Context::getLang('diff_old_version');
$old_version_header .= '<br />';
$old_version_header .= zdate($old_version->regdate, 'Y.m.d H:i:s');
$diff_html = str_replace("Old Version", $old_version_header, $diff_html);
$new_version_header = Context::getLang('diff_new_version');
$new_version_header .= '<br />';
$new_version_header .= zdate($new_version->regdate, 'Y.m.d H:i:s');
$diff_html = str_replace("New Version", $new_version_header, $diff_html);
}
Context::set('old_version', $old_version);
Context::set('new_version', $new_version);
Context::set('diff_html', $diff_html);
$this->setTemplateFile('document_compare');
return new Object(0, 'success');
}
/**
* @brief Document editing screen
* @developer NHN (developers@xpressengine.com)
* @access public
* @return Object
*/
function dispWikiEditPage()
{
if(!$this->grant->write_document)
{
return $this->dispWikiMessage('msg_not_permitted');
}
$oDocumentModel = & getModel('document');
$document_srl = Context::get('document_srl');
$entry = Context::get('entry');
$section = Context::get('section');
if(!$document_srl)
{
$mid = Context::get('mid');
$document_srl = $oDocumentModel->getDocumentSrlByAlias($mid, $entry);
}
$oDocument = $oDocumentModel->getDocument(0, $this->grant->manager);
$oDocument->setDocument($document_srl);
$oDocument->add('module_srl', $this->module_srl);
if($oDocument->isExists())
{
// Set up document alias
$oDocument->add('alias', $oDocumentModel->getAlias($document_srl));
// Prepare doc_srl of latest edit made to this document - used for
// preventing content override when more than one user edits a the same document
$output = $oDocumentModel->getHistories($document_srl, 1, 1);
if($output->toBool() && $output->data)
{
$history = array_pop($output->data);
$latest_doc_edit = $history->history_srl;
Context::set('latest_doc_edit', $latest_doc_edit);
}
// Update content, when paragraph edit is used
if (isset($section))
{
require_once $this->module_path . 'lib/WikiText.class.php';
$content = $oDocument->get('content');
$lang = $this->module_info->markup_type;
if ($lang == 'mediawiki_markup') $lang = 'wikitext';
elseif ($lang == 'googlecode_markup') $lang = 'googlecode';
//markdown stays markdown
elseif ($lang == 'xe_wiki_markup') $lang = 'xewiki';
$wt = new WTParser($content, $lang);
$paragraph = $wt->getText((int)$section);
$oDocument->add('content', $paragraph);
}
}
else
{
$oDocument->add('title', $entry);
$alias = $this->beautifyEntryName($entry);
$oDocument->add('alias', $alias);
}
Context::set('document_srl', $document_srl);
Context::set('oDocument', $oDocument);
// Document status list
$statusNameList = $this->_getStatusNameList();
if(count($statusNameList) > 0) Context::set('status_list', $statusNameList);
$history_srl = Context::get('history_srl');
if($history_srl)
{
$output = $oDocumentModel->getHistory($history_srl);
if($output && $output->content != NULL)
{
Context::set('history', $output);
$security = new Security();
$security->encodeHTML('history.nick_name');
}
}
$this->setTemplateFile('document_edit');
return new Object(0, 'success');
}
/**
* @brief Displaying custom error / succes message
* @developer NHN (developers@xpressengine.com)
* @access public
* @param $msg_code string
* @return Object
*/
function dispWikiMessage($msg_code)
{
$msg = Context::getLang($msg_code);
if(!$msg)
{
$msg = $msg_code;
}
Context::set('message', $msg);
$this->setTemplateFile('message');
return new Object(0, 'success');
}
/**
* @brief View a list of wiki's articles
* @developer NHN (developers@xpressengine.com)
* @access public
* @return Object
*/
function dispWikiTitleIndex()
{
$page = Context::get('page');
$oDocumentModel = &getModel('document');
$obj->module_srl = $this->module_info->module_srl;
$obj->sort_index = 'update_order';
$obj->page = $page;
$obj->list_count = 50;
$obj->search_keyword = Context::get('search_keyword');
$obj->search_target = Context::get('search_target');
$output = $oDocumentModel->getDocumentList($obj);
if($output->data)
{
foreach($output->data as $no => $val)
{
$alias = $oDocumentModel->getAlias($val->document_srl);
$output->data[$no]->add('alias', $alias);
}
}
Context::set('document_list', $output->data);
Context::set('total_count', $output->total_count);
Context::set('total_page', $output->total_page);
Context::set('page', $output->page);
Context::set('page_navigation', $output->page_navigation);
// search options settings
foreach($this->search_option as $opt)
{
$search_option[$opt] = Context::getLang($opt);
}
Context::set('search_option', $search_option);
$this->setTemplateFile('title_index');
return new Object(0, 'success');
}
/**
* @brief hierarchical view of the appropriate wiki
* @developer NHN (developers@xpressengine.com)
* @access public
* @return Object
*/
function dispWikiTreeIndex()
{
$oWikiModel = &getModel('wiki');
Context::set('document_tree', $oWikiModel->readWikiTreeCache($this->module_srl));
$this->setTemplateFile('tree_list');
$security = new Security();
$security->encodeHTML('document_tree..');
return new Object(0, 'success');
}
/**
* @brief Display screen for changing the hierarchy
* @developer NHN (developers@xpressengine.com)
* @access public
* @return Object
*/
function dispWikiModifyTree()
{
if(!$this->grant->write_document)
{
return new Object(-1, 'msg_not_permitted');
}
Context::set('isManageGranted', $this->grant->write_document ? 'true' : 'false');
$this->setTemplateFile('modify_tree');
return new Object(0, 'success');
}
/**
* @brief View update history
* @developer NHN (developers@xpressengine.com)
* @access private
* @param $entry Document alias
* @return void
*/
function addToVisitLog($entry)
{
$module_srl = $this->module_info->module_srl;
if(!$_SESSION['wiki_visit_log'])
{
$_SESSION['wiki_visit_log'] = array();
}
if(!$_SESSION['wiki_visit_log'][$module_srl] || !is_array($_SESSION['wiki_visit_log'][$module_srl]))
{
$_SESSION['wiki_visit_log'][$module_srl] = array();
}
else
{
foreach($_SESSION['wiki_visit_log'][$module_srl] as $key => $value)
{
if($value == $entry)
{
unset($_SESSION['wiki_visit_log'][$module_srl][$key]);
}
}
if(count($_SESSION['wiki_visit_log'][$module_srl]) >= 5)
{
array_shift($_SESSION['wiki_visit_log'][$module_srl]);
}
}
$_SESSION['wiki_visit_log'][$module_srl][] = $entry;
}
/**
* @brief Wiki document view
* @developer NHN (developers@xpressengine.com)
* @access public
* @return Object
*/
function dispWikiContentView()
{
$oWikiModel = &getModel('wiki');
$oDocumentModel = &getModel('document');
// The requested order parameter values
$document_srl = Context::get('document_srl');
$entry = Context::get('entry');
if(!$document_srl)
{
if(!$entry)
{
$root = $oWikiModel->getRootDocument($this->module_info->module_srl);
if(!is_null($root))
{
$document_srl = $root->document_srl;
$entry = $oDocumentModel->getAlias($document_srl);
Context::set('entry', $entry);
}
else
{
$visitingAnEmptyWiki = TRUE;
}
}
$document_srl = $oDocumentModel->getDocumentSrlByAlias($this->module_info->mid, $entry);
if(!$document_srl)
{
$document_srl = $oDocumentModel->getDocumentSrlByTitle($this->module_info->module_srl, $entry);
}
}
else if(!$entry)
{
$entry = $oDocumentModel->getAlias($document_srl);
Context::set('entry', $entry);
}
/*
* Check if exists document_srl for requested document
*/
if($document_srl)
{
$oDocument = $oDocumentModel->getDocument($document_srl);
if($oDocument->isExists())
{
// Load next and previous documents before parsing content, otherwise extra_vars are overriden
list($prev_document_srl, $next_document_srl) = $oWikiModel->getPrevNextDocument($this->module_srl, $document_srl);
if($prev_document_srl)
{
Context::set('oDocumentPrev', $oDocumentModel->getDocument($prev_document_srl));
}
if($next_document_srl)
{
Context::set('oDocumentNext', $oDocumentModel->getDocument($next_document_srl));
}
$this->addToVisitLog($entry);
$this->_handleWithExistingDocument($oDocument);
}
else
{
Context::set('document_srl', '', TRUE);
return new Object(-1, 'msg_not_founded');
}
} // generate an empty document object if you do not have a document_srl for requested document
else
{
$oDocument = $oDocumentModel->getDocument(0);
}
// View posts by checking permissions or display an error message if you do not have permission
if($oDocument->isExists())
{
// add page title to the browser title
Context::addBrowserTitle($oDocument->getTitleText());
// Increase in hits (if document has permissions)
if(!$oDocument->isSecret() || $oDocument->isGranted())
{
$oDocument->updateReadedCount();
}
// Not showing the content if it is secret
if($oDocument->isSecret() && !$oDocument->isGranted())
{
$oDocument->add('content', Context::getLang('thisissecret'));
}
$this->setTemplateFile('document_view');
// set contributors
if($this->use_history)
{
$contributors = $oWikiModel->getContributors($oDocument->document_srl);
Context::set('contributors', $contributors);
}
// If the document has no rights set for comments is forced to use
if($this->module_info->use_comment != 'N')
{
$oDocument->add('allow_comment', 'Y');
}
// Set up alias
$alias = $oDocumentModel->getAlias($oDocument->document_srl);
$oDocument->add('alias', $alias);
// Put root element in context
$root = $oWikiModel->getRootDocument($this->module_info->module_srl);
Context::set('root', $root);
}
else
{
// Document was not found
// If user is for the first time on this wiki and there is no document in the entire site
// show a friendly message
if($visitingAnEmptyWiki)
{
$title = Context::getLang('create_first_page_title');
if($this->module_info->markup_type == 'markdown') {
$content = Context::getLang('create_first_page_markdown_help');
$wiki_parser = $this->getWikiTextParser();
$content = $wiki_parser->parse($content);
}
else {
$content = Context::getLang('create_first_page_description');
}
$oDocument->add('title', $title);
$alias = $this->beautifyEntryName($title);
$oDocument->add('alias', $alias);
$oDocument->add('content', $content);
}
// Otherwise, show the usual message
else
{
$content = Context::getLang('not_exist');
$oDocument->add('title', $entry);
$alias = $this->beautifyEntryName($entry);
$oDocument->add('alias', $alias);
$oDocument->add('content', $content);
}
$this->setTemplateFile('document_not_found');
}
Context::set('visit_log', $_SESSION['wiki_visit_log'][$this->module_info->module_srl]);
// Setting a value oDocument for being use in skins
Context::set('oDocument', $oDocument);
Context::set('entry', $alias);
// get translated language for current document
$translatedlangs = $oDocument->getTranslationLangCodes();
$arr_translation_langs = array();
foreach($translatedlangs as $langs)
{
$arr_translation_langs[] = $langs->lang_code;
}
Context::set("translatedlangs", $arr_translation_langs);
$this->getBreadCrumbs((int)$oDocument->document_srl);
// Redirect to user friendly URL if request comes from Search
$error_return_url = Context::get('error_return_url');
if(isset($error_return_url))
{
$site_module_info = Context::get('site_module_info');
if($document_srl)
{
$url = getSiteUrl($site_module_info->document, '', 'mid', $this->module_info->mid, 'entry', $oDocument->get('alias'), 'document_srl', '');
}
else
{
$url = getSiteUrl($site_module_info->document, '', 'mid', $this->module_info->mid, 'entry', $entry, 'document_srl', '');
}
$this->setRedirectUrl($url);
}
return new Object(0, 'success');
}
/**
* @brief Display screen for posting a comment
* @developer NHN (developers@xpressengine.com)
* @access public
* @return Object
*/
function dispWikiReplyComment()
{
// Check permission
if(!$this->grant->write_comment)
{
return $this->dispWikiMessage('msg_not_permitted');
}
// Produces a list of variables needed to implement
$parent_srl = Context::get('comment_srl');
// Return message error if there is no parent_srl
if(!$parent_srl)
{
return new Object(-1, 'msg_invalid_request');
}
// Look for the comment
$oCommentModel = &getModel('comment');
$oSourceComment = $oCommentModel->getComment($parent_srl, $this->grant->manager);
// If there is no reply error
if(!$oSourceComment->isExists())
{
return $this->dispWikiMessage('msg_invalid_request');
}
if(Context::get('document_srl') && $oSourceComment->get('document_srl') != Context::get('document_srl'))
{
return $this->dispWikiMessage('msg_invalid_request');
}
// Generate the target comment
$oComment = $oCommentModel->getComment();
$oComment->add('parent_srl', $parent_srl);
$oComment->add('document_srl', $oSourceComment->get('document_srl'));
// Set the necessary informations
Context::set('oSourceComment', $oSourceComment);
Context::set('oComment', $oComment);
$this->setTemplateFile('comment_edit');
return new Object(0, 'success');
}
/**
* @brief Modify comment page
* @developer NHN (developers@xpressengine.com)
* @access public
* @return Object
*/
function dispWikiModifyComment()
{
// Check persmission
if(!$this->grant->write_comment)
{
return $this->dispWikiMessage('msg_not_permitted');
}
// Produce a list of variables needed to implement
$document_srl = Context::get('document_srl');
$comment_srl = Context::get('comment_srl');
// If you do not have error for specified comment
if(!$comment_srl)
{
return new Object(-1, 'msg_invalid_request');
}
// Look for the comment
$oCommentModel = &getModel('comment');
$oComment = $oCommentModel->getComment($comment_srl, $this->grant->manager);
// If there is no reply error
if(!$oComment->isExists())
{
return $this->dispWikiMessage('msg_invalid_request');
}
// If the article does not have permission then display the password input screen
if(!$oComment->isGranted())
{
return $this->setTemplateFile('input_password_form');
}
// Set the necessary informations
Context::set('oSourceComment', $oCommentModel->getComment());
Context::set('oComment', $oComment);
$this->setTemplateFile('comment_edit');
return new Object(0, 'success');
}
/**
* @brief Delete comment form
* @developer NHN (developers@xpressengine.com)
* @access public
* @return Object
*/
function dispWikiDeleteComment()
{
// Check permission
if(!$this->grant->write_comment)
{
return $this->dispWikiMessage('msg_not_permitted');
}
// Produce a list of variables needed to implement
$comment_srl = Context::get('comment_srl');
// If you do not have error for specified comment
if($comment_srl)
{
$oCommentModel = &getModel('comment');
$oComment = $oCommentModel->getComment($comment_srl, $this->grant->manager);
}
// If there is no reply error
if(!$oComment->isExists())
{
return $this->dispWikiContent();
}
// If the article does not have permission then display the password input screen
if(!$oComment->isGranted())
{
return $this->setTemplateFile('input_password_form');
}
Context::set('oComment', $oComment);
$this->setTemplateFile('delete_comment_form');
return new Object(0, 'success');
}
/**
* @brief Add comment view - used for loading comment form via ajax
* @developer Bogdan Bajanica (xe_dev@arnia.ro)
* @access public
* @return Object
*/
function dispCommentEditor()
{
// allow only logged in users to comment.
if(!Context::get('is_logged'))
{
return new Object(-1, 'login_to_comment');
}
$document_srl = Context::get('document_srl');
$oDocumentModel = &getModel("document");
$oDocument = $oDocumentModel->getDocument($document_srl);
if(!$oDocument->isExists())
{
return new Object(-1, 'msg_invalid_request');
}
if(!$oDocument->allowComment())
{
return new Object(-1, 'comments_disabled');
}
Context::set('oDocument', $oDocument);
$oModuleModel = &getModel('module');
$module_info = $oModuleModel->getModuleInfoByModuleSrl($oDocument->get('module_srl'));
Context::set("module_info", $module_info);
$module_path = './modules/' . $module_info->module . '/';
$skin_path = $module_path . 'skins/' . $module_info->skin . '/';
if(!$module_info->skin || !is_dir($skin_path))
{
$skin_path = $module_path . 'skins/xe_wiki/';
}
$oTemplateHandler = TemplateHandler::getInstance();
$this->add('html', $oTemplateHandler->compile($skin_path, 'comment_edit.html'));
return new Object(0, 'success');
}
/**
* @brief Perpares document for display and loads any extra data needed
* @developer NHN (developers@xpressengine.com)
* @access private
* @param $oDocument
* @return void
*/
function _handleWithExistingDocument(&$oDocument)
{
// Display error message if it is a different module than requested module
if($oDocument->get('module_srl') != $this->module_info->module_srl)
{
$this->stop('msg_invalid_request');
return;
}
// Check if you have administrative authority to grant
if($this->grant->manager)
{
$oDocument->setGrant();
}
// Check if history is enable and get Document history otherwise ignore it
$history_srl = Context::get('history_srl');
if($history_srl)
{
$oDocumentModel = & getModel('document'); $output = $oDocumentModel->getHistory($history_srl);
if($output && $output->content != NULL)
{
Context::set('history', $output);
}
}
$content = $oDocument->getContent(FALSE, FALSE, FALSE, FALSE);
$content = $this->_renderWikiContent($oDocument->document_srl, $content);
// Retrieve documents that link here and that this doc links to
$oWikiModel = &getModel('wiki');
$inbound_links = $oWikiModel->getInboundLinks($oDocument->document_srl);
$outbound_links = $oWikiModel->getOutboundLinks($oDocument->document_srl);
$inbound_links_html = '';
foreach($inbound_links as $link)
{
$inbound_links_html .= '<p><a href="' . getUrl('mid', $this->module_info->mid, 'entry', $link->alias, 'document_srl', '') . '">' . $link->title . '</a> </p>';
}
if($inbound_links_html != '')
{
$inbound_links_html = '<div id="wikiInboundLinks" class="wikiLinks"><p><strong>' . Context::getLang('pages_that_link_to_this') . '</strong></p>' . $inbound_links_html . '</div>';
}
$outbound_links_html = '';
foreach($outbound_links as $link)
{
$outbound_links_html .= '<p><a href="' . getUrl('mid', $this->module_info->mid, 'entry', $link->alias, 'document_srl', '') . '">' . $link->title . '</a></p>';
}
if($outbound_links_html != '')
{
$outbound_links_html = '<div id="wikiOutboundLinks" class="wikiLinks"><p><strong>' . Context::getLang('links_in_this_page') . '</strong></p>' . $outbound_links_html . '</div>';
}
$content .= $inbound_links_html . $outbound_links_html;
$oDocument->add('content', $content);
}
/**
* @brief Parse wiki document syntax
* @developer NHN (developers@xpressengine.com)
* @access private
* @param $document_srl
* @param $org_content original content
* @return string $parsed_content
*/
function _renderWikiContent($document_srl, $org_content)
{
$oCacheHandler = & CacheHandler::getInstance('object', NULL, TRUE);
if($oCacheHandler->isSupport())
{
$object_key = sprintf('%s.%s.php', $document_srl, Context::getLangType());
$cache_key = $oCacheHandler->getGroupKey('wikiContent', $object_key);
$content = $oCacheHandler->get($cache_key);
}
//disable cache here: (true || ...)
if(true || !$content)
{
$wiki_syntax_parser = $this->getWikiTextParser();
$content = $wiki_syntax_parser->parse($org_content);
if($oCacheHandler->isSupport())
{
$oCacheHandler->put($cache_key, $content);
}
}
return $content;
}
/**
* @brief Set list for Tree menu on left side of pages
* @developer Bogdan Bajanica (xe_dev@arnia.ro)
* @access private
* @param $module_srl
* @param $document_srl
* @return void
*/
function _loadSidebarTreeMenu($module_srl, $document_srl)
{
if($document_srl)
{
$oWikiModel = &getModel('wiki');
$this->list = $oWikiModel->getMenuTree($module_srl, $document_srl, $this->module_info->mid);
}
Context::set("list", $this->list);
$security = new Security();
$security->encodeHTML('list..title');
}
/**
* @brief Generate Left menu according with settings from admin panel
* @developer Bogdan Bajanica (xe_dev@arnia.ro)
* @access private
* @return void
*/
function getLeftMenu()
{
$oWikiModel = &getModel("wiki");
$oDocumentModel = &getModel("document");
$module_srl = $this->module_info->module_srl;
// We need to retrieve skin info directly from module model
// because it wasn't yet synced with module_info (this method executes on init)
$oModuleModel = &getModel('module');
$skin_vars = $oModuleModel->getModuleSkinVars($module_srl);
if($skin_vars["menu_style"]->value == "classic")
{
$this->list = $oWikiModel->loadWikiTreeList($module_srl);
Context::set('list', $this->list);
}
else
{
$document_srl = Context::get("document_srl");
$entry = Context::get("entry");
$root = $oWikiModel->getRootDocument($module_srl);
if(!$document_srl)
{
if(!$entry)
{
$document_srl = $root->document_srl;
$entry = $oDocumentModel->getAlias($document_srl);
}
else
{
if(is_null($oDocumentModel->getDocumentSrlByTitle($this->module_info->module_srl, $entry)))
{
$document_srl = $root->document_srl;
$this->_loadSidebarTreeMenu($module_srl, $document_srl);
}
else
{
$this->_loadSidebarTreeMenu($module_srl, $oDocumentModel->getDocumentSrlByAlias($module_srl, $entry));
}
}
$document_srl = $oDocumentModel->getDocumentSrlByAlias($this->module_info->mid, $entry);
$this->_loadSidebarTreeMenu($module_srl, $document_srl);
}
else
{
$this->_loadSidebarTreeMenu($module_srl, $document_srl);
}
}
}
/**
* @brief Generate breadcrumbs
* @developer Bogdan Bajanica (xe_dev@arnia.ro)
* @access private
* @param $document_srl
* @return void
*/
function getBreadCrumbs($document_srl)
{
// get Breadcrumbs menu
$oWikiModel = & getModel("wiki");
$menu_breadcrumbs = $oWikiModel->getBreadcrumbs($document_srl, $this->list);
Context::set('breadcrumbs', $menu_breadcrumbs);
}
/**
* @brief View for displaying search results