/
txp_article.php
1492 lines (1221 loc) · 49 KB
/
txp_article.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 is Textpattern
Copyright 2005 by Dean Allen
All rights reserved.
Use of this software indicates acceptance of the Textpattern license agreement
$HeadURL$
$LastChangedRevision$
*/
if (!defined('txpinterface')) die('txpinterface is undefined.');
global $vars, $statuses;
$vars = array(
'ID','Title','Body','Excerpt','textile_excerpt','Image',
'textile_body', 'Keywords','Status','Posted','Expires','Section','Category1','Category2',
'Annotate','AnnotateInvite','publish_now','reset_time','AuthorID','sPosted',
'LastModID','sLastMod','override_form','from_view','year','month','day','hour',
'minute','second','url_title','exp_year','exp_month','exp_day','exp_hour',
'exp_minute','exp_second','sExpires'
);
$cfs = getCustomFields();
foreach($cfs as $i => $cf_name)
{
$vars[] = "custom_$i";
}
$statuses = array(
STATUS_DRAFT => gTxt('draft'),
STATUS_HIDDEN => gTxt('hidden'),
STATUS_PENDING => gTxt('pending'),
STATUS_LIVE => strong(gTxt('live')),
STATUS_STICKY => gTxt('sticky'),
);
if (!empty($event) and $event == 'article') {
require_privs('article');
$save = gps('save');
if ($save) $step = 'save';
$publish = gps('publish');
if ($publish) $step = 'publish';
if (empty($step)) $step = 'create';
bouncer($step,
array(
'create' => false,
'publish' => true,
'edit' => false,
'save' => true,
'save_pane_state' => true
)
);
switch($step) {
case "create": article_edit(); break;
case "publish": article_post(); break;
case "edit": article_edit(); break;
case "save": article_save(); break;
case "save_pane_state": article_save_pane_state(); break;
}
}
//--------------------------------------------------------------
function article_post()
{
global $txp_user, $vars, $prefs;
extract($prefs);
$incoming = doSlash(textile_main_fields(array_map('assert_string', psa($vars))));
extract($incoming);
$msg = '';
if ($Title or $Body or $Excerpt) {
$Status = assert_int(ps('Status'));
// comments my be on, off, or disabled.
$Annotate = (int) $Annotate;
// set and validate article timestamp
if ($publish_now == 1) {
$when = 'now()';
$when_ts = time();
} else {
if (!is_numeric($year) || !is_numeric($month) || !is_numeric($day) || !is_numeric($hour) || !is_numeric($minute) || !is_numeric($second) ) {
$ts = false;
} else {
$ts = strtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second);
}
if ($ts === false || $ts < 0) { // Tracking the PHP meanders on how to return an error
article_edit(array(gTxt('invalid_postdate'), E_ERROR));
return;
}
$when_ts = $ts - tz_offset($ts);
$when = "from_unixtime($when_ts)";
}
// Force a reasonable 'last modified' date for future articles, keep recent articles list in order
$lastmod = ($when_ts > time() ? 'now()' : $when);
// set and validate expiry timestamp
if (empty($exp_year)) {
$expires = 0;
} else {
if(empty($exp_month)) $exp_month=1;
if(empty($exp_day)) $exp_day=1;
if(empty($exp_hour)) $exp_hour=0;
if(empty($exp_minute)) $exp_minute=0;
if(empty($exp_second)) $exp_second=0;
$ts = strtotime($exp_year.'-'.$exp_month.'-'.$exp_day.' '.$exp_hour.':'.$exp_minute.':'.$exp_second);
if ($ts === false || $ts < 0) {
article_edit(array(gTxt('invalid_expirydate'), E_ERROR));
return;
} else {
$expires = $ts - tz_offset($ts);
}
}
if ($expires && ($expires <= $when_ts)) {
article_edit(array(gTxt('article_expires_before_postdate'), E_ERROR));
return;
}
if ($expires) {
$whenexpires = "Expires=from_unixtime($expires)";
} else {
$whenexpires = "Expires=".NULLDATETIME;
}
$user = doSlash($txp_user);
$Keywords = doSlash(trim(preg_replace('/( ?[\r\n\t,])+ ?/s', ',', preg_replace('/ +/', ' ', ps('Keywords'))), ', '));
$msg = '';
if (!has_privs('article.publish') && $Status >= STATUS_LIVE) $Status = STATUS_PENDING;
if (empty($url_title)) $url_title = stripSpace($Title_plain, 1);
$cfq = array();
$cfs = getCustomFields();
foreach($cfs as $i => $cf_name)
{
$custom_x = "custom_{$i}";
$cfq[] = "custom_$i = '".$$custom_x."'";
}
$cfq = join(', ', $cfq);
$rs = compact($vars);
if (article_validate($rs, $msg)) {
$ok = safe_insert(
"textpattern",
"Title = '$Title',
Body = '$Body',
Body_html = '$Body_html',
Excerpt = '$Excerpt',
Excerpt_html = '$Excerpt_html',
Image = '$Image',
Keywords = '$Keywords',
Status = $Status,
Posted = $when,
Expires = $whenexpires,
AuthorID = '$user',
LastMod = $lastmod,
LastModID = '$user',
Section = '$Section',
Category1 = '$Category1',
Category2 = '$Category2',
textile_body = '$textile_body',
textile_excerpt = '$textile_excerpt',
Annotate = $Annotate,
override_form = '$override_form',
url_title = '$url_title',
AnnotateInvite = '$AnnotateInvite',"
.(($cfs) ? $cfq.',' : '').
"uid = '".md5(uniqid(rand(),true))."',
feed_time = now()"
);
if ($ok) {
$rs['ID'] = $GLOBALS['ID'] = $ok;
if ($Status >= STATUS_LIVE) {
do_pings();
update_lastmod();
}
callback_event('article_posted', '', false, $rs);
$s = check_url_title($url_title);
$msg = array(get_status_message($Status).' '.$s, ($s ? E_WARNING : 0));
} else {
unset($GLOBALS['ID']);
$msg = array(gTxt('article_save_failed'), E_ERROR);
}
}
}
article_edit($msg);
}
//--------------------------------------------------------------
function article_save()
{
global $txp_user, $vars, $prefs, $statuses;
extract($prefs);
$incoming = array_map('assert_string', psa($vars));
$oldArticle = safe_row('Status, url_title, Title, '.
'unix_timestamp(LastMod) as sLastMod, LastModID, '.
'unix_timestamp(Posted) as sPosted, '.
'unix_timestamp(Expires) as sExpires',
'textpattern', 'ID = '.(int)$incoming['ID']);
if (! ( ($oldArticle['Status'] >= STATUS_LIVE and has_privs('article.edit.published'))
or ($oldArticle['Status'] >= STATUS_LIVE and $incoming['AuthorID']==$txp_user and has_privs('article.edit.own.published'))
or ($oldArticle['Status'] < STATUS_LIVE and has_privs('article.edit'))
or ($oldArticle['Status'] < STATUS_LIVE and $incoming['AuthorID']==$txp_user and has_privs('article.edit.own'))))
{
// Not allowed, you silly rabbit, you shouldn't even be here.
// Show default editing screen.
article_edit();
return;
}
if ($oldArticle['sLastMod'] != $incoming['sLastMod'])
{
article_edit(array(gTxt('concurrent_edit_by', array('{author}' => txpspecialchars($oldArticle['LastModID']))), E_ERROR), TRUE, TRUE );
return;
}
$incoming = textile_main_fields($incoming);
extract(doSlash($incoming));
extract(array_map('assert_int', psa(array('ID', 'Status'))));
// comments my be on, off, or disabled.
$Annotate = (int) $Annotate;
if (!has_privs('article.publish') && $Status >= STATUS_LIVE) $Status = STATUS_PENDING;
// set and validate article timestamp
if ($reset_time) {
$whenposted = "Posted=now()";
$when_ts = time();
} else {
if (!is_numeric($year) || !is_numeric($month) || !is_numeric($day) || !is_numeric($hour) || !is_numeric($minute) || !is_numeric($second) ) {
$ts = false;
} else {
$ts = strtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second);
}
if ($ts === false || $ts < 0) {
$when = $when_ts = $oldArticle['sPosted'];
$msg = array(gTxt('invalid_postdate'), E_ERROR);
} else {
$when = $when_ts = $ts - tz_offset($ts);
}
$whenposted = "Posted=from_unixtime($when)";
}
// set and validate expiry timestamp
if (empty($exp_year)) {
$expires = 0;
} else {
if(empty($exp_month)) $exp_month=1;
if(empty($exp_day)) $exp_day=1;
if(empty($exp_hour)) $exp_hour=0;
if(empty($exp_minute)) $exp_minute=0;
if(empty($exp_second)) $exp_second=0;
$ts = strtotime($exp_year.'-'.$exp_month.'-'.$exp_day.' '.$exp_hour.':'.$exp_minute.':'.$exp_second);
if ($ts === false || $ts < 0) {
$expires = $oldArticle['sExpires'];
$msg = array(gTxt('invalid_expirydate'), E_ERROR);
} else {
$expires = $ts - tz_offset($ts);
}
}
if ($expires && ($expires <= $when_ts)) {
$expires = $oldArticle['sExpires'];
$msg = array(gTxt('article_expires_before_postdate'), E_ERROR);
}
if ($expires) {
$whenexpires = "Expires=from_unixtime($expires)";
} else {
$whenexpires = "Expires=".NULLDATETIME;
}
//Auto-Update custom-titles according to Title, as long as unpublished and NOT customized
if ( empty($url_title)
|| ( ($oldArticle['Status'] < STATUS_LIVE)
&& ($oldArticle['url_title'] == $url_title )
&& ($oldArticle['url_title'] == stripSpace($oldArticle['Title'],1))
&& ($oldArticle['Title'] != $Title)
)
)
{
$url_title = stripSpace($Title_plain, 1);
}
$Keywords = doSlash(trim(preg_replace('/( ?[\r\n\t,])+ ?/s', ',', preg_replace('/ +/', ' ', ps('Keywords'))), ', '));
$user = doSlash($txp_user);
$cfq = array();
$cfs = getCustomFields();
foreach($cfs as $i => $cf_name)
{
$custom_x = "custom_{$i}";
$cfq[] = "custom_$i = '".$$custom_x."'";
}
$cfq = join(', ', $cfq);
$rs = compact($vars);
if (article_validate($rs, $msg)) {
if (safe_update("textpattern",
"Title = '$Title',
Body = '$Body',
Body_html = '$Body_html',
Excerpt = '$Excerpt',
Excerpt_html = '$Excerpt_html',
Keywords = '$Keywords',
Image = '$Image',
Status = $Status,
LastMod = now(),
LastModID = '$user',
Section = '$Section',
Category1 = '$Category1',
Category2 = '$Category2',
Annotate = $Annotate,
textile_body = '$textile_body',
textile_excerpt = '$textile_excerpt',
override_form = '$override_form',
url_title = '$url_title',
AnnotateInvite = '$AnnotateInvite',"
.(($cfs) ? $cfq.',' : '').
"$whenposted,
$whenexpires",
"ID = $ID"
)) {
if ($Status >= STATUS_LIVE && $oldArticle['Status'] < STATUS_LIVE) {
do_pings();
}
if ($Status >= STATUS_LIVE || $oldArticle['Status'] >= STATUS_LIVE) {
update_lastmod();
}
callback_event('article_saved', '', false, $rs);
if (empty($msg)) {
$s = check_url_title($url_title);
$msg = array(get_status_message($Status).' '.$s, $s ? E_WARNING : 0);
}
} else {
$msg = array(gTxt('article_save_failed'), E_ERROR);
}
}
article_edit($msg, FALSE, TRUE);
}
//--------------------------------------------------------------
function article_edit($message = '', $concurrent = FALSE, $refresh_partials = FALSE)
{
global $vars, $txp_user, $prefs, $event, $view;
extract($prefs);
/*
$partials is an array of:
$key => array (
'mode' => {PARTIAL_STATIC | PARTIAL_VOLATILE | PARTIAL_VOLATILE_VALUE},
'selector' => $DOM_selector,
'cb' => $callback_function,
'html' => $return_value_of_callback_function (need not be intialized here)
)
*/
$partials = array(
'sLastMod' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '[name=sLastMod]', 'cb' => 'article_partial_value'),
'sPosted' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '[name=sPosted]', 'cb' => 'article_partial_value'),
'sidehelp' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#textfilter_group', 'cb' => 'article_partial_sidehelp'),
'custom_fields' => array('mode' => PARTIAL_STATIC, 'selector' => '#custom_field_group', 'cb' => 'article_partial_custom_fields'),
'image' => array('mode' => PARTIAL_STATIC, 'selector' => '#image_group', 'cb' => 'article_partial_image'),
'keywords' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.keywords', 'cb' => 'article_partial_keywords'),
'keywords_value' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '#keywords', 'cb' => 'article_partial_keywords_value'),
'url_title' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.url-title', 'cb' => 'article_partial_url_title'),
'url_title_value' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '#url-title', 'cb' => 'article_partial_url_title_value'),
'recent_articles' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#recent_group .recent', 'cb' => 'article_partial_recent_articles'),
'title' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.title', 'cb' => 'article_partial_title'),
'title_value' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '#title', 'cb' => 'article_partial_title_value'),
'article_view' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#article_partial_article_view', 'cb' => 'article_partial_article_view'),
'body' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.body', 'cb' => 'article_partial_body'),
'excerpt' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.excerpt', 'cb' => 'article_partial_excerpt'),
'author' => array('mode' => PARTIAL_VOLATILE, 'selector' => 'p.author', 'cb' => 'article_partial_author'),
'view_modes' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#view_modes', 'cb' => 'article_partial_view_modes'),
'article_nav' => array('mode' => PARTIAL_VOLATILE, 'selector' => 'p.nav-tertiary', 'cb' => 'article_partial_article_nav'),
'status' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#write-status', 'cb' => 'article_partial_status'),
'categories' => array('mode' => PARTIAL_STATIC, 'selector' => '#categories_group', 'cb' => 'article_partial_categories'),
'section' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.section', 'cb' => 'article_partial_section'),
'comments' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#write-comments', 'cb' => 'article_partial_comments'),
'posted' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#write-timestamp', 'cb' => 'article_partial_posted'),
'expires' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#write-expires', 'cb' => 'article_partial_expires'),
);
// add partials for custom fields (and their values which is redundant by design, for plugins)
global $cfs;
foreach ($cfs as $k => $v) {
$partials["custom_field_{$k}"] = array('mode' => PARTIAL_STATIC, 'selector' => "p.custom-field.custom-{$k}", 'cb' => 'article_partial_custom_field');
$partials["custom_{$k}"] = array('mode' => PARTIAL_STATIC, 'selector' => "#custom-{$k}", 'cb' => 'article_partial_value');
}
extract(gpsa(array('view','from_view','step')));
if(!empty($GLOBALS['ID'])) { // newly-saved article
$ID = $GLOBALS['ID'];
$step = 'edit';
} else {
$ID = gps('ID');
}
// switch to 'text' view upon page load and after article post
if(!$view || gps('save') || gps('publish')) {
$view = 'text';
}
if (!$step) $step = "create";
if ($step == "edit"
&& $view=="text"
&& !empty($ID)
&& $from_view != 'preview'
&& $from_view != 'html'
&& !$concurrent)
{
$pull = true; //-- it's an existing article - off we go to the db
$ID = assert_int($ID);
$rs = safe_row(
"*, unix_timestamp(Posted) as sPosted,
unix_timestamp(Expires) as sExpires,
unix_timestamp(LastMod) as sLastMod",
"textpattern",
"ID=$ID"
);
if (empty($rs)) return;
$rs['reset_time'] = $rs['publish_now'] = false;
} else {
$pull = false; //-- assume they came from post
if ($from_view=='preview' or $from_view=='html')
{
$store_out = array();
$store = unserialize(base64_decode(ps('store')));
foreach($vars as $var)
{
if (isset($store[$var])) $store_out[$var] = $store[$var];
}
}
else
{
$store_out = gpsa($vars);
if ($concurrent)
{
$store_out['sLastMod'] = safe_field('unix_timestamp(LastMod) as sLastMod', 'textpattern', 'ID='.$ID);
}
}
// Use preferred textfilter as default and fallback
$hasfilter = new TextfilterConstraint(null);
$validator = new Validator();
foreach (array('textile_body', 'textile_excerpt') as $k) {
$hasfilter->setValue($store_out[$k]);
$validator->setConstraints($hasfilter);
if (!$validator->validate()) {
$store_out[$k] = $use_textile;
}
}
$rs = textile_main_fields($store_out);
if (!empty($rs['exp_year']))
{
if(empty($rs['exp_month'])) $rs['exp_month']=1;
if(empty($rs['exp_day'])) $rs['exp_day']=1;
if(empty($rs['exp_hour'])) $rs['exp_hour']=0;
if(empty($rs['exp_minute'])) $rs['exp_minute']=0;
if(empty($rs['exp_second'])) $rs['exp_second']=0;
$rs['sExpires'] = safe_strtotime($rs['exp_year'].'-'.$rs['exp_month'].'-'.$rs['exp_day'].' '.
$rs['exp_hour'].':'.$rs['exp_minute'].':'.$rs['exp_second']);
}
if (!empty($rs['year'])) {
$rs['sPosted'] = safe_strtotime($rs['year'].'-'.$rs['month'].'-'.$rs['day'].' '.
$rs['hour'].':'.$rs['minute'].':'.$rs['second']);
}
}
$validator = new Validator(new SectionConstraint($rs['Section']));
if (!$validator->validate()) {
$rs['Section'] = getDefaultSection();
}
extract($rs);
$GLOBALS['step'] = $step;
if ($step != 'create' && isset($sPosted)) {
// Previous record?
$rs['prev_id'] = checkIfNeighbour('prev',$sPosted);
// Next record?
$rs['next_id'] = checkIfNeighbour('next',$sPosted);
} else {
$rs['prev_id'] = $rs['next_id'] = 0;
}
// let plugins chime in on partials
callback_event_ref('article_ui', 'partials_meta', 0, $rs, $partials);
// get content for volatile partials
foreach ($partials as $k => $p) {
if ($p['mode'] == PARTIAL_VOLATILE || $p['mode'] == PARTIAL_VOLATILE_VALUE) {
$cb = $p['cb'];
$partials[$k]['html'] = (is_array($cb) ? call_user_func($cb, $rs, $k): $cb($rs, $k));
}
}
if ($refresh_partials) {
global $theme;
$response[] = $theme->announce_async($message);
// update the volatile partials
foreach ($partials as $k => $p) {
// volatile partials need a target DOM selector
if (empty($p['selector']) && $p['mode'] != PARTIAL_STATIC) {
trigger_error("Empty selector for partial '$k'", E_USER_ERROR);
} else {
// build response script
if ($p['mode'] == PARTIAL_VOLATILE) {
// volatile partials replace *all* of the existing HTML fragment for their selector
$response[] = '$("'.$p['selector'].'").replaceWith("'.escape_js($p['html']).'")';
} elseif ($p['mode'] == PARTIAL_VOLATILE_VALUE) {
// volatile partial values replace the *value* of elements matching their selector
$response[] = '$("'.$p['selector'].'").val("'.escape_js($p['html']).'")';
}
}
}
send_script_response(join(";\n", $response));
// bail out
return;
}
foreach ($partials as $k => $p) {
if ($p['mode'] == PARTIAL_STATIC) {
$cb = $p['cb'];
$partials[$k]['html'] = (is_array($cb) ? call_user_func($cb, $rs, $k): $cb($rs, $k));
}
}
$page_title = ($Title) ? $Title : gTxt('write');
pagetop($page_title, $message);
echo n.'<h1 class="txp-heading txp-accessibility">'.gTxt('tab_write').'</h1>';
echo n.'<div id="'.$event.'_container" class="txp-container">';
echo n.n.'<form id="article_form" name="article_form" method="post" action="index.php" '. ($step=='create' ? '>' : ' class="async">');
if (!empty($store_out))
{
echo hInput('store', base64_encode(serialize($store_out)));
}
echo hInput('ID', $ID).
n.eInput('article').
n.sInput($step).
n.hInput('sPosted', $sPosted).
n.hInput('sLastMod', $sLastMod).
n.hInput('AuthorID', $AuthorID).
n.hInput('LastModID', $LastModID).
'<input type="hidden" name="view" />'.
startTable('', '', 'txp-columntable').
'<tr>'.n.
'<td id="article-col-1"><div id="configuration_content">';
if ($view == 'text')
{
//-- markup help --------------
echo $partials['sidehelp']['html'];
//-- custom menu entries --------------
echo pluggable_ui('article_ui', 'extend_col_1', '', $rs);
//-- advanced --------------
echo n.n.'<div role="group" id="advanced_group" class="txp-details">'.
n.'<h3 class="txp-summary'.(get_pref('pane_article_advanced_visible') ? ' expanded' : '').'"><a href="#advanced" role="button">'.gTxt('advanced_options').'</a></h3>'.
n.'<div id="advanced" class="toggle" style="display:'.(get_pref('pane_article_advanced_visible') ? 'block' : 'none').'">';
// markup selection
echo pluggable_ui('article_ui', 'markup',
n.graf('<label for="markup-body">'.gTxt('article_markup').'</label>'.br.
pref_text('textile_body', $textile_body, 'markup-body'), ' class="markup markup-body"').
n.graf('<label for="markup-excerpt">'.gTxt('excerpt_markup').'</label>'.br.
pref_text('textile_excerpt', $textile_excerpt, 'markup-excerpt'), ' class="markup markup-excerpt"'),
$rs);
// form override
echo ($allow_form_override)
? pluggable_ui('article_ui', 'override', graf('<label for="override-form">'.gTxt('override_default_form').'</label>'.sp.popHelp('override_form').br.
form_pop($override_form, 'override-form'), ' class="override-form"'), $rs)
: '';
echo n.'</div>'.n.'</div>';
//-- custom fields --------------
echo $partials['custom_fields']['html'];
//-- article image --------------
echo $partials['image']['html'];
//-- meta info --------------
echo n.n.'<div role="group" id="meta_group" class="txp-details">'.
n.'<h3 class="txp-summary'.(get_pref('pane_article_meta_visible') ? ' expanded' : '').'"><a href="#meta" role="button">'.gTxt('meta').'</a></h3>'.
n.'<div id="meta" class="toggle" style="display:'.(get_pref('pane_article_meta_visible') ? 'block' : 'none').'">';
// keywords
echo $partials['keywords']['html'];
// url title
echo $partials['url_title']['html'];
echo n.'</div>'.n.'</div>';
//-- recent articles --------------
echo n.n.'<div role="navigation" id="recent_group" class="txp-details">'.
n.'<h3 class="txp-summary'.(get_pref('pane_article_recent_visible') ? ' expanded' : '').'"><a href="#recent" role="button">'.gTxt('recent_articles').'</a>'.'</h3>'.
n.'<div id="recent" class="toggle" style="display:'.(get_pref('pane_article_recent_visible') ? 'block' : 'none').'">';
echo $partials['recent_articles']['html'];
echo n.'</div>'.n.'</div>';
}
else
{
echo sp;
}
echo n.n.'</div>'.n.'</td>'.n.'<td id="article-main"><div id="main_content">';
//-- title input --------------
if ($view == 'preview')
{
echo '<div class="preview">'.hed(gTxt('preview'), 2).hed($Title, 1, ' class="title"');
}
elseif ($view == 'html')
{
echo '<div class="html">'.hed('HTML', 2).hed($Title, 1, ' class="title"');
}
elseif ($view == 'text')
{
echo '<div class="text">'.n.$partials['title']['html'];
}
//-- body --------------------
if ($view == 'preview')
{
echo '<div class="body">'.$Body_html.'</div>';
}
elseif ($view == 'html')
{
echo tag(str_replace(array(n,t), array(br,sp.sp.sp.sp), txpspecialchars($Body_html)), 'code', ' class="body"');
}
else
{
echo $partials['body']['html'];
}
//-- excerpt --------------------
if ($articles_use_excerpts)
{
if ($view == 'preview')
{
echo n.'<hr /><div class="excerpt">'.$Excerpt_html.'</div>';
}
elseif ($view == 'html')
{
echo n.'<hr />'.tag(str_replace(array(n,t), array(br,sp.sp.sp.sp), txpspecialchars($Excerpt_html)), 'code', ' class="excerpt"');
}
else
{
echo $partials['excerpt']['html'];
}
}
//-- author --------------
if ($view=="text" && $step != "create")
{
echo $partials['author']['html'];
}
echo hInput('from_view',$view),
'</div></div></td>';
//-- layer tabs -------------------
echo '<td id="article-tabs">';
echo $partials['view_modes']['html'];
echo '</td>';
echo '<td id="article-col-2"><div id="supporting_content">';
if ($view == 'text')
{
if ($step != 'create')
{
echo n.graf(href(gtxt('create_new'), 'index.php?event=article'), ' class="action-create"');
}
//-- prev/next article links --
if ($step!='create' and ($rs['prev_id'] or $rs['next_id'])) {
echo $partials['article_nav']['html'];
}
//-- status radios --------------
echo $partials['status']['html'];
//-- sort and display -----------
echo pluggable_ui('article_ui', 'sort_display',
n.n.tag(
n.'<legend>'.gTxt('sort_display').'</legend>'.
//-- section select --------------
$partials['section']['html'].
//-- category selects -----------
$partials['categories']['html'].
n,
'fieldset', ' id="write-sort"'),
$rs);
//-- "Comments" section
echo n.n.'<div role="group" id="comments_group" class="txp-details'.(($use_comments==1) ? '' : ' empty').'">'.
n.'<h3 class="txp-summary'.(get_pref('pane_article_comments_visible') ? ' expanded' : '').'"><a href="#comments" role="button">'.gTxt('comment_settings').'</a></h3>'.
n.'<div id="comments" class="toggle" style="display:'.(get_pref('pane_article_comments_visible') ? 'block' : 'none').'">';
echo $partials['comments']['html'];
// end "Comments" section
echo '</div>'.n.'</div>';
//-- "Dates" section
echo n.n.'<div role="group" id="dates_group" class="txp-details">'.
n.'<h3 class="txp-summary'.(get_pref('pane_article_dates_visible') ? ' expanded' : '').'"><a href="#dates" role="button">'.gTxt('date_settings').'</a></h3>'.
n.'<div id="dates" class="toggle" style="display:'.(get_pref('pane_article_dates_visible') ? 'block' : 'none').'">';
if ($step == "create" and empty($GLOBALS['ID']))
{
//-- timestamp -------------------
//Avoiding modified date to disappear
$persist_timestamp = (!empty($store_out['year']))?
safe_strtotime($store_out['year'].'-'.$store_out['month'].'-'.$store_out['day'].' '.$store_out['hour'].':'.$store_out['minute'].':'.$store_out['second'])
: time();
echo pluggable_ui('article_ui', 'timestamp',
n.n.'<fieldset id="write-timestamp">'.
n.'<legend>'.gTxt('timestamp').'</legend>'.
n.graf(checkbox('publish_now', '1', $publish_now, '', 'publish_now').'<label for="publish_now">'.gTxt('set_to_now').'</label>', ' class="publish-now"').
n.graf(gTxt('or_publish_at').sp.popHelp('timestamp'), ' class="publish-at"').
n.graf('<span class="label">'.gtxt('date').'</span>'.sp.
tsi('year', '%Y', $persist_timestamp, '').' / '.
tsi('month', '%m', $persist_timestamp, '').' / '.
tsi('day', '%d', $persist_timestamp, '')
, ' class="date posted created"'
).
n.graf('<span class="label">'.gTxt('time').'</span>'.sp.
tsi('hour', '%H', $persist_timestamp, '').' : '.
tsi('minute', '%M', $persist_timestamp, '').' : '.
tsi('second', '%S', $persist_timestamp, '')
, ' class="time posted created"'
).
n.'</fieldset>',
array('sPosted' => $persist_timestamp) + $rs);
//-- expires -------------------
$persist_timestamp = (!empty($store_out['exp_year']))?
safe_strtotime($store_out['exp_year'].'-'.$store_out['exp_month'].'-'.$store_out['exp_day'].' '.$store_out['exp_hour'].':'.$store_out['exp_minute'].':'.$store_out['second'])
: NULLDATETIME;
echo pluggable_ui('article_ui', 'expires',
n.n.'<fieldset id="write-expires">'.
n.'<legend>'.gTxt('expires').'</legend>'.
n.graf('<span class="label">'.gtxt('date').'</span>'.sp.
tsi('exp_year', '%Y', $persist_timestamp, '').' / '.
tsi('exp_month', '%m', $persist_timestamp, '').' / '.
tsi('exp_day', '%d', $persist_timestamp, '')
, ' class="date expires"'
).
n.graf('<span class="label">'.gTxt('time').'</span>'.sp.
tsi('exp_hour', '%H', $persist_timestamp, '').' : '.
tsi('exp_minute', '%M', $persist_timestamp, '').' : '.
tsi('exp_second', '%S', $persist_timestamp, '')
, ' class="time expires"'
).
n.'</fieldset>',
$rs);
// end "Dates" section
echo n.n.'</div>'.n.'</div>';
//-- publish button --------------
echo graf(
(has_privs('article.publish')) ?
fInput('submit','publish',gTxt('publish'),"publish", '', '', '', 4) :
fInput('submit','publish',gTxt('save'),"publish", '', '', '', 4)
, ' id="write-publish"');
}
else
{
//-- timestamp -------------------
echo $partials['posted']['html'];
//-- expires -------------------
echo $partials['expires']['html'];;
// end "Dates" section
echo n.n.'</div>'.n.'</div>';
//-- save button --------------
if ( ($Status >= STATUS_LIVE and has_privs('article.edit.published'))
or ($Status >= STATUS_LIVE and $AuthorID==$txp_user and has_privs('article.edit.own.published'))
or ($Status < STATUS_LIVE and has_privs('article.edit'))
or ($Status < STATUS_LIVE and $AuthorID==$txp_user and has_privs('article.edit.own')))
echo graf(fInput('submit','save',gTxt('save'),"publish", '', '', '', 4), ' id="write-save"');
}
}
echo '</div></td></tr></table>'.n.
tInput().n.
'</form></div>'.n;
// Assume users would not change the timestamp if they wanted to "publish now"/"reset time"
echo script_js( <<<EOS
$('#write-timestamp input.year,#write-timestamp input.month,#write-timestamp input.day').change(
function() {
$('#publish_now').prop('checked', false);
$('#reset_time').prop('checked', false);
});
EOS
);
}
// -------------------------------------------------------------
function custField($num, $field, $content)
{
return n.n.graf('<label for="custom-'.$num.'">'.$field.'</label>'.br.
n.fInput('text', 'custom_'.$num, $content, '', '', '', INPUT_REGULAR, '', 'custom-'.$num), ' class="custom-field custom-'.$num.'"');
}
// -------------------------------------------------------------
function checkIfNeighbour($whichway,$sPosted)
{
$sPosted = assert_int($sPosted);
$dir = ($whichway == 'prev') ? '<' : '>';
$ord = ($whichway == 'prev') ? 'desc' : 'asc';
return safe_field("ID", "textpattern",
"Posted $dir from_unixtime($sPosted) order by Posted $ord limit 1");
}
//--------------------------------------------------------------
function status_radio($Status)
{
global $statuses;
$Status = (!$Status) ? STATUS_LIVE : $Status;
foreach ($statuses as $a => $b)
{
$out[] = n.t.'<li class="status-'.$a.($Status == $a ? ' active' : '').'">'.radio('Status', $a, ($Status == $a) ? 1 : 0, 'status-'.$a).
'<label for="status-'.$a.'">'.$b.'</label></li>';
}
return '<ul class="status plain-list">'.join('', $out).n.'</ul>';
}
//--------------------------------------------------------------
function category_popup($name, $val, $id)
{
$rs = getTree('root', 'article');
if ($rs)
{
return treeSelectInput($name,$rs,$val, $id, 35);
}
return false;
}
//--------------------------------------------------------------
function section_popup($Section, $id)
{
$rs = safe_column('name', 'txp_section', "name != 'default'");
if ($rs)
{
return selectInput('Section', $rs, $Section, false, '', $id);
}
return false;
}
//--------------------------------------------------------------
function tab($tabevent,$view)
{
$state = ($view == $tabevent) ? 'up' : 'down';
$pressed = ($view == $tabevent) ? 'true' : 'false';
return '<li class="view-mode '.$tabevent.'" id="tab-'.$tabevent.$state.'" title="'.gTxt('view_'.$tabevent).'">'.
'<a href="javascript:document.article_form.view.value=\''.$tabevent.'\';document.article_form.submit();" role="button" aria-pressed="'.$pressed.'">'.gTxt($tabevent).'</a>'.
'</li>'.n;
}
//--------------------------------------------------------------
function getDefaultSection()
{
return get_pref('default_section');
}
// -------------------------------------------------------------
function form_pop($form, $id)
{
$arr = array(' ');
$rs = safe_column('name', 'txp_form', "type = 'article' and name != 'default' order by name");
if ($rs)
{
return selectInput('override_form', $rs, $form, true, '', $id);
}
}
// -------------------------------------------------------------
function check_url_title($url_title)