-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwiki.php
More file actions
1990 lines (1662 loc) · 70.8 KB
/
wiki.php
File metadata and controls
1990 lines (1662 loc) · 70.8 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
/*
Plugin Name: PS-Wiki
Plugin URI: https://cp-psource.github.io/wiki/
Description: Ein simples aber mächtiges Wiki-Plugin für Deine ClassicPress Seite, inkl. Multisitesupport, Frontend-Editor, Rechtemanagment.
Author: DerN3rd (PSOURCE)
Version: 1.3.8
Author URI: https://github.com/cp-psource
Text Domain: ps-wiki
*/
/*
Copyright 2019-2024 PSOURCE (https://github.com/cp-psource)
Author - Der N3rd
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by
the Free Software Foundation.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require 'psource/psource-plugin-update/plugin-update-checker.php';
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
$myUpdateChecker = PucFactory::buildUpdateChecker(
'https://github.com/cp-psource/ps-wiki',
__FILE__,
'ps-wiki'
);
//Set the branch that contains the stable release.
$myUpdateChecker->setBranch('master');
class Wiki {
// @var string Aktuelle Version
var $version = '1.3.8';
// @var string Der DB Prefix
var $db_prefix = '';
// @var string Die Plugin Einstellungen
var $settings = array();
// @var string Der für Wiki-Tags zu verwendende Slug
var $slug_tags = 'tags';
// @var string Der für Wiki-Kategorien zu verwendende Slug
var $slug_categories = 'categories';
// @var string Das Verzeichnis, in dem sich dieses Plugin befindet
var $plugin_dir = '';
// @var string Die Basis-URL des Plugins
var $plugin_url = '';
/**
* Bezieht sich auf unsere einzelne Instanz der Klasse
*
* @since 1.2.5
* @access private
*/
private static $_instance = null;
/**
* Ruft die einzelne Instanz der Klasse ab
*
* @since 1.2.5
* @access public
*/
public static function get_instance() {
if ( is_null(self::$_instance) ) {
self::$_instance = new Wiki();
}
return self::$_instance;
}
/**
* Konstruktorfunktion
*
* @since 1.2.5
* @access private
*/
private function __construct() {
$this->init_vars();
add_action('init', array(&$this, 'init'));
add_action('init', array(&$this, 'maybe_flush_rewrites'), 999);
//add_action('current_screen', function(){ echo get_current_screen()->id; });
add_action('wpmu_new_blog', array(&$this, 'new_blog'), 10, 6);
add_action('admin_print_styles-settings_page_wiki', array(&$this, 'admin_styles'));
add_action('admin_print_scripts-settings_page_wiki', array(&$this, 'admin_scripts'));
add_action('add_meta_boxes_psource_wiki', array(&$this, 'meta_boxes') );
add_action('wp_insert_post', array(&$this, 'save_wiki_meta'), 10, 2 );
add_action('widgets_init', array(&$this, 'widgets_init'));
add_action('pre_post_update', array(&$this, 'send_notifications'), 50, 1);
add_filter('the_content', array(&$this, 'theme'), 999); //auf wirklich niedrige Priorität gesetzt. Wir möchten, dass dies nach allen anderen Filtern ausgeführt wird, da es sonst zu unerwünschten Ausgaben kommen kann.
add_action('template_include', array(&$this, 'load_templates') );
add_filter('name_save_pre', array(&$this, 'name_save'));
add_filter('role_has_cap', array(&$this, 'role_has_cap'), 10, 3);
add_filter('user_has_cap', array(&$this, 'user_has_cap'), 10, 3);
add_filter('get_edit_post_link', array(&$this, 'get_edit_post_link'));
add_filter('comments_open', array(&$this, 'comments_open'), 10, 1);
add_filter('user_can_richedit', array(&$this, 'user_can_richedit'));
add_filter('wp_title', array(&$this, 'wp_title'), 10, 3);
add_filter('the_title', array(&$this, 'the_title'), 10, 2);
add_filter('404_template', array(&$this, 'not_found_template'));
add_action('pre_get_posts', array( &$this, 'pre_get_posts'));
add_filter('request', array(&$this, 'request'));
add_filter('body_class', array(&$this, 'body_class'), 10);
add_action('wp_enqueue_scripts', array( &$this, 'wp_enqueue_scripts'), 10);
}
/**
* Wird beim Hinzufügen eines neuen Blogs in Multisite ausgeführt
*
* @param int $blog_id
* @param int $user_id,
* @param string $domain
* @param string $path
* @param int $site_id
* @param array $meta
*/
function new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
if ( is_plugin_active_for_network('ps-wiki/wiki.php') )
$this->setup_blog($blog_id);
}
/**
* Holt sich den Tabellennamen mit Präfixen
*
* @param string $table Tabellenname
* @uses $wpdb
* @return string Tabellenname komplett mit Präfixen
*/
function tablename($table) {
global $wpdb;
return $wpdb->base_prefix.'wiki_'.$table;
}
/**
* Plugin-Variablen initialisieren
* @since 1.2.4
*/
function init_vars() {
global $wpdb;
$this->db_prefix = ( !empty($wpdb->base_prefix) ) ? $wpdb->base_prefix : $wpdb->prefix;
$this->plugin_dir = plugin_dir_path(__FILE__);
$this->plugin_url = plugin_dir_url(__FILE__);
}
function request( $query_vars ) {
if (!is_admin() && isset($query_vars['post_type']) && 'psource_wiki' == $query_vars['post_type'] && (isset($query_vars['orderby']) && $query_vars['orderby'] == 'menu_order title') && $query_vars['posts_per_page'] == '-1') {
$query_vars['orderby'] = 'menu_order';
unset($query_vars['posts_per_page']);
unset($query_vars['posts_per_archive_page']);
return $query_vars;
}
return $query_vars;
}
function the_title( $title, $id = false ) {
global $wp_query, $post;
if (!$id && get_query_var('post_type') == 'psource_wiki' && $wp_query->is_404) {
$post_type_object = get_post_type_object( get_query_var('post_type') );
if (current_user_can($post_type_object->cap->publish_posts)) {
return ucwords(get_query_var('name'));
}
}
return $title;
}
function body_class($classes) {
if (get_query_var('post_type') == 'psource_wiki') {
if (!in_array('psource_wiki', $classes)) {
$classes[] = 'psource_wiki';
}
if (is_singular() && !in_array('single-psource_wiki', $classes)) {
$classes[] = 'single-psource_wiki';
}
}
return $classes;
}
function not_found_template( $path ) {
global $wp_query;
if ( 'psource_wiki' != get_query_var('post_type') )
return $path;
$post_type_object = get_post_type_object( get_query_var('post_type') );
if (current_user_can($post_type_object->cap->publish_posts)) {
$type = reset( explode( '_', current_filter() ) );
$file = basename( $path );
if ( empty( $path ) || "$type.php" == $file ) {
// Eine spezifischere Vorlage wurde nicht gefunden, lade daher die Standardvorlage
$path = $this->plugin_dir . "default-templates/$type-psource_wiki.php";
}
if ( file_exists( get_stylesheet_directory() . "/$type-psource_wiki.php" ) ) {
$path = get_stylesheet_directory() . "/$type-psource_wiki.php";
}
}
return $path;
}
function load_templates( $template ) {
global $wp_query, $post;
if ( is_single() && 'psource_wiki' == get_post_type() ) {
// Sucht nach benutzerdefinierten Designvorlagen im Theme
$wiki_name = $post->post_name;
$wiki_id = (int) $post->ID;
$templates = array('psource_wiki.php');
if ( $wiki_name )
$templates[] = "psource_wiki-$wiki_name.php";
if ( $wiki_id )
$templates[] = "psource_wiki-$wiki_id.php";
if ( $new_template = locate_template($templates) ) {
remove_filter('the_content', array(&$this, 'theme'), 1);
return $new_template;
}
// Fallback: Plugin-Template verwenden
$plugin_template = $this->plugin_dir . 'default-templates/psource_wiki.php';
if ( file_exists($plugin_template) ) {
remove_filter('the_content', array(&$this, 'theme'), 1);
return $plugin_template;
}
}
return $template;
}
function pre_get_posts( $query ) {
if( $query->is_main_query() && !is_admin() && !empty($query->query_vars['psource_wiki']) && preg_match('/\//', $query->query_vars['psource_wiki']) == 0 ) {
$query->query_vars['post_parent'] = 0;
}
}
function user_can_richedit($wp_rich_edit) {
global $wp_query;
if (get_query_var('post_type') == 'psource_wiki') {
return true;
}
return $wp_rich_edit;
}
/**
* Überprüft, ob Neuschreibungen geleert werden sollten, und löscht sie
*
* @since 1.2.4
*/
function maybe_flush_rewrites() {
if ( !get_option('wiki_flush_rewrites') )
return;
flush_rewrite_rules();
delete_option('wiki_flush_rewrites');
}
function comments_open($open) {
global $wp_query, $psource_tab_check;
$action = isset($_REQUEST['action'])?$_REQUEST['action']:'view';
if (get_query_var('post_type') == 'psource_wiki' && ($action != 'discussion')) {
if ($psource_tab_check == 0 && !isset($_POST['submit']) && !isset($_POST['Submit'])) {
return false;
}
}
return $open;
}
function wp_title($title, $sep, $seplocation) {
global $post, $wp_query;
$tmp_title = "";
$bc = 0;
if (!$post && get_query_var('post_type') == 'psource_wiki' && $wp_query->is_404) {
$post_type_object = get_post_type_object( get_query_var('post_type') );
if (current_user_can($post_type_object->cap->publish_posts)) {
$tmp_title = ucwords(get_query_var('name'));
if ($seplocation == 'left') {
$title = " {$sep} {$tmp_title}";
}
if ($seplocation == 'right') {
$title = " {$tmp_title} {$sep} ";
}
}
} else {
if (isset($post->ancestors) && is_array($post->ancestors)) {
foreach($post->ancestors as $parent_pid) {
if ($bc >= $this->settings['breadcrumbs_in_title']) {
break;
}
$parent_post = get_post($parent_pid);
if ($seplocation == 'left') {
$tmp_title .= " {$sep} ";
}
$tmp_title .= $parent_post->post_title;
if ($seplocation == 'right') {
$tmp_title .= " {$sep} ";
}
$bc++;
}
}
$tmp_title = trim($tmp_title);
if (!empty($tmp_title)) {
if ($seplocation == 'left') {
$title = "{$title} {$tmp_title} ";
}
if ($seplocation == 'right') {
$title .= " {$tmp_title} ";
}
}
}
return $title;
}
/**
* Benennt $_POST-Daten von Formularnamen in DB-Post-Spalten um.
*
* Manipuliert $_POST direkt.
*
* @package ClassicPress
* @since 2.6.0
*
* @param bool $update Aktualisieren wir einen bereits bestehenden Beitrag?
* @param array $post_data Array von Post-Daten. Standardmäßig der Inhalt von $_POST.
* @return object|bool WP_Error bei Fehler, true bei Erfolg.
*/
function _translate_postdata( $update = false, $post_data = null ) {
if ( empty($post_data) )
$post_data = &$_POST;
if ( $update )
$post_data['ID'] = (int) $post_data['post_ID'];
$post_data['post_content'] = isset($post_data['content']) ? $post_data['content'] : '';
$post_data['post_excerpt'] = isset($post_data['excerpt']) ? $post_data['excerpt'] : '';
$post_data['post_parent'] = isset($post_data['parent_id'])? $post_data['parent_id'] : '';
if ( isset($post_data['trackback_url']) )
$post_data['to_ping'] = $post_data['trackback_url'];
if ( !isset($post_data['user_ID']) )
$post_data['user_ID'] = $GLOBALS['user_ID'];
if (!empty ( $post_data['post_author_override'] ) ) {
$post_data['post_author'] = (int) $post_data['post_author_override'];
} else {
if (!empty ( $post_data['post_author'] ) ) {
$post_data['post_author'] = (int) $post_data['post_author'];
} else {
$post_data['post_author'] = (int) $post_data['user_ID'];
}
}
$ptype = get_post_type_object( $post_data['post_type'] );
if ( isset($post_data['user_ID']) && ($post_data['post_author'] != $post_data['user_ID']) ) {
if ( !current_user_can( $ptype->cap->edit_others_posts ) ) {
if ( 'page' == $post_data['post_type'] ) {
return new WP_Error( 'edit_others_pages', $update ?
__( 'Du darfst als dieser Benutzer keine Seiten bearbeiten.', 'ps-wiki' ) :
__( 'Du darfst als dieser Benutzer keine Seiten erstellen.', 'ps-wiki' )
);
} else {
return new WP_Error( 'edit_others_posts', $update ?
__( 'Du darfst als dieser Benutzer keine Beiträge bearbeiten.', 'ps-wiki' ) :
__( 'Du darfst nicht als dieser Benutzer posten.', 'ps-wiki' )
);
}
}
}
// What to do based on which button they pressed
if ( isset($post_data['saveasdraft']) && '' != $post_data['saveasdraft'] )
$post_data['post_status'] = 'draft';
if ( isset($post_data['saveasprivate']) && '' != $post_data['saveasprivate'] )
$post_data['post_status'] = 'private';
if ( isset($post_data['publish']) && ( '' != $post_data['publish'] ) && ( !isset($post_data['post_status']) || $post_data['post_status'] != 'private' ) )
$post_data['post_status'] = 'publish';
if ( isset($post_data['advanced']) && '' != $post_data['advanced'] )
$post_data['post_status'] = 'draft';
if ( isset($post_data['pending']) && '' != $post_data['pending'] )
$post_data['post_status'] = 'pending';
if ( isset( $post_data['ID'] ) )
$post_id = $post_data['ID'];
else
$post_id = false;
$previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;
// Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published.
// Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( $ptype->cap->publish_posts )) )
if ( $previous_status != 'publish' || !current_user_can( 'edit_post', $post_id ) )
$post_data['post_status'] = 'pending';
if ( ! isset($post_data['post_status']) )
$post_data['post_status'] = $previous_status;
if (!isset( $post_data['comment_status'] ))
$post_data['comment_status'] = 'closed';
if (!isset( $post_data['ping_status'] ))
$post_data['ping_status'] = 'closed';
foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
if ( !empty( $post_data['hidden_' . $timeunit] ) && $post_data['hidden_' . $timeunit] != $post_data[$timeunit] ) {
$post_data['edit_date'] = '1';
break;
}
}
if ( !empty( $post_data['edit_date'] ) ) {
$aa = $post_data['aa'];
$mm = $post_data['mm'];
$jj = $post_data['jj'];
$hh = $post_data['hh'];
$mn = $post_data['mn'];
$ss = $post_data['ss'];
$aa = ($aa <= 0 ) ? date('Y') : $aa;
$mm = ($mm <= 0 ) ? date('n') : $mm;
$jj = ($jj > 31 ) ? 31 : $jj;
$jj = ($jj <= 0 ) ? date('j') : $jj;
$hh = ($hh > 23 ) ? $hh -24 : $hh;
$mn = ($mn > 59 ) ? $mn -60 : $mn;
$ss = ($ss > 59 ) ? $ss -60 : $ss;
$post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
$post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
}
return $post_data;
}
/**
* Aktualisiert einen vorhandenen Beitrag mit den in $_POST bereitgestellten Werten.
*
* @since 1.5.0
*
* @param array $post_data Optional.
* @return int Post ID.
*/
function edit_post( $post_data = null ) {
if ( empty($post_data) )
$post_data = &$_POST;
$post_ID = (int) $post_data['post_ID'];
$ptype = get_post_type_object($post_data['post_type']);
if ( !current_user_can( $ptype->cap->edit_post, $post_ID ) ) {
if ( 'page' == $post_data['post_type'] )
wp_die( __('Du bist nicht berechtigt, diese Seite zu bearbeiten.', 'ps-wiki' ));
else
wp_die( __('Du bist nicht berechtigt, diesen Beitrag zu bearbeiten.', 'ps-wiki' ));
}
// Autosave sollte nicht zu früh nach einem echten Save speichern
if ( 'autosave' == $post_data['action'] ) {
$post =& get_post( $post_ID );
$now = time();
$then = strtotime($post->post_date_gmt . ' +0000');
$delta = AUTOSAVE_INTERVAL / 2;
if ( ($now - $then) < $delta )
return $post_ID;
}
$post_data = $this->_translate_postdata( true, $post_data );
$post_data['post_status'] = 'publish';
if ( is_wp_error($post_data) )
wp_die( $post_data->get_error_message() );
if ( 'autosave' != $post_data['action'] && 'auto-draft' == $post_data['post_status'] )
$post_data['post_status'] = 'draft';
if ( isset($post_data['visibility']) ) {
switch ( $post_data['visibility'] ) {
case 'public' :
$post_data['post_password'] = '';
break;
case 'password' :
unset( $post_data['sticky'] );
break;
case 'private' :
$post_data['post_status'] = 'private';
$post_data['post_password'] = '';
unset( $post_data['sticky'] );
break;
}
}
// Beitragsformate
if ( current_theme_supports( 'post-formats' ) && isset( $post_data['post_format'] ) ) {
$formats = get_theme_support( 'post-formats' );
if ( is_array( $formats ) ) {
$formats = $formats[0];
if ( in_array( $post_data['post_format'], $formats ) ) {
set_post_format( $post_ID, $post_data['post_format'] );
} elseif ( '0' == $post_data['post_format'] ) {
set_post_format( $post_ID, false );
}
}
}
// Meta-Zeug
if ( isset($post_data['meta']) && $post_data['meta'] ) {
foreach ( $post_data['meta'] as $key => $value ) {
if ( !$meta = get_post_meta_by_id( $key ) )
continue;
if ( $meta->post_id != $post_ID )
continue;
update_meta( $key, $value['key'], $value['value'] );
}
}
if ( isset($post_data['deletemeta']) && $post_data['deletemeta'] ) {
foreach ( $post_data['deletemeta'] as $key => $value ) {
if ( !$meta = get_post_meta_by_id( $key ) )
continue;
if ( $meta->post_id != $post_ID )
continue;
delete_meta( $key );
}
}
// add_meta( $post_ID );
update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
wp_update_post( $post_data );
// Vereinigt alle verwaisten Anhänge wieder mit ihren Eltern
if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
$draft_ids = array();
if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )
_relocate_children( $draft_temp_id, $post_ID );
$this->set_post_lock( $post_ID, $GLOBALS['current_user']->ID );
if ( current_user_can( $ptype->cap->edit_others_posts ) ) {
if ( ! empty( $post_data['sticky'] ) )
stick_post( $post_ID );
else
unstick_post( $post_ID );
}
return $post_ID;
}
function theme( $content ) {
global $post;
if ( !is_single() || 'psource_wiki' != get_post_type() )
return $content;
if ( post_password_required() )
return $content;
if ( function_exists('is_main_query') && !is_main_query() )
return $content;
$revision_id = isset($_REQUEST['revision'])?absint($_REQUEST['revision']):0;
$left = isset($_REQUEST['left'])?absint($_REQUEST['left']):0;
$right = isset($_REQUEST['right'])?absint($_REQUEST['right']):0;
$action = isset($_REQUEST['action'])?$_REQUEST['action']:'view';
$new_content = '';
if ($action != 'edit') {
$new_content .= '<div class="psource_wiki psource_wiki_single">';
if ( isset($_GET['restored']) ) {
$new_content .= '<div class="psource_wiki_message">' . __('Revision erfolgreich wiederhergestellt', 'ps-wiki') . ' <a class="dismiss" href="#">x</a></div>';
}
$new_content .= '<div class="psource_wiki_tabs psource_wiki_tabs_top">' . $this->tabs() . '<div class="psource_wiki_clear"></div></div>';
$new_content .= $this->decider($content, $action, $revision_id, $left, $right);
} else {
$new_content .= $this->get_edit_form(false);
}
if ( !comments_open() ) {
$new_content .= '<style type="text/css">'.
'#comments { display: none; }'.
'.comments { display: none; }'.
'</style>';
} else {
$new_content .= '<style type="text/css">'.
'.hentry { margin-bottom: 5px; }'.
'</style>';
}
return $new_content;
}
function decider($content, $action, $revision_id = null, $left = null, $right = null, $stray_close = true) {
global $post;
$new_content = '';
switch ($action) {
case 'discussion':
break;
case 'edit':
set_include_path(get_include_path().PATH_SEPARATOR.ABSPATH.'wp-admin');
$post_type_object = get_post_type_object($post->post_type);
$p = $post;
if ( empty($post->ID) )
wp_die( __('Du hast versucht, ein nicht vorhandenes Element zu bearbeiten. Vielleicht wurde es gelöscht?', 'ps-wiki' ) );
if ( !current_user_can($post_type_object->cap->edit_post, $post->ID) )
wp_die( __('Du bist nicht berechtigt, dieses Element zu bearbeiten.', 'ps-wiki' ) );
if ( 'trash' == $post->post_status )
wp_die( __('Du kannst dieses Element nicht bearbeiten, da es sich im Papierkorb befindet. Bitte stelle es wieder her und versuche es erneut.', 'ps-wiki' ) );
if ( null == $post_type_object )
wp_die( __('Unbekannter Beitragstyp.') );
$post_type = $post->post_type;
if ( $last = $this->check_post_lock( $post->ID ) ) {
add_action('admin_notices', '_admin_notice_post_locked' );
} else {
$this->set_post_lock( $post->ID );
wp_enqueue_script('autosave');
}
$title = $post_type_object->labels->edit_item;
$post = $this->post_to_edit($post->ID);
$new_content = $this->get_edit_form(false);
break;
case 'restore':
if ( ! $revision = wp_get_post_revision( $revision_id ) )
break;
if ( ! current_user_can( 'edit_post', $revision->post_parent ) )
break;
if ( ! $post = get_post( $revision->post_parent ) )
break;
// Überarbeitungen deaktiviert und wir betrachten keine automatische Speicherung
if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
$redirect = get_permalink().'?action=edit';
break;
}
check_admin_referer( "restore-post_$post->ID|$revision->ID" );
wp_restore_post_revision( $revision->ID );
$redirect = add_query_arg('restored', 1, get_permalink());
break;
case 'diff':
if ( !$left_revision = get_post( $left ) ) {
break;
}
if ( !$right_revision = get_post( $right ) ) {
break;
}
// Wenn wir eine Überarbeitung mit sich selbst vergleichen, leiten sie zur Ansichtsseite für diese Überarbeitung oder zur Bearbeitungsseite für diesen Beitrag weiter
if ( $left_revision->ID == $right_revision->ID ) {
$redirect = get_permalink().'?action=edit';
break;
}
// Reverse Diffs nicht zulassen?
if ( strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) {
$redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) );
break;
}
if ( $left_revision->ID == $right_revision->post_parent ) // Rechts ist eine Überarbeitung von Links
$post =& $left_revision;
elseif ( $left_revision->post_parent == $right_revision->ID ) // Links ist eine Überarbeitung von Rechts
$post =& $right_revision;
elseif ( $left_revision->post_parent == $right_revision->post_parent ) // beide sind Revisionen des gemeinsamen Elternteils
$post = get_post( $left_revision->post_parent );
else
break; // Vergleiche nicht zwei unabhängige Revisionen
if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) { // Revisions disabled
if (
// Wir sehen uns kein Autosave an
( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
||
// Wir vergleichen eine automatische Speicherung nicht mit dem aktuellen Beitrag
( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )
) {
$redirect = get_permalink().'?action=edit';
break;
}
}
if (
// Sie sind gleich
$left_revision->ID == $right_revision->ID
||
// Auch keine Überarbeitung
( !wp_get_post_revision( $left_revision->ID ) && !wp_get_post_revision( $right_revision->ID ) )
) {
break;
}
$post_title = '<a href="' . get_permalink().'?action=edit' . '">' . get_the_title() . '</a>';
$h2 = sprintf( __( 'Vergleiche Revisionen von “%1$s”', 'wiki' ), $post_title );
$title = __( 'Revisionen' );
$left = $left_revision->ID;
$right = $right_revision->ID;
case 'history':
$args = array( 'format' => 'form-table', 'parent' => false, 'right' => $right, 'left' => $left );
if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) {
$args['type'] = 'autosave';
}
if (!isset($h2)) {
$post_title = '<a href="' . get_permalink().'?action=edit' . '">' . get_the_title() . '</a>';
$revisions = wp_get_post_revisions( $post->ID );
$revision = array_shift($revisions);
$revision_title = wp_post_revision_title( $revision, false );
$h2 = sprintf( __( 'Revision für “%1$s” erstellt am %2$s', 'wiki' ), $post_title, $revision_title );
}
$new_content .= '<h3 class="long-header">'.$h2.'</h3>';
$new_content .= '<table class="form-table ie-fixed">';
$new_content .= '<col class="th" />';
if ( 'diff' == $action ) :
$new_content .= '<tr id="revision">';
$new_content .= '<th scope="row"></th>';
$new_content .= '<th scope="col" class="th-full">';
$new_content .= '<span class="alignleft">'.sprintf( __('Älter: %s', 'wiki'), wp_post_revision_title( $left_revision, false ) ).'</span>';
$new_content .= '<span class="alignright">'.sprintf( __('Neuer: %s', 'wiki'), wp_post_revision_title( $right_revision, false ) ).'</span>';
$new_content .= '</th>';
$new_content .= '</tr>';
endif;
// get_post_to_edit-Filter verwenden?
$identical = true;
foreach ( _wp_post_revision_fields() as $field => $field_title ) :
if ( 'diff' == $action ) {
$left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision->ID );
$right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision->ID );
if ( !$rcontent = wp_text_diff( $left_content, $right_content ) )
continue; // Es gibt keinen Unterschied zwischen links und rechts
$identical = false;
} else {
add_filter( "_wp_post_revision_field_$field", 'htmlspecialchars' );
$rcontent = apply_filters( "_wp_post_revision_field_$field", $revision->$field, $field, $revision->ID );
}
$new_content .= '<tr id="revision-field-' . $field . '">';
$new_content .= '<th scope="row" style="width: auto; max-width: 45px;">'.esc_html( $field_title ).'</th>';
$new_content .= '<td><div class="pre">'.$rcontent.'</div></td>';
$new_content .= '</tr>';
endforeach;
if ( 'diff' == $action && $identical ) :
$new_content .= '<tr><td colspan="2"><div class="updated"><p>'.__( 'Diese Revisionen sind identisch.', 'wiki' ). '</p></div></td></tr>';
endif;
$new_content .= '</table>';
$new_content .= '<br class="clear" />';
$new_content .= '<div class="psource_wiki_revisions">' . $this->list_post_revisions( $post, $args ) . '</div>';
$redirect = false;
break;
default:
$top = "";
$crumbs = array('<a href="'.home_url($this->settings['slug']).'" class="psource_wiki_crumbs">'.$this->settings['wiki_name'].'</a>');
foreach($post->ancestors as $parent_pid) {
$parent_post = get_post($parent_pid);
$crumbs[] = '<a href="'.get_permalink($parent_pid).'" class="psource_wiki_crumbs">'.$parent_post->post_title.'</a>';
}
$crumbs[] = '<span class="psource_wiki_crumbs">'.$post->post_title.'</span>';
sort($crumbs);
$top .= join(get_option("psource_meta_seperator", " > "), $crumbs);
$taxonomy = "";
if ( class_exists('Wiki_Premium') ) {
$category_list = get_the_term_list( 0, 'psource_wiki_category', __( 'Wiki-Kategorie:', 'ps-wiki' ) . ' <span class="psource_wiki-category">', '', '</span> ' );
$tags_list = get_the_term_list( 0, 'psource_wiki_tag', __( 'Tags:', 'ps-wiki' ) . ' <span class="psource_wiki-tags">', ' ', '</span> ' );
$taxonomy .= apply_filters('the_terms', $category_list, 'psource_wiki_category', __( 'Wiki-Kategorie:', 'ps-wiki' ) . ' <span class="psource_wiki-category">', '', '</span> ' );
$taxonomy .= apply_filters('the_terms', $tags_list, 'psource_wiki_tag', __( 'Tags:', 'ps-wiki' ) . ' <span class="psource_wiki-tags">', ' ', '</span> ' );
}
$children = get_posts(array(
'post_parent' => $post->ID,
'post_type' => 'psource_wiki',
'orderby' => $this->settings['sub_wiki_order_by'],
'order' => $this->settings['sub_wiki_order'],
'numberposts' => 100000
));
$crumbs = array();
foreach($children as $child) {
$crumbs[] = '<a href="'.get_permalink($child->ID).'" class="psource_wiki_crumbs">'.$child->post_title.'</a>';
}
$bottom = "<h3>" . $this->settings['sub_wiki_name'] . "</h3> <ul><li>";
$bottom .= join("</li><li>", $crumbs);
if (count($crumbs) == 0) {
$bottom = $taxonomy;
} else {
$bottom .= "</li></ul>";
$bottom = "{$taxonomy} {$bottom}";
}
$revisions = wp_get_post_revisions($post->ID);
if (current_user_can('edit_wiki', $post->ID)) {
$bottom .= '<div class="psource_wiki-meta">';
if (is_array($revisions) && count($revisions) > 0) {
$revision = array_shift($revisions);
}
$bottom .= '</div>';
}
$notification_meta = get_post_meta($post->ID, 'psource_wiki_email_notification', true);
if ( $notification_meta == 'enabled' && !$this->is_subscribed() ) {
if (is_user_logged_in()) {
$bottom .= '<div class="psource_wiki-subscribe"><a href="'.wp_nonce_url(add_query_arg(array('post_id' => $post->ID, 'subscribe' => 1)), "wiki-subscribe-wiki_$post->ID" ).'">'.__('Benachrichtige mich über Änderungen', 'ps-wiki').'</a></div>';
} else {
if (!empty($_COOKIE['psource_wiki_email'])) {
$user_email = $_COOKIE['psource_wiki_email'];
} else {
$user_email = "";
}
$bottom .= '<div class="psource_wiki-subscribe">'.
'<form action="" method="post">'.
'<label>'.__('E-mail', 'ps-wiki').': <input type="text" name="email" id="email" value="'.$user_email.'" /></label> '.
'<input type="hidden" name="post_id" id="post_id" value="'.$post->ID.'" />'.
'<input type="submit" name="subscribe" id="subscribe" value="'.__('Benachrichtige mich über Änderungen', 'ps-wiki').'" />'.
'<input type="hidden" name="_wpnonce" id="_wpnonce" value="'.wp_create_nonce("wiki-subscribe-wiki_$post->ID").'" />'.
'</form>'.
'</div>';
}
}
$new_content = '<div class="psource_wiki_top">' . $top . '</div>'. $new_content;
$new_content .= '<div class="psource_wiki_content">' . $content . '</div>';
$new_content .= '<div class="psource_wiki_bottom">' . $bottom . '</div>';
$redirect = false;
}
if ($stray_close) {
$new_content .= '</div>';
}
// Ein leerer post_type bedeutet, dass entweder ein falsch formatiertes Objekt gefunden wurde oder kein gültiges übergeordnetes Element gefunden wurde.
if ( isset($redirect) && !$redirect && empty($post->post_type) ) {
$redirect = 'edit.php';
}
if ( !empty($redirect) ) {
echo '<script type="text/javascript">'.
'window.location = "'.$redirect.'";'.
'</script>';
exit;
}
return $new_content;
}
/**
* Standard-Beitragsinformationen, die beim Ausfüllen des Formulars „Beitrag schreiben“ verwendet werden.
*
* @since 1.0.0
*
* @param string $post_type Ein Beitragstyp-String, standardmäßig „post“.
* @return object stdClass-Objekt, das alle standardmäßigen Beitragsdaten als Attribute enthält
*/
function get_default_post_to_edit( $post_type = 'post', $create_in_db = false, $parent_id = 0 ) {
global $wpdb;
$post_title = '';
if ( !empty( $_REQUEST['post_title'] ) )
$post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
$post_content = '';
if ( !empty( $_REQUEST['content'] ) )
$post_content = esc_html( stripslashes( $_REQUEST['content'] ));
$post_excerpt = '';
if ( !empty( $_REQUEST['excerpt'] ) )
$post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
if ( $create_in_db ) {
// Bereinigt alte automatische Entwürfe, die älter als 7 Tage sind
$old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
foreach ( (array) $old_posts as $delete )
wp_delete_post( $delete, true ); // Löschen erzwingen
$post_id = wp_insert_post( array( 'post_parent' => $parent_id, 'post_title' => __( 'Automatischer Entwurf', 'ps-wiki' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
$post = get_post( $post_id );
if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) )
set_post_format( $post, get_option( 'default_post_format' ) );
// Wiki-Privilegien kopieren
$privileges = get_post_meta($post->post_parent, 'psource_wiki_privileges');
update_post_meta($post->ID, 'psource_wiki_privileges', $privileges[0]);
} else {
$post->ID = 0;
$post->post_author = '';
$post->post_date = '';
$post->post_date_gmt = '';
$post->post_password = '';
$post->post_type = $post_type;
$post->post_status = 'draft';
$post->to_ping = '';
$post->pinged = '';
$post->comment_status = get_option( 'default_comment_status' );
$post->ping_status = get_option( 'default_ping_status' );
$post->post_pingback = get_option( 'default_pingback_flag' );
$post->post_category = get_option( 'default_category' );
$post->page_template = 'default';
$post->post_parent = 0;
$post->menu_order = 0;
}
$post->post_content = apply_filters( 'default_content', $post_content, $post );
$post->post_title = apply_filters( 'default_title', $post_title, $post );
$post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );
$post->post_name = '';
return $post;
}
function enqueue_comment_hotkeys_js() {
if ( 'true' == get_user_option( 'comment_shortcuts' ) )
wp_enqueue_script( 'jquery-table-hotkeys' );
}
/**
* Holt sich einen vorhandenen Beitrag und formatiert ihn zur Bearbeitung.
*
* @since 1.0.0
*
* @param unknown_type $id
* @return unknown
*/
function post_to_edit( $id ) {
$post = get_post( $id, OBJECT, 'edit' );
if ( $post->post_type == 'page' )
$post->page_template = get_post_meta( $id, '_wp_page_template', true );
return $post;
}
/**
* Überprüft, ob der Beitrag gerade von einem anderen Benutzer bearbeitet wird.
*
* @since 2.5.0
*
* @param int $post_id ID des Beitrags, der auf Bearbeitung geprüft werden soll
* @return bool|int False: nicht gesperrt oder vom aktuellen Benutzer gesperrt. Int: Benutzer-ID des Benutzers mit Sperre.
*/
function check_post_lock( $post_id ) {
if ( !$post = get_post( $post_id ) )
return false;
if ( !$lock = get_post_meta( $post->ID, '_edit_lock', true ) )
return false;
$lock = explode( ':', $lock );
$time = $lock[0];
$user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true );
$time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 );
if ( $time && $time > time() - $time_window && $user != get_current_user_id() )
return $user;
return false;
}