forked from Deesen/YAMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyams.module.inc.php
More file actions
2540 lines (2494 loc) · 120 KB
/
yams.module.inc.php
File metadata and controls
2540 lines (2494 loc) · 120 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
/**
* Manages the YAMS module interface
*
* @author PMS (http://modxcms.com/forums/index.php?action=profile;u=12570)
* @copyright Nashi Power (http://nashi.podzone.org/) 2009
* @license GPL v3
* @package YAMS (http://modxcms.com/extras/package/?package=543)
* @see Forum (http://modxcms.com/forums/index.php/board,381.0.html)
*
*/
global $modx;
global $_lang;
if ( ! $modx->IsBackend() )
{
exit;
}
require_once( dirname( __FILE__ ) . '/class/yams.utils.class.inc.php' );
require_once( dirname( __FILE__ ) . '/class/yams.class.inc.php' );
// require_once( dirname( __FILE__ ) . '/class/yams.module.mgr.class.inc.php' );
// require_once( dirname( __FILE__ ) . '/class/templator.class.inc.php' );
require_once( dirname( __FILE__ ) . '/yams.module.funcs.inc.php' );
// $YMM = YamsModuleMgr::GetInstance();
// echo $YMM->GetOutput();
// return;
//----------------------------------------------
//do post actions here...
//----------------------------------------------
$yams = YAMS::GetInstance();
$errorText = array();
$mode = 'add';
// Keep track of whether it is necessary
// to update the template variables or not
$updateTVs = FALSE;
$updateServerConfig = FALSE;
// Update tv management if necessary
$manageTVs = $yams->GetManageTVs();
if ( isset( $_POST['yams_manage_tvs'] ) )
{
if ( $_POST['yams_manage_tvs'] == '1' && ! $manageTVs )
{
$yams->SetManageTVs( TRUE );
}
elseif ( $_POST['yams_manage_tvs'] == '0' && $manageTVs )
{
$yams->SetManageTVs( FALSE );
}
}
if ( isset( $_POST['yams_action'] ) )
{
$nMatches =
preg_match(
'/^(edit_multi|edit_mono|default|submit_multi|submit_mono|submit_templates|submit_other_params|cancel|add|deactivate|activate|delete)(,(\S+))?$/'
, $_POST['yams_action']
, $matches
);
if ( $nMatches != 1 )
{
$mode = 'add';
}
else
{
switch ( $matches[1] )
{
case 'edit_multi':
$mode = 'edit_multi';
$edit_lang = $matches[3];
break;
case 'edit_mono':
$mode = 'edit_mono';
// $edit_lang = $matches[3];
break;
case 'default':
$langId = $matches[3];
$success = $yams->SetDefaultLangId( $langId, FALSE );
if ( ! $success )
{
$errorText[] =
'Could not set "'
. YamsUtils::Escape( $langId )
. '" as default lang.';
$yams->Reload();
break;
}
$success = $yams->SaveCurrentSettings();
if ( ! $success )
{
$errorText[] =
'Unable to save settings to file';
}
$mode = 'add';
break;
case 'submit_mono':
if ( ! isset( $_POST['yams_edit_mono_server_name'] ) )
{
$mode = 'add';
break;
}
$serverName = $_POST['yams_edit_mono_server_name'];
$success = $yams->SetMonoServerName( $serverName, FALSE );
if ( ! $success )
{
$errorText[] =
'Could not set server name to "'
. YamsUtils::Escape( $serverName );
$mode = 'add';
$yams->Reload();
break;
}
$success = $yams->SaveCurrentSettings();
if ( ! $success )
{
$errorText[] =
'Unable to save settings to file';
$mode = 'add';
break;
}
$updateServerConfig = TRUE;
$mode = 'add';
break;
case 'submit_multi':
if (
!isset( $_POST['yams_edit_tags'] )
|| !isset( $_POST['yams_edit_choose_lang_text'])
|| !isset( $_POST['yams_edit_modx_lang_name'])
|| !isset( $_POST['yams_edit_root_name'])
|| !isset( $_POST['yams_edit_server_name'])
|| !isset( $_POST['yams_edit_is_ltr'])
|| !isset( $_POST['yams_edit_roles_list'])
)
{
$mode = 'add';
break;
}
$allLangIds = array_merge(
$yams->GetActiveLangIds()
, $yams->GetInactiveLangIds()
);
foreach ( $allLangIds as $whichLangId )
{
if ( !isset( $_POST['yams_edit_name_' . $whichLangId ] ) )
{
$mode = 'add';
$errorText[] =
'Internal error: Name for '
. YamsUtils::Escape( $whichLangId )
. ' not set';
$yams->Reload();
break 2;
}
}
$tags = $_POST['yams_edit_tags'];
$chooseLangText = $_POST['yams_edit_choose_lang_text'];
$modxLangName = $_POST['yams_edit_modx_lang_name'];
$rootName = $_POST['yams_edit_root_name'];
$serverName = $_POST['yams_edit_server_name'];
if ( $_POST['yams_edit_is_ltr'] == '1' )
{
$isLTR = TRUE;
}
else
{
$isLTR = FALSE;
}
$rolesList = $_POST['yams_edit_roles_list'];
$langId = $matches[3];
foreach ( $allLangIds as $whichLangId )
{
$name = $_POST['yams_edit_name_' . $whichLangId ];
$success = $yams->SetLangName( $langId, $name, $whichLangId, FALSE );
if ( ! $success )
{
$errorText[] =
'Could not set name to "'
. YamsUtils::Escape( $name )
. '" for lang "'
. YamsUtils::Escape( $whichLangId )
. '" in lang "'
. YamsUtils::Escape( $langId )
. '"';
$mode = 'add';
$yams->Reload();
break 2;
}
}
$success = $yams->SetLangTagsText( $langId, $tags, FALSE );
if ( ! $success )
{
$errorText[] =
'Could not set tags to "'
. YamsUtils::Escape( $tags )
. '" for lang "'
. YamsUtils::Escape( $langId ) . '"';
$mode = 'add';
$yams->Reload();
break;
}
$success = $yams->SetChooseLangText( $langId, $chooseLangText, FALSE );
if ( ! $success )
{
$errorText[] =
'Could not set choose lang text "'
. YamsUtils::Escape( $chooseLangText )
. '" for lang "'
. YamsUtils::Escape( $langId ) . '"';
$mode = 'add';
$yams->Reload();
break;
}
$success = $yams->SetMODxLangName( $langId, $modxLangName, FALSE );
if ( ! $success )
{
$errorText[] =
'Could not set the MODx language name"'
. YamsUtils::Escape( $modxLangName )
. '" for lang "'
. YamsUtils::Escape( $langId ) . '"';
$mode = 'add';
$yams->Reload();
break;
}
$success = $yams->SetRootName( $langId, $rootName, FALSE );
if ( ! $success )
{
$errorText[] =
'Could not set root name to "'
. YamsUtils::Escape( $rootName )
. '" for lang "'
. YamsUtils::Escape( $langId ) . '"';
$mode = 'add';
$yams->Reload();
break;
}
$success = $yams->SetServerName( $langId, $serverName, FALSE );
if ( ! $success )
{
$errorText[] =
'Could not set server name to "'
. YamsUtils::Escape( $serverName )
. '" for lang "'
. YamsUtils::Escape( $langId ) . '"';
$mode = 'add';
$yams->Reload();
break;
}
$success = $yams->SetIsLTR( $langId, $isLTR, FALSE );
if ( ! $success )
{
$errorText[] =
'Could not set isLTR to "'
. YamsUtils::Escape( $isLTR )
. '" for lang "'
. YamsUtils::Escape( $langId ) . '"';
$mode = 'add';
$yams->Reload();
break;
}
$success = $yams->SetRolesAccessList( $langId, $rolesList, FALSE );
if ( ! $success )
{
$errorText[] =
'Could not set rolesList to "'
. YamsUtils::Escape( $rolesList )
. '" for lang "'
. YamsUtils::Escape( $langId ) . '"';
$mode = 'add';
$yams->Reload();
break;
}
$success = $yams->SaveCurrentSettings();
if ( ! $success )
{
$errorText[] =
'Unable to save settings to file';
$mode = 'add';
break;
}
$mode = 'add';
$updateServerConfig = TRUE;
break;
case 'submit_templates':
// Build up the activeTemplates array
$activeTemplates = array();
$limit = $yams->GetTemplateInfo( $info );
for ( $i = 0; $i < $limit; $i++ )
{
$row = mysql_fetch_assoc( $info );
if (
isset( $_POST['template,' . $row['id']] )
&& $_POST['template,' . $row['id']] == '1'
)
{
$activeTemplates[ $row['id'] ] = NULL;
}
}
// $errorText[] = print_r( $activeTemplates, TRUE );
$success = $yams->SetActiveTemplates( $activeTemplates );
if ( !$success )
{
$errorText[] =
'Failed to set active templates: '
. YamsUtils::Escape(
print_r( $activeTemplates, TRUE )
);
break;
}
$updateTVs = TRUE;
break;
case 'submit_other_params':
$success = $yams->SetRedirectionMode( $_POST['yams_redirection_mode'] );
if ( ! $success )
{
$errorText[] = 'Could not set redirection.';
}
$success = $yams->SetHTTPStatus( $_POST['yams_http_status'] );
if ( ! $success )
{
$errorText[] = 'Could not set the http status for redirection to the default language.';
}
$success = $yams->SetHTTPStatusNotDefault( $_POST['yams_http_status_not_default'] );
if ( ! $success )
{
$errorText[] = 'Could not set the http status for redirection to non-default languages.';
}
$success = $yams->SetHTTPStatusChangeLang( $_POST['yams_http_status_change_lang'] );
if ( ! $success )
{
$errorText[] = 'Could not set the http status for changing languages.';
}
$success = $yams->SetAcceptMODxURLDocIdsString( $_POST['yams_accept_modx_url_doc_ids'] );
if ( ! $success )
{
$errorText[] = 'Could not set the list of index.php?id= document ids.';
}
$success = $yams->SetHideFields( $_POST['yams_hide_fields'] );
if ( ! $success )
{
$errorText[] = 'Could not set the \'hide fields\' option.';
}
$success = $yams->SetTabifyLangs( $_POST['yams_tabify_langs'] );
if ( ! $success )
{
$errorText[] = 'Could not set the \'tabify langs\' option.';
}
$success = $yams->SetSynchronisePagetitle( $_POST['yams_synchronise_pagetitle'] );
if ( ! $success )
{
$errorText[] = 'Could not set the \'synchronise pagetitle\' option.';
}
$success = $yams->SetEasyLingualCompatibility( $_POST['yams_easylingual_compatibility'] );
if ( ! $success )
{
$errorText[] = 'Could not set the \'EasyLingual Compatibility\' option.';
}
$success = $yams->SetUseMimeDependentSuffixes( $_POST['yams_use_mime_dependent_suffixes'] );
if ( ! $success )
{
$errorText[] = 'Could not set the \'use mime dependent suffixes\' option.';
}
$success = $yams->SetUseStripAlias( $_POST['yams_use_strip_alias'] );
if ( ! $success )
{
$errorText[] = 'Could not set the \'use strip alias\' option.';
}
$success = $yams->SetShowSiteStartAlias( $_POST['yams_show_site_start_alias'] );
if ( ! $success )
{
$errorText[] = 'Could not set the \'Show site start alias\' option.';
}
$success = $yams->SetRewriteContainersAsFolders( $_POST['yams_rewrite_containers_as_folders'] );
if ( ! $success )
{
$errorText[] = 'Could not set the \'Rewrite containers as folders\' option.';
}
$success = $yams->SetLangQueryParam( $_POST['yams_lang_query_param'] );
if ( ! $success )
{
$errorText[] = 'Could not set the \'current language GET parameter\' option.';
}
$success = $yams->SetChangeLangQueryParam( $_POST['yams_change_lang_query_param'] );
if ( ! $success )
{
$errorText[] = 'Could not set the \'change language GET/POST parameter\' option.';
}
$success = $yams->SetMODxSubdirectory( $_POST['yams_modx_subdirectory'] );
if ( ! $success )
{
$errorText[] = 'Could not set the \'set MODx subdirectory\' option.';
}
$success = $yams->SetURLConversionMode( $_POST['yams_url_conversion_mode'] );
if ( ! $success )
{
$errorText[] = 'Could not set the URL conversion mode.';
}
$oldUseMultilingualAliases = $yams->GetUseMultilingualAliases();
$success = $yams->SetUseMultilingualAliases( $_POST['yams_use_multilingual_aliases'] );
if ( ! $success )
{
$errorText[] = 'Could not set the \'Use multiilingual aliases\' option.';
}
else
{
$newUseMultilingualAliases = $yams->GetUseMultilingualAliases();
if ( $oldUseMultilingualAliases != $newUseMultilingualAliases )
{
$updateTVs = TRUE;
}
}
$oldMultilingualAliasesAreUnique = $yams->GetMultilingualAliasesAreUnique();
$success = $yams->SetMultilingualAliasesAreUnique( $_POST['yams_multilingual_aliases_are_unique'] );
if ( ! $success )
{
$errorText[] = 'Could not set the \'Multiilingual aliases are unique\' option.';
}
else
{
$newMultilingualAliasesAreUnique = $yams->GetMultilingualAliasesAreUnique();
if ( $oldMultilingualAliasesAreUnique != $newMultilingualAliasesAreUnique )
{
$updateTVs = TRUE;
}
}
break;
case 'add':
if (
!isset( $_POST['yams_add_lang'] )
|| !isset( $_POST['yams_add_tags'] )
|| !isset( $_POST['yams_add_choose_lang_text'] )
|| !isset( $_POST['yams_add_modx_lang_name'] )
|| !isset( $_POST['yams_add_root_name'] )
|| !isset( $_POST['yams_add_server_name'] )
|| !isset( $_POST['yams_add_is_ltr'] )
|| !isset( $_POST['yams_add_name_new'] )
)
{
$mode = 'add';
break;
}
$allLangIds = array_merge(
$yams->GetActiveLangIds()
, $yams->GetInactiveLangIds()
);
foreach ( $allLangIds as $whichLangId )
{
if ( !isset( $_POST['yams_add_name_' . $whichLangId ] ) )
{
$mode = 'add';
break 2;
}
}
$langId = $_POST['yams_add_lang'];
$tags = $_POST['yams_add_tags'];
$chooseLangText = $_POST['yams_add_choose_lang_text'];
$modxLangName = $_POST['yams_add_modx_lang_name'];
$rootName = $_POST['yams_add_root_name'];
$serverName = $_POST['yams_add_server_name'];
$isLTR = $_POST['yams_add_is_ltr'];
$langNames = array();
foreach ( $allLangIds as $whichLangId )
{
$langNames[ $whichLangId ] = $_POST['yams_add_name_' . $whichLangId ];
}
$langNames[ $langId ] = $_POST['yams_add_name_new'];
$success = $yams->AddLang(
$langId
, $tags
, $chooseLangText
, $modxLangName
, $rootName
, $serverName
, $langNames
, $isLTR
, TRUE
);
if ( ! $success )
{
$errorText[] =
'Could not add language with lang id "'
. YamsUtils::Escape( $langId )
. '"';
$mode = 'add';
break;
}
$updateTVs = TRUE;
$mode = 'add';
break;
case 'deactivate':
$langId = $matches[3];
$success = $yams->DeactivateLangId( $langId );
if ( ! $success )
{
$errorText[] =
'Could not deactivate lang "'
. YamsUtils::Escape( $langId )
. '"';
$mode = 'add';
break;
}
$updateTVs = TRUE;
$updateServerConfig = TRUE;
$mode = 'add';
break;
case 'activate':
$langId = $matches[3];
$success = $yams->ActivateLangId( $langId );
if ( ! $success )
{
$errorText[] =
'Could not activate lang "'
. YamsUtils::Escape( $langId )
. '"';
$mode = 'add';
break;
}
$updateTVs = TRUE;
$updateServerConfig = TRUE;
$mode = 'add';
break;
case 'delete':
$langId = $matches[3];
$success = $yams->DeleteLang( $langId );
if ( ! $success )
{
$errorText[] =
'Could not delete lang "'
. YamsUtils::Escape( $langId )
. '"';
$mode = 'add';
break;
}
$mode = 'add';
break;
case 'cancel':
default:
$mode = 'add';
}
}
}
// Check to see if the URLs of the active langs are unique
// if ( ! $yams->ActiveURLsAreUnique() )
// {
// $errorText[] = 'Warning: The URLs of the active languages are not unique! Please alter the root names or the server names to make them unique.';
// }
if ( $updateServerConfig )
{
$errorText[] = 'The .htaccess or server configuration may required updating as a result of the change that has just been made. The current setup should be checked against the Server Config tab.';
}
$activeLangIds = $yams->GetActiveLangIds();
$inactiveLangIds = $yams->GetInactiveLangIds();
$allLangIds = array_merge( $activeLangIds, $inactiveLangIds );
$defaultLangId = $yams->GetDefaultLangId();
if ( $updateTVs )
{
// Get a list of the current TV names
YamsGetMODxTVs( $modxTVs );
// Loop over the template variables
$tvs = $yams->GetDocVarNames();
// $tvCaption = array(
// 'pagetitle' => 'Title'
// , 'longtitle' => 'Long Title'
// , 'description' => 'Description'
// , 'introtext' => 'Summary'
// , 'menutitle' => 'Menu Title'
// , 'content' => 'Content'
// );
// Loop over the template variables
foreach ( $tvs as $tv )
{
// Loop over the active languages
// create template variables which don't exist
foreach ( $activeLangIds as $langId )
{
// Check if the template variable exists.
// If not, create it
$newlyCreatedTV = FALSE;
$newlyAssociatedTV = FALSE;
$multiLangTV = $tv . '_' . $langId;
if ( ! array_key_exists(
$multiLangTV
, $modxTVs
) )
{
// The template variable doesn't exist
if ( $yams->GetManageTVs() )
{
// Create the template variable
// and get the template variable id
$tvType = $yams->GetDocVarType( $tv );
$tvCaption = $yams->GetDocVarCaption( $tv, $langId );
$data = array(
'name' => $modx->db->escape( $multiLangTV )
, 'caption' => $modx->db->escape( $tvCaption )
, 'description' => $modx->db->escape( $tv . ' (' . $langId . ')' )
, 'type' => $modx->db->escape( $tvType )
, 'elements' => ''
, 'display' => ''
, 'rank' => 0
, 'locked' => 0
);
$tblName = $modx->getFullTableName('site_tmplvars');
$tvId =
$modx->db->insert(
$data
, $tblName
);
// Set a flag to say that it is newly created.
if ( $tvId )
{
$newlyCreatedTV = TRUE;
$errorText[] = 'Created a template variable called "' . $multiLangTV . '" (' . $tvId . ').';
}
else
{
$errorText[] = 'Error creating a template variable called "' . $multiLangTV . '".';
}
}
else
{
// Get the user to create the tvs manually
$errorText[] = 'Please create a template variable called "' . $multiLangTV . '" and associate it with the active templates.';
}
}
// Now check that the template variables are
// associated with the correct templates.
// Each multilingual tv should be associated
// with each active template
// Get the id of the template variable in question
if ( ! $newlyCreatedTV )
{
$tvId = $modxTVs[ $multiLangTV ];
}
// Get all the templates currently associated with this tv
YamsGetMODxTemplatesForTV( $tvId, $templates );
$templateIds = array_keys( $templates );
// If the tv is not associated with an active template
// create that association
$unAssociatedActiveTemplates = array_diff(
$yams->GetActiveTemplates()
, $templateIds
);
if ( $yams->GetManageTVs() )
{
foreach ( $unAssociatedActiveTemplates as $templateId )
{
// Associate template variable tvId with template templateId
$newId = YamsAddAssociationForTV( $tvId, $templateId );
if ( ! $newId )
{
$errorText[] = 'Failed to associate template variable ' . $multiLangTV . '" with template number ' . $templateId . ' .';
}
else
{
$newlyAssociatedTV = TRUE;
$errorText[] = 'Associated template variable "' . $multiLangTV . '" with template number ' . $templateId . ' .';
}
}
}
else
{
foreach ( $unAssociatedActiveTemplates as $templateId )
{
$errorText[] = 'Template variable "' . $multiLangTV . '" needs to be associated with template number ' . $templateId . ' .';
}
}
// If the tv is associated with an inactive template
// remove that association
// If the tv is not associated with an active template
// create that association
$associatedInactiveTemplates = array_diff(
$templateIds
, $yams->GetActiveTemplates()
);
if ( $yams->GetManageTVs() )
{
if ( count($associatedInactiveTemplates) > 0 )
{
$result = YamsRemoveAssociationsForTV( $tvId, $associatedInactiveTemplates );
if ( ! $result )
{
$errorText[] = 'Error when removing association of "' . $multiLangTV . '" with template(s) ' . implode( ',', $associatedInactiveTemplates ) . ' .';
}
else
{
$errorText[] = 'Removed association of template variable "' . $multiLangTV . '" with template(s) ' . implode( ',', $associatedInactiveTemplates ) . ' .';
}
}
}
else
{
foreach ( $associatedInactiveTemplates as $templateId )
{
$errorText[] = 'Template variable "' . $multiLangTV . '" does not need to be associated with template number ' . $templateId . ' .';
}
}
if ( $yams->GetManageTVs() )
{
// Handle the default content for newly created template variables
if ( $newlyCreatedTV || $newlyAssociatedTV )
{
switch ( $tv )
{
case 'alias':
if (! $yams->GetUseMultilingualAliases() )
{
break;
}
// Create a list of active templates
$activeTemplates = $yams->GetActiveTemplates();
if ( count( $activeTemplates ) > 0 )
{
// Get a list of all documents that have these templates
// Loop over the documents.
$result =
$modx->db->select(
'id,' . $modx->db->escape( $tv )
, $modx->getFullTableName('site_content')
, 'template IN ('
. implode(',', $activeTemplates)
. ') AND deleted=0'
);
// For each document copy the content from the
// document variable to the template variable
$nDocs = mysql_num_rows( $result );
for ( $i = 0; $i < $nDocs; $i++ )
{
$row = mysql_fetch_assoc( $result );
$id = $row['id'];
$tvVal = $row[ $tv ];
if ( $yams->GetMultilingualAliasesAreUnique() )
{
// Prepend the document alias by the language id
// to make it unique - except for the default
// language - which can have the same alias
// as the document variable...
if ( $langId == $yams->GetDefaultLangId() )
{
$tvVal = $tvVal;
}
else
{
$tvVal = $langId . '-' . $tvVal;
}
}
if ( $tvVal == '' )
{
// The content is empty, so there is nothing to copy
continue;
}
// Check if there is any existing content.
// If so, leave it as is...
$selectResult =
$modx->db->select(
'value'
, $modx->getFullTableName('site_tmplvar_contentvalues')
, 'tmplvarid='
. $modx->db->escape( $tvId )
. ' AND contentid='
. $modx->db->escape( $id )
);
$selectNRows = mysql_num_rows( $selectResult );
if ( $selectNRows > 1)
{
// error, there should only be 1 result...
continue;
}
if ( $selectNRows == 1 )
{
$row = mysql_fetch_assoc( $selectResult );
if ( $row['value'] != '' )
{
// Content is already exists
// Leave it as is...
continue;
}
// Copy over the content...
$data = array(
'value' => $modx->db->escape( $tvVal )
);
$success =
$modx->db->update(
$data
, $modx->getFullTableName('site_tmplvar_contentvalues')
, 'tmplvarid='
. $modx->db->escape( $tvId )
. ' AND contentid='
. $modx->db->escape( $id )
);
if ( $success )
{
$errorText[] = 'Copied content from ' . YamsUtils::Escape( $tv ) . ' field to newly created ' . YamsUtils::Escape( $multiLangTV ) . ' for document ' . $id . '.';
}
else
{
$errorText[] = 'Failed to copy content from ' . YamsUtils::Escape( $tv ) . ' field to newly created ' . YamsUtils::Escape( $multiLangTV ) . ' for document ' . $id . '.';
}
continue;
}
$data = array(
'tmplvarid' => $modx->db->escape( $tvId )
, 'contentid' => $modx->db->escape( $id )
, 'value' => $modx->db->escape( $tvVal )
);
$success =
$modx->db->insert(
$data
, $modx->getFullTableName('site_tmplvar_contentvalues')
);
if ( $success )
{
$errorText[] = 'Copied content from ' . YamsUtils::Escape( $tv ) . ' field to newly created ' . YamsUtils::Escape( $multiLangTV ) . ' for document ' . YamsUtils::Escape( $id ) . '.';
}
else
{
$errorText[] = 'Failed to copy content from ' . YamsUtils::Escape( $tv ) . ' field to newly created ' . YamsUtils::Escape( $multiLangTV ) . ' for document ' . YamsUtils::Escape( $id ) . '.';
}
}
}
break;
default:
// If this is the default lang and this is
// a newly created template variable,
// copy content from the document variable field
// into the template variable for all documents
// belonging to all active templates.
if ( $langId != $yams->GetDefaultLangId() )
{
break;
}
// Create a list of active templates
$activeTemplates = $yams->GetActiveTemplates();
if ( count( $activeTemplates ) > 0 )
{
// Get a list of all documents that have these templates
// Loop over the documents.
$result =
$modx->db->select(
'id,' . $modx->db->escape( $tv )
, $modx->getFullTableName('site_content')
, 'template IN ('
. implode(',', $activeTemplates)
. ') AND deleted=0'
);
// For each document copy the content from the
// document variable to the template variable
$nDocs = mysql_num_rows( $result );
for ( $i = 0; $i < $nDocs; $i++ )
{
$row = mysql_fetch_assoc( $result );
$id = $row['id'];
$tvVal = $row[ $tv ];
if ( $tvVal == '' )
{
// The content is empty, so there is nothing to copy
continue;
}
// Check if there is any existing content.
// If so, leave it as is...
$selectResult =
$modx->db->select(
'value'
, $modx->getFullTableName('site_tmplvar_contentvalues')
, 'tmplvarid='
. $modx->db->escape( $tvId )
. ' AND contentid='
. $modx->db->escape( $id )
);
$selectNRows = mysql_num_rows( $selectResult );
if ( $selectNRows > 1)
{
// error, there should only be 1 result...
continue;
}
if ( $selectNRows == 1 )
{
$row = mysql_fetch_assoc( $selectResult );
if ( $row['value'] != '' )
{
// Content is already exists
// Leave it as is...
continue;
}
// Copy over the content...
$data = array(
'value' => $modx->db->escape( $tvVal )
);
$success =
$modx->db->update(
$data
, $modx->getFullTableName('site_tmplvar_contentvalues')
, 'tmplvarid='
. $modx->db->escape( $tvId )
. ' AND contentid='
. $modx->db->escape( $id )
);
if ( $success )
{
$errorText[] = 'Copied content from ' . $tv . ' field to newly created ' . YamsUtils::Escape( $multiLangTV ) . ' for document ' . $id . '.';
}
else
{
$errorText[] = 'Failed to copy content from ' . $tv . ' field to newly created ' . YamsUtils::Escape( $multiLangTV ) . ' for document ' . $id . '.';
}
continue;
}
$data = array(
'tmplvarid' => $modx->db->escape( $tvId )
, 'contentid' => $modx->db->escape( $id )
, 'value' => $modx->db->escape( $tvVal )
);
$success =
$modx->db->insert(
$data
, $modx->getFullTableName('site_tmplvar_contentvalues')
);
if ( $success )
{
$errorText[] = 'Copied content from ' . $tv . ' field to newly created ' . YamsUtils::Escape( $multiLangTV ) . ' for document ' . $id . '.';
}
else
{
$errorText[] = 'Failed to copy content from ' . $tv . ' field to newly created ' . YamsUtils::Escape( $multiLangTV ) . ' for document ' . $id . '.';
}
}
}
}
}
}
}
}
}
if ( ! YamsUtils::IsHTTPS() )
{
$protocol = 'http://';
}
else
{
$protocol = 'https://';
}
$errorOutput = '';
// Define the placholders
if ( count( $errorText ) > 0 )
{
foreach ( $errorText as $index => $message )
{
$errorText[$index] = YamsUtils::Escape( $message );
}
$errorOutput =
'<p class="warning">'
. implode('<br />', $errorText )
. '</p>';
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $modx->config['manager_direction']; ?>" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $modx->config['modx_charset']; ?>" />
<title>YAMS Module Configuration</title>
<link rel="stylesheet" type="text/css" href="media/style/<?php echo $modx->config['manager_theme']; ?>/style.css" ></link>
<script type="text/javascript" src="media/script/scriptaculous/prototype.js"></script>
<script type="text/javascript" src="media/script/scriptaculous/scriptaculous.js"></script>
<script type="text/javascript" src="media/script/modx.js" ></script>
<script type="text/javascript" src="media/script/cb2.js" ></script>
<script type="text/javascript" src="media/script/tabpane.js" ></script>
<script type="text/javascript" src="media/script/datefunctions.js" ></script>