-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathied_plugin_composer.php
More file actions
4812 lines (4182 loc) · 212 KB
/
Copy pathied_plugin_composer.php
File metadata and controls
4812 lines (4182 loc) · 212 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
// This is a PLUGIN TEMPLATE for Textpattern CMS.
// Copy this file to a new name like abc_myplugin.php. Edit the code, then
// run this file at the command line to produce a plugin for distribution:
// $ php abc_myplugin.php > abc_myplugin-0.1.txt
// Plugin name is optional. If unset, it will be extracted from the current
// file name. Plugin names should start with a three letter prefix which is
// unique and reserved for each plugin author ("abc" is just an example).
// Uncomment and edit this line to override:
$plugin['name'] = 'ied_plugin_composer';
// Allow raw HTML help, as opposed to Textile.
// 0 = Plugin help is in Textile format, no raw HTML allowed (default).
// 1 = Plugin help is in raw HTML. Not recommended.
# $plugin['allow_html_help'] = 1;
$plugin['version'] = '1.3.0';
$plugin['author'] = 'Yura Linnyk, Stef Dawson, Steve Dickinson';
$plugin['author_uri'] = 'http://stefdawson.com/';
$plugin['description'] = 'Create, publish and edit plugins from within Textpattern CMS';
// Plugin load order:
// The default value of 5 would fit most plugins, while for instance comment
// spam evaluators or URL redirectors would probably want to run earlier
// (1...4) to prepare the environment for everything else that follows.
// Values 6...9 should be considered for plugins which would work late.
// This order is user-overrideable.
$plugin['order'] = '5';
// Plugin 'type' defines where the plugin is loaded
// 0 = public : only on the public side of the website (default)
// 1 = public+admin : on both the public and admin side
// 2 = library : only when include_plugin() or require_plugin() is called
// 3 = admin : only on the admin side (no AJAX)
// 4 = admin+ajax : only on the admin side (AJAX supported)
// 5 = public+admin+ajax : on both the public and admin side (AJAX supported)
$plugin['type'] = '5';
// Plugin "flags" signal the presence of optional capabilities to the core plugin loader.
// Use an appropriately OR-ed combination of these flags.
// The four high-order bits 0xf000 are available for this plugin's private use
if (!defined('PLUGIN_HAS_PREFS')) define('PLUGIN_HAS_PREFS', 0x0001); // This plugin wants to receive "plugin_prefs.{$plugin['name']}" events
if (!defined('PLUGIN_LIFECYCLE_NOTIFY')) define('PLUGIN_LIFECYCLE_NOTIFY', 0x0002); // This plugin wants to receive "plugin_lifecycle.{$plugin['name']}" events
$plugin['flags'] = '3';
// Plugin 'textpack' is optional. It provides i18n strings to be used in conjunction with gTxt().
// Syntax:
// ## arbitrary comment
// #@event
// #@language ISO-LANGUAGE-CODE
// abc_string_name => Localized String
$plugin['textpack'] = <<<EOT
#@owner ied_plugin
#@language en, en-gb, en-ca, en-us
#@admin-side
ied_plugin_composer => Plugin composer
#@ied_plugin
ied_plugin_any => Any
ied_plugin_auto_enable => Auto-enable plugins on install
ied_plugin_cacheplugs_legend => Plugins in cache directory
ied_plugin_cache_not_set => Advanced pref "plugin cache directory" not defined
ied_plugin_check_type => Check your plugin type!
ied_plugin_choose_file => Please choose a file first
ied_plugin_code_dist => Plugin code for distribution
ied_plugin_code_legend => Plugin code
ied_plugin_code_save => Save code
ied_plugin_code_saved => Code saved
ied_plugin_code_saved_fail => Code saving failed
ied_plugin_compress => Zip
ied_plugin_cpanel_legend => Installation
ied_plugin_create_new => Create new plugin
ied_plugin_dbplugs_legend => Plugins in database
ied_plugin_dist_legend => Distribution
ied_plugin_docs_legend => Plugin help
ied_plugin_edit => Edit: {name} v{version}
ied_plugin_editing => Editing {name} in Plugin Composer
ied_plugin_editor => Plugin editor
ied_plugin_editor_options => Plugin editor configuration options
ied_plugin_editor_path => Plugin editor URL
ied_plugin_editor_width => Plugin editor width
ied_plugin_edit_new => Edit your new plugin
ied_plugin_enable => Enabled
ied_plugin_export => Export as {name}
ied_plugin_export_textpack => Export textpack(s)
ied_plugin_export_zip => Export as {name} (compressed)
ied_plugin_flags => Flags
ied_plugin_flag_has_prefs => Has prefs
ied_plugin_flag_lifecycle_notify => Event notify
ied_plugin_fn_not_exist => (the function is probably javascript or mangled PHP)
ied_plugin_help_editor => Help editor
ied_plugin_help_editor_options => Help editor configuration options
ied_plugin_help_editor_path => Help editor URL
ied_plugin_help_not_available => Plugin help not available
ied_plugin_if_el_dist => Code for distribution
ied_plugin_if_el_style => Help style block
ied_plugin_if_settings => Interface settings
ied_plugin_install_textpack => Install file's Textpack
ied_plugin_install_txt => Install from .txt file
ied_plugin_interface_elems => Optional interface elements
ied_plugin_jump_to_line => Jump to line:
ied_plugin_langs_all => All available
ied_plugin_langs_installed => Only installed
ied_plugin_lang_choose => Textpack language list
ied_plugin_lang_default => Default textpack language
ied_plugin_lbl_lc_delete => Delete
ied_plugin_lbl_lc_disable => Disable
ied_plugin_lbl_lc_disdel => Disable+Delete
ied_plugin_lbl_lc_enable => Enable
ied_plugin_lbl_lc_instable => Install+Enable
ied_plugin_lbl_lc_install => Install
ied_plugin_lbl_op_code_first => Code first
ied_plugin_lbl_op_help_first => Help first
ied_plugin_lbl_setup => Plugin composer setup
ied_plugin_lc_fired => Lifecycle event {event} fired for {name}
ied_plugin_lifecycle => Fire lifecycle event
ied_plugin_lifecycle_options => Perform lifecycle actions on
ied_plugin_list => Plugin list
ied_plugin_load => Load
ied_plugin_load_order => Load order
ied_plugin_load_order_help => (1=first > 5=normal > 9=last)
ied_plugin_meta_legend => Meta information
ied_plugin_meta_save => Save meta
ied_plugin_meta_saved => Meta info saved
ied_plugin_meta_saved_fail => Meta info not saved
ied_plugin_msgpop_lbl => phpdoc block
ied_plugin_name_first => Please name the plugin before creating it
ied_plugin_output_order => PHP export order
ied_plugin_output_sfile => Export plugin filename format
ied_plugin_output_sfilec => Export compressed filename format
ied_plugin_output_sfilep => Plugin template filename format
ied_plugin_output_sfilet => Textpack filename format
ied_plugin_output_tmpcache => Cache Textiled help path
ied_plugin_pack_legend => Textpack strings
ied_plugin_php_doc => Make phpdoc
ied_plugin_prefs => Preferences
ied_plugin_prefs_deleted => Preferences deleted
ied_plugin_renamed => (renamed)
ied_plugin_rename_failed => (rename failed)
ied_plugin_rename_file => Rename file
ied_plugin_restored => Plugin {name} restored.
ied_plugin_restore_help => Roll back the plugin code to the most recent restore point
ied_plugin_restore_point => Restore point
ied_plugin_restore_verify => Are you sure you want to rollback the {name} source code to its last restore point?
ied_plugin_run_install => Perform post-install actions
ied_plugin_same => Same
ied_plugin_save_as => Save as {name}
ied_plugin_setup => Setup
ied_plugin_syntax_check => Syntax check on code save
ied_plugin_syntax_err => Syntax error
ied_plugin_toggle => Toggle
ied_plugin_tp_populate => Load strings from function
ied_plugin_tp_prefix => Textpack owner|prefix
ied_plugin_type => Plugin type
ied_plugin_type_0 => Public
ied_plugin_type_1 => Admin + Public
ied_plugin_type_2 => Library
ied_plugin_type_3 => Admin only
ied_plugin_type_4 => Admin (+Ajax)
ied_plugin_type_5 => Admin + Public (+Ajax)
ied_plugin_updated => Plugin {name} updated
ied_plugin_uploaded => Plugin {name} uploaded
ied_plugin_upload_php => Upload plugin
ied_plugin_view_help => Help: {name}
#@language fr
#@admin-side
ied_plugin_composer => Plugin composer
#@ied_plugin
ied_plugin_any => Tous
ied_plugin_auto_enable => Activer les plugins dès leur installation
ied_plugin_cacheplugs_legend => Les Plugins sont chargés depuis le cache
ied_plugin_cache_not_set => Le paramètre "chemin du cache des plugins" des préférences avancées n'est pas renseigné
ied_plugin_check_type => Renseignez le type de votre plugin !
ied_plugin_choose_file => Veuillez choisir d'abord un fichier
ied_plugin_code_dist => Code de distribution du plugin
ied_plugin_code_legend => Code source du plugin
ied_plugin_code_save => Sauvegarder le code
ied_plugin_code_saved => Code sauvegardé
ied_plugin_code_saved_fail => Échec de sauvegarde du code
ied_plugin_compress => Zip
ied_plugin_cpanel_legend => Installation
ied_plugin_create_new => Créer un nouveau plugin
ied_plugin_dbplugs_legend => Plugins disponibles
ied_plugin_dist_legend => Distribution
ied_plugin_docs_legend => Aide du plugin
ied_plugin_edit => Éditer : {name} v{version}
ied_plugin_editing => Édition de {name} depuis Plugin Composer
ied_plugin_editor => Éditeur de plugins
ied_plugin_editor_options => Options de configuration de l'éditeur de plugins
ied_plugin_editor_path => URL de l'éditeur de plugins
ied_plugin_editor_width => Taille (largeur) de l'éditeur de plugin
ied_plugin_edit_new => Éditer votre nouveau plugin
ied_plugin_enable => Activé
ied_plugin_export => Exporter sous {name}
ied_plugin_export_textpack => Exporter le(s) textpack(s)
ied_plugin_export_zip => Exporter sous {name} (compressé)
ied_plugin_flags => Flags
ied_plugin_flag_has_prefs => A les préfs
ied_plugin_flag_lifecycle_notify => Notification d'événement
ied_plugin_fn_not_exist => (la fonction est probablement en javascript ou contient du PHP corrompu)
ied_plugin_help_editor => Éditeur de l'aide
ied_plugin_help_editor_options => Configuration pour l'éditeur de l'aide
ied_plugin_help_editor_path => URL pour l'éditeur de l'aide
ied_plugin_help_not_available => Aide du plugin non disponible
ied_plugin_if_el_dist => Code de distribution
ied_plugin_if_el_style => Bloc CSS pour l'aide
ied_plugin_if_settings => Paramètres de l'interface
ied_plugin_install_txt => Installer depuis un fichier .txt
ied_plugin_interface_elems => Éléments optionels de l'interface
ied_plugin_jump_to_line => Aller à la ligne :
ied_plugin_langs_all => Toutes disponibles
ied_plugin_langs_installed => Seulement installées
ied_plugin_lang_choose => Liste des traductions (Textpack)
ied_plugin_lang_default => Langue par défaut (Textpack)
ied_plugin_lbl_lc_delete => Supprimer
ied_plugin_lbl_lc_disable => Désactiver
ied_plugin_lbl_lc_enable => Activer
ied_plugin_lbl_lc_install => Installer
ied_plugin_lbl_op_code_first => Code au début
ied_plugin_lbl_op_help_first => Aide au début
ied_plugin_lbl_setup => Configuration de Plugin composer
ied_plugin_lifecycle_options => Réaliser les actions "lifecycle" sur
ied_plugin_load => Charger
ied_plugin_load_order => Ordre de chargement
ied_plugin_load_order_help => (1=premier > 5=normal > 9=dernier)
ied_plugin_meta_legend => Meta information
ied_plugin_msgpop_lbl => Bloc phpdoc
ied_plugin_name_first => Veuillez nommer le plugin avant de pouvoir le créer
ied_plugin_output_order => Orde d'exportation du source PHP
ied_plugin_output_sfile => Noms d'exportation des fichiers plugin
ied_plugin_output_sfilec => Noms des fichiers compressés
ied_plugin_output_sfilep => Noms des fichiers Plugin
ied_plugin_output_sfilet => Noms des fichiers Textpack
ied_plugin_output_tmpcache => Chemin du cache de l'aide sous Textile
ied_plugin_pack_legend => Chaînes du Textpack
ied_plugin_php_doc => Créer un phpdoc
ied_plugin_prefs => Préférences
ied_plugin_prefs_deleted => Préférences supprimées
ied_plugin_renamed => (renomé)
ied_plugin_rename_failed => (échec de renomage)
ied_plugin_rename_file => Renomer le fichier
ied_plugin_restored => Plugin {name} restauré.
ied_plugin_restore_help => Restituer le code du plugin à partir de son dernier point de restauration
ied_plugin_restore_point => Point de restauration
ied_plugin_restore_verify => Êtes-vous sûr de vouloir restituer le code source de {name} à partir de son dernier point de restauration ?
ied_plugin_run_install => Effectuer les actions de post-installation
ied_plugin_same => Nom
ied_plugin_save_as => Sauver sous {name}
ied_plugin_setup => Configuration
ied_plugin_syntax_check => Vérifier la syntaxe du code avant sauvegarde
ied_plugin_syntax_err => Erreur de syntaxe
ied_plugin_tp_populate => Essayer de charger les chaînes depuis la fonction
ied_plugin_tp_prefix => Préfixe du Textpack
ied_plugin_type => Type de plugin
ied_plugin_type_0 => Public
ied_plugin_type_1 => Admin + Public
ied_plugin_type_2 => Librarie
ied_plugin_type_3 => Admin seul
ied_plugin_type_4 => Admin (+Ajax)
ied_plugin_type_5 => Admin + Public (+Ajax)
ied_plugin_updated => Plugin {name} mis à jour
ied_plugin_uploaded => Plugin {name} téléchargé
ied_plugin_upload_php => Télécharger un plugin
ied_plugin_view_help => Aide de : {name}
EOT;
if (!defined('txpinterface'))
@include_once('zem_tpl.php');
# --- BEGIN PLUGIN CODE ---
// <?php
/**
* ied_plugin_composer
*
* A Textpattern CMS plugin for writing, editing and sharing plugins
* -> Create and edit admin-side or public plugins
* -> Supports plugin lifecycle events and prefs
* -> Supports Textpacks
* -> Optional syntax checker on save
*
* @author Yura Linnyk
* @author Stef Dawson
* @author Steve Dickinson
* @link http://stefdawson.com/
*/
// TODO:
// * Use href() (from 4.6.+) for anchor creation to avoid double-encoded ampersands
// * Figure out why syntax checker doesn't jump to line number sometimes (Ajax fails with error but it's not handled)
// * Show which langs have installed strings in the distribution section so the correct langs in the select list can be chosen
// * Find out why uploading PHP files sometiems throws an error even though it succeeds
// * jQuery on editor dropdowns in setup
// * phpdoc
if (txpinterface === 'admin') {
new ied_pc();
} elseif (txpinterface === 'public') {
if (class_exists('\Textpattern\Tag\Registry')) {
\Txp::get('\Textpattern\Tag\Registry')
->register('ied_plugin_list')
->register('ied_plugin_info')
->register('ied_plugin_textpacks')
->register('ied_plugin_download')
->register('ied_plugin_download_link');
}
register_callback('ied_plugin_download', 'pretext');
/*
* Public tag: List plugins, filtered by name or prefix.
*
* @param array $atts Tag attributes
* @param string $thing Tag container content
*/
function ied_plugin_list($atts = array(), $thing = null)
{
global $ied_plugin_data;
extract(lAtts(array(
'from' => 'database', // database, cache (or both)
'name' => '', // List of plugin names to return
'prefix' => '', // Plugin prefixes
'exclude' => '', // names to exclude from the list
'type' => '', // 0-5 or comma-separated combos thereof
'wraptag' => '',
'class' => '',
'break' => '',
'breakclass' => '',
'html_id' => '',
'form' => '',
),$atts));
$thing = (empty($form)) ? ((empty($thing)) ? '<txp:ied_plugin_info item="name" />' : $thing) : fetch_form($form);
$location = do_list($from);
$names = do_list($name);
$prefixes = do_list($prefix);
$excludes = do_list($exclude);
if (in_array('database', $location)) {
$sql = array();
$sql[] = '1';
if ($name) {
$sql[] = "name IN ('".implode("','", doSlash($names))."')";
}
if ($prefix) {
$sqlor = array();
foreach ($prefixes as $pfx) {
$sqlor[] = "name LIKE '".doSlash($pfx)."%'";
}
$sql[] = '(' . implode(' OR ', $sqlor) . ')';
}
if ($exclude) {
$sql[] = "name NOT IN ('".implode("','", doSlash($excludes))."')";
}
$rs = safe_rows('*', 'txp_plugin', implode(' AND ', $sql) . ' ORDER BY name');
}
// TODO: Add the meta data from matching plugins in the cache directory
if (in_array('cache', $location)) {
}
$out = array();
$ied_pd_saved = $ied_plugin_data;
foreach ($rs as $row) {
$ied_plugin_data = $row;
$ied_plugin_data['help_unstyled'] = preg_replace('/\<\!\-\- \*\*\* BEGIN PLUGIN CSS.+END PLUGIN CSS \*\*\* \-\-\>/s', '', $row['help']);
$out[] = parse($thing);
$ied_plugin_data = array();
}
$ied_plugin_data = $ied_pd_saved;
return ($wraptag) ? doWrap($out, $wraptag, $break, $class, $breakclass, '', '', $html_id) : implode($break, $out);
}
/**
* Public tag: Display plugin data for form/container usage.
*
* @param array $atts Tag attributes
* @param string $thing Tag container content
*/
function ied_plugin_info($atts, $thing = null)
{
global $ied_plugin_data;
extract(lAtts(array(
'item' => '',
'wraptag' => '',
'break' => '',
'class' => '',
'debug' => 0,
), $atts));
$pdata = is_array($ied_plugin_data) ? $ied_plugin_data : array();
if ($debug) {
echo '++ AVAILABLE INFO ++';
dmp($pdata);
}
$items = do_list($item);
$out = array();
foreach ($items as $it) {
if (isset($pdata[$it])) {
$out[] = $pdata[$it];
}
}
return doWrap($out, $wraptag, $break, $class);
}
/**
* Public tag: List of available textpack information.
*
* @param array $atts Tag attributes
* @param string $thing Tag container content
*/
function ied_plugin_textpacks($atts, $thing = null)
{
global $ied_plugin_data;
extract(lAtts(array(
'name' => '',
'filename' => '',
'lang' => 'IED_ALL',
'wraptag' => '',
'break' => '',
'class' => '',
'form' => '',
), $atts));
if (!$name && !$filename) {
return;
}
if ($name) {
$theName = $name;
} elseif ($filename) {
$theName = $filename;
}
$thing = (empty($form)) ? ((empty($thing)) ? '<txp:ied_plugin_info item="lang" />' : $thing) : fetch_form($form);
$langs = array();
$tp_prefixes = json_decode(get_pref('ied_plugin_tp_prefix', ''), true);
if (isset($tp_prefixes[$theName])) {
$strings = ied_plugin_textpack_grab($lang, $tp_prefixes[$theName]);
foreach ($strings as $row) {
if (array_search($row['lang'], $langs) === false) {
$langs[] = $row['lang'];
}
}
}
$out = array();
$ied_pd_saved = $ied_plugin_data;
$idx = 0;
$num_langs = count($langs);
foreach ($langs as $row) {
$ied_plugin_data['lang'] = $row;
$ied_plugin_data['first_lang'] = (($idx === 0) ? 1 : 0);
$ied_plugin_data['last_lang'] = (($idx === $num_langs - 1) ? 1 : 0);
$out[] = parse($thing);
$ied_plugin_data['lang'] = $ied_plugin_data['first_lang'] = $ied_plugin_data['last_lang'] = '';
$idx++;
}
$ied_plugin_data = $ied_pd_saved;
return doWrap($out, $wraptag, $break, $class);
}
/**
* Public tag: Download a plugin.
*
* @param array $atts Tag attributes
* @param string $thing Tag container content
*/
function ied_plugin_download_link($atts, $thing = null)
{
extract(lAtts(array(
'type' => 'compressed', // uncompressed, compressed, template, textpack
'name' => '',
'filename' => '',
'label' => 'Download',
'class' => '',
'lang' => 'IED_ALL',
'form' => '',
'escape' => 'html',
), $atts));
if (!$name && !$filename) {
return;
}
$amp = ($escape === 'html') ? '&' : '&';
if ($name) {
$theName = $amp.'name='.urlencode($name);
} elseif ($filename) {
$theName = $amp.'filename='.urlencode($filename);
}
$theClass = '';
if ($class) {
$theClass = ' class="'.$class.'"';
}
$langopt = '';
if ($lang) {
$langs = do_list($lang);
$langopt = $amp.'lang='.implode(',', $langs);
}
$linkName = (empty($form)) ? ((empty($thing)) ? $label : parse($thing)) : parse_form($form);
if ($type === 'compressed') {
return href($linkName, '?ied_plugin_download=1'.$theName.$amp.'type=zip'.$langopt, $theClass);
} elseif ($type === 'uncompressed') {
return href($linkName, '?ied_plugin_download=1'.$theName.$amp.'type=txt'.$langopt, $theClass);
} elseif ($type === 'template') {
return href($linkName, '?ied_plugin_download=1'.$theName.$amp.'type=php'.$langopt, $theClass);
} elseif ($type === 'textpack') {
return href($linkName, '?ied_plugin_download=1'.$theName.$amp.'type=textpack'.$langopt, $theClass);
}
}
/**
* Handles downloading plugin content.
*/
function ied_plugin_download()
{
if (gps('ied_plugin_download')) {
$type = gps('type');
switch ($type) {
case 'zip':
case 'txt':
$ied_pc = new ied_pc();
$ied_pc->save_as_file();
break;
case 'php':
$ied_pc = new ied_pc();
$ied_pc->save_as_php_file();
break;
case 'textpack':
$ied_pc = new ied_pc();
$ied_pc->save_as_textpack();
break;
}
}
}
}
/**
* Plugin composer admin interface.
*/
class ied_pc
{
/**
* Shared information across methods.
*
* @var array
*/
protected $ied_plugin_globals = array();
/**
* The plugin's event as registered in Txp.
*
* @var string
*/
protected $ied_pc_event = 'ied_plugin_composer';
/**
* Constructor to set up callbacks and environment.
*/
public function __construct()
{
$this->ied_plugin_globals = array(
'css_start' => '<!--',
'css_end' => '-->',
'dlm_start' => '#',
'dlm_end' => '',
'start' => ' --- BEGIN PLUGIN SECTION ---',
'end' => ' --- END PLUGIN SECTION ---',
'size_help' => '63535',
'size_css' => '2000',
'size_code' => '16777215',
);
add_privs($this->ied_pc_event, '1,2');
add_privs('plugin_prefs.' . $this->ied_pc_event, '1,2');
register_tab('extensions', $this->ied_pc_event, gTxt('ied_plugin_composer'));
register_callback(array($this, 'plugin_composer'), $this->ied_pc_event);
register_callback(array($this, 'setup'), 'plugin_prefs.' . $this->ied_pc_event);
register_callback(array($this, 'welcome'), 'plugin_lifecycle.' . $this->ied_pc_event);
register_callback(array($this, 'inject_css'), 'admin_side', 'head_end');
// Load additional lang strings from other areas to save having to define
// them in the plugin.
$adminLang = get_pref('language_ui');
$langs = Txp::get('\Textpattern\L10n\Lang');
$langs->available(TEXTPATTERN_LANG_ACTIVE);
$additionalStrings = $langs->extract($adminLang, array('plugin', 'lang'));
$langs->setPack($additionalStrings, true);
}
/**
* CSS definitions: hopefully kind to themers.
*
* @return string Style rules
*/
protected function get_style_rules()
{
$ied_pc_styles = array(
'ied_plugin' => '
.ied_label { margin:0 0.2em 0 0.6em;}
.ied_plugin_link { float:right; }
.ied_plugin_info_bar { text-align:right; }
#ied_plugin_jumpToLine { width:4em; margin:0 1em 0 0.4em; }
.ied_editForm { width:{edwidth}; margin:0 auto; }
.ied_subdue { color:gray; padding:1px 2px 2px 1px; }
#ied_plugin_tp_controls input[type="text"] { width:16%; }
#options_group_pack ul { list-style-type:none; }
#options_group_pack ul label { margin:0 8px 0 0; }
#options_group_pack ul input { width:450px; }
#options_group_pack li { margin-bottom:.2em }
.distribution-code { height:4.2em!important; }
.ied_plugin_edit_toolbar { text-align:right; width:95%; display:inline-block; margin:-2em 0 0 0; }
#ied_plugin_msgpop { display:none; position:absolute; left:200px; max-width:500px; border:3px ridge #999; opacity:.92; filter:alpha(opacity:92); padding:15px 20px; background-color:#e2dfce; color:#80551e; }
#ied_plugin_msgpop .publish { float:right; }
',
);
return $ied_pc_styles;
}
/**
* Inject style rules into the <head> of the page.
*
* @param string $evt Textpattern event
* @param string $stp Textpattern step (action)
* @return string Style rules, or nothing if not the correct $event
*/
public function inject_css($evt, $stp)
{
global $event;
if ($event === $this->ied_pc_event) {
$ied_plugin_prefs = $this->get_prefs();
$ied_plugin_styles = $this->get_style_rules();
// Possible variable replacements.
$edwidth = get_pref('ied_plugin_editor_width', $ied_plugin_prefs['ied_plugin_editor_width']['default']);
$stylefind = array(
'{edwidth}',
);
$stylereps = array(
$edwidth,
);
echo '<style type="text/css">' . str_replace($stylefind, $stylereps, $ied_plugin_styles['ied_plugin']) . '</style>';
}
return;
}
/**
* Plugin jumpoff point.
*
* @param string $evt Textpattern event
* @param string $stp Textpattern step (action)
*/
public function plugin_composer($evt, $stp)
{
$available_steps = array(
'code_save' => true,
'create' => true,
'edit' => false,
'generate_phpdoc' => true,
'help' => true,
'help_viewer' => false,
'install' => true,
'lang_set' => true,
'table' => false,
'meta_save' => true,
'multi_edit' => true,
'prefs' => false,
'restore' => true,
'save' => true,
'save_as_file' => true,
'save_as_php_file' => true,
'save_as_textpack' => true,
'set_tp_prefix' => true,
'switch_status' => true,
'textpack_del' => true,
'textpack_get' => true,
'textpack_load' => true,
'textpack_save' => true,
'upload' => true,
'save_pane_state' => true,
);
if (!$stp or !bouncer($stp, $available_steps)) {
$stp = 'table';
}
$this->$stp();
}
/**
* Lifecycle handling, post-install / delete.
*
* @param string $evt Textpattern event
* @param string $stp Textpattern step (action)
* @return string Success/failure message
*/
public function welcome($evt, $stp)
{
$msg = '';
switch ($stp) {
case 'installed':
$this->prefs_update();
$msg = 'Thanks for installing the plugin composer. Happy authoring :-)';
break;
case 'deleted':
$this->prefs_remove(0);
break;
}
return $msg;
}
/**
* Table of plugins in both database and file system cache.
*
* @param string $message Flash message to display success/error
* @return string HTML
*/
public function table($message = '')
{
pagetop(gTxt('ied_plugin_composer'), $message);
require_privs('ied_plugin_composer');
$ied_plugin_prefs = $this->get_prefs();
$lc_opts = do_list(get_pref('ied_plugin_lifecycle_options'));
$checked = in_array('installed', $lc_opts);
$auto_en = get_pref('ied_plugin_auto_enable');
$pcd = get_pref('plugin_cache_dir');
$aeRadio[] = '<p class="ied_plugin_radioset ied_plugin_autoenable txp-layout-2col">';
$aeRadio[] = '<label class="ied_label">' . gTxt('ied_plugin_auto_enable') . '</label>';
$aeRadio[] = radioset($ied_plugin_prefs['ied_plugin_auto_enable']['content'], 'ied_plugin_autoenable', $auto_en);
$aeRadio[] = '</p>';
$ioRadio[] = '<p class="ied_plugin_radioset ied_plugin_installopts txp-layout-2col" hidden>';
$ioRadio[] = '<label class="ied_label">' . gTxt('ied_plugin_run_install') . '</label>';
$ioRadio[] = yesnoradio('ied_plugin_installopts', $checked);
$ioRadio[] = '</p>';
extract(gpsa(array('sort', 'dir')));
if ($sort === '') $sort = get_pref('ied_plugin_sort_column', 'name');
if ($dir === '') $dir = get_pref('ied_plugin_sort_dir', 'asc');
$dir = ($dir == 'desc') ? 'desc' : 'asc';
if (!in_array($sort, array('name', 'status', 'author', 'version', 'load_order'))) $sort = 'name';
$sort_sql = $sort.' '.$dir;
set_pref('ied_plugin_sort_column', $sort, 'ied_plugin', PREF_HIDDEN, '', 0, PREF_PRIVATE);
set_pref('ied_plugin_sort_dir', $dir, 'ied_plugin', PREF_HIDDEN, '', 0, PREF_PRIVATE);
$switch_dir = ($dir == 'desc') ? 'asc' : 'desc';
// Top control-panel part of screen
echo '<div class="txp-layout">'.
n. '<div class="txp-layout-2col">'.
n. '<h1 class="txp-heading">'.gTxt('ied_plugin_composer').sp.$this->anchor($this->ied_pc_event, 'help_viewer', '?', array('name' => 'ied_plugin_composer'), array('class' => 'pophelp')).'</h1>'.
n. '</div>'.
n. '<div id="ied_plugin_control" class="txp-layout-2col">'.
n. sLink($this->ied_pc_event, 'prefs', '<span class="ui-icon ui-icon-wrench"></span>'.sp.gTxt('ied_plugin_setup'), 'ied_plugin_link').
n. '</div>'.
n. '<div class="txp-layout-1col">';
$formBlock = n. '<form class="ied_plugin_form" enctype="multipart/form-data" action="index.php" method="post">'.
n. implode(n, $aeRadio).
n. implode(n, $ioRadio).
n. '<p class="clear">'.
n. '<label for="ied_plugin_newname" class="ied_label">'.gTxt('name').'</label>'.
n. fInput('text', 'name', '', '', '', '', INPUT_REGULAR, '', 'ied_plugin_newname', false, false, 'Create a new plugin').
n. fInput('submit', 'plugin_create', gTxt('create')).
n. '</p>'.
n. '<p>'.
n. '<label for="ied_plugin_file" class="ied_label">'.gTxt('ied_plugin_upload_php').'</label>'.
n. fInput('file', 'thefile', '', '', '', '', '', '', 'ied_plugin_file').
n. fInput('submit', 'plugin_upload', gTxt('upload')).
n. '</p>'.
n. '<p>'.
n. '<label for="ied_plugin64" class="ied_label">'.gTxt('ied_plugin_install_txt').'</label>'.
n. text_area('plugin64', '', '', '', 'ied_plugin64').
n. fInput('submit', 'plugin_install', gTxt('install')).
n. '</p>'.
n. eInput($this->ied_pc_event).
n. sInput('create').
n. hInput('MAX_FILE_SIZE', 1000000).
n. tInput().
n. '</form>';
echo wrapRegion('ied_plugin_control_panel', $formBlock, 'ied_plugin_cpanel', 'ied_plugin_cpanel_legend', 'ied_plugin_cpanel_visible');
echo n. '</div>'.
n. '</div>';
// Main plugin list
$rs = safe_rows('*', 'txp_plugin', '1=1 ORDER BY '.$sort_sql);
$out = array();
if ($rs) {
echo '<div class="txp-layout-1col">';
$out[] = n. '<form action="index.php" id="ied_plugin_db_form" method="post">'.
n. '<div class="txp-listtables">'.
n. startTable('', '', 'txp-list').
n.'<thead>'.
n. tr(
n.hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' class="txp-list-col-multi-edit" scope="col" title="'.gTxt('toggle_all_selected').'"')
.n.column_head('plugin', 'name', 'ied_plugin_composer', true, $switch_dir, '', '', (('name' == $sort) ? "$dir " : '').'name')
.n.column_head('author', 'author', 'ied_plugin_composer', true, $switch_dir, '', '', (('author' == $sort) ? "$dir " : '').'author')
.n.column_head(gTxt('version').' ('.gTxt('modified').')', 'version', 'ied_plugin_composer', true, $switch_dir, '', '', (('version' == $sort) ? "$dir " : '').'version')
.n.hCell(gTxt('description'), '', ' class="description"')
.n.hCell(gTxt('manage'), '', ' class="manage"')
.n.column_head('active', 'status', 'ied_plugin_composer', true, $switch_dir, '', '', (('status' == $sort) ? "$dir " : '').'status')
).
n. '</thead>'.
n. '<tbody>';
foreach ($rs as $row) {
extract($row);
$ename = $this->anchor($this->ied_pc_event, 'edit', $name, array('name' => $name));
$hlink = ($help) ? $this->anchor($this->ied_pc_event, 'help_viewer', gTxt('help'), array('name' => $name)) : gTxt('none');
$fnames = $this->get_name($name, $version);
$pubtag = $this->anchor($this->ied_pc_event, 'save_as_file', gTxt('publish'), array('name' => $name), array('title' => gTxt('ied_plugin_export', array('{name}' => $fnames[0]))));
$pubztag = $this->anchor($this->ied_pc_event, 'save_as_file', gTxt('ied_plugin_compress'), array('name' => $name, 'type' => 'zip'), array('title' => gTxt('ied_plugin_export', array('{name}' => $fnames[1]))));
$modified = (strtolower($code) != (strtolower($code_restore)));
$plugpref = ($flags & PLUGIN_HAS_PREFS) ? (sp.$this->anchor('plugin_prefs.'.urlencode($name), '', '['.gTxt('options').']', array('name' => $name), array('class' => 'plugin_prefs'.( ($status) ? '' : ' empty'))) ) : '';
$out[] = tr(
n.td(
fInput('checkbox', 'selected[]', $name),'', 'txp-list-col-multi-edit'
)
.n.td($ename.$plugpref)
.n.td(( ($author_uri) ? '<a href="'.txpspecialchars($author_uri).'">'.txpspecialchars($author).'</a>' : txpspecialchars($author)))
.n.td(( ($modified) ? $this->anchor($this->ied_pc_event, 'restore', $version, array('name' => $name), array('title' => gTxt('ied_plugin_restore_help'), 'onclick' => 'return verify(\''.gTxt('ied_plugin_restore_verify', array('{name}' => $name)).'\');')) : $version) . (($modified) ? sp.'('.gTxt('yes').')' : ''))
.n.td(txpspecialchars($description))
.n.td($pubtag .sp. '|' .sp. $pubztag .sp. '|' .sp. $hlink)
.n.td($this->status_link($status,$name,yes_no($status)))
);
unset($name,$page);
}
$out[] = n. '</tbody>'.
n. endTable().
n. '</div>'.
n. tInput().
$this->multiedit_form('db', '', $sort, $dir, '', '').
n. '</form>';
echo wrapRegion('ied_plugin_database', join(n, $out), 'ied_plugin_dbplugs', 'ied_plugin_dbplugs_legend', 'ied_plugin_dbplugs_visible');
echo n. '</div>';
}
if (!empty($pcd) && file_exists($pcd)) {
$filenames = array();
$directory = dir($pcd);
while ($file = $directory->read()) {
if ($file != "." && $file != "..") {
$fileaddr = $pcd . DS . $file;
if (!is_dir($fileaddr)) {
$filenames[]=$file;
}
}
}
$directory->close();
($filenames)?natcasesort($filenames):'';
$out = array();
foreach ($filenames as $filename) {
$parts = explode ('.',$filename);
$fileext = array_pop($parts);
if ($fileext=='php') {
$basename = basename($filename);
$plugin = $this->read_file($pcd . DS . $filename);
$hlink = ($plugin['help']) ? $this->anchor($this->ied_pc_event, 'help_viewer', gTxt('help'), array('filename' => $filename)) : gTxt('none');
$efile = $this->anchor($this->ied_pc_event, 'edit', $plugin['name'], array('filename' => $filename));
$fnames = $this->get_name($plugin['name'], $plugin['version']);
$plugpref = (($plugin['flags'] & PLUGIN_HAS_PREFS)) ? ' '.$this->anchor('plugin_prefs.'.urlencode($plugin['name']), '', ' ['.gTxt('options').']') : '';
$pubtag = $this->anchor($this->ied_pc_event, 'save_as_file', gTxt('publish'), array('filename' => $filename), array('title' => gTxt('ied_plugin_export', array('{name}' => $fnames[0]))));
$pubztag = $this->anchor($this->ied_pc_event, 'save_as_file', gTxt('ied_plugin_compress'), array('filename' => $filename, 'type' => 'zip'), array('title' => gTxt('ied_plugin_export', array('{name}' => $fnames[1]))));
$out[] = tr(
n.td(
fInput('checkbox', 'selected-cache[]', $filename),'', 'txp-list-col-multi-edit'
)
.n.td(
tag($filename,'div',' class="ied_subdue"')
.(isset($plugin['name']) ? $efile.$plugpref.'<br />' : '').' '
)
.n.td(
( isset($plugin['author_uri']) ? '<a href="'.$plugin['author_uri'].'">' : '' ) .
( isset($plugin['author']) ? $plugin['author'] : ' ' ).
( isset($plugin['author_uri']) ? '</a>' : '' )
)
.n.td(
(isset($plugin['version']) ? $plugin['version'] : ' ')
)
.n.td(
(isset($plugin['description']) ? $plugin['description'] : ' ')
)
.n.td(
(isset($plugin['name']) ? $pubtag .sp. '|' .sp. $pubztag
: tag(' ', 'span')
)
.sp. '|' .sp. $hlink
)
);
}
}
if ($out) {
$formBlock = '<div class="txp-layout-1col">'.
n. '<form action="index.php" id="ied_plugin_cache_form" method="post">'.
n. '<div class="txp-listtables ied_plugin_cacheplugs">'.
n.startTable('', '', 'txp-list').
n. '<thead>'.
n. tr(
n.hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' class="txp-list-col-multi-edit" scope="col" title="'.gTxt('toggle_all_selected').'"')
.n.hCell(gTxt('plugin'), '', ' class="name"')
.n.hCell(gTxt('author'), '', ' class="author"')
.n.hCell(gTxt('version') . ' ('.gTxt('plugin_modified').')', '', ' class="version"')
.n.hCell(gTxt('description'), '', ' class="description"')
.n.hCell(gTxt('manage'), '', ' class="manage"')
).
n. '</thead>'.
n. '<tbody>'.
n. implode(n, $out).
n. '</tbody>'.
n. endTable().
n. '</div>'.
n. tInput().
$this->multiedit_form('cache', '', $sort, $dir, '', '').
n. '</form>'.
n. '</div>';
echo wrapRegion('ied_plugin_filesystem', $formBlock, 'ied_plugin_cacheplugs', 'ied_plugin_cacheplugs_legend', 'ied_plugin_cacheplugs_visible');
}
}
echo '</div>'.
n. script_js( <<<EOJS
$(document).ready(function () {
$('#ied_plugin_db_form').txpMultiEditForm({
'checkbox' : 'input[name="selected[]"][type=checkbox]'
});
$('#ied_plugin_cache_form').txpMultiEditForm({
'checkbox' : 'input[name="selected-cache[]"][type=checkbox]'
});
var ied_io = $('.ied_plugin_installopts');
$('#ied_plugin_file').change(function() {
var fn = $(this).val();