-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
SiteSettingsViewController.m
1228 lines (1014 loc) · 45.7 KB
/
SiteSettingsViewController.m
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
#import "SiteSettingsViewController.h"
#import "Blog.h"
#import "BlogService.h"
#import "BlogSiteVisibilityHelper.h"
#import "CoreDataStack.h"
#import "NSURL+IDN.h"
#import "PostCategory.h"
#import "PostCategoryService.h"
#import "RelatedPostsSettingsViewController.h"
#import "SettingsSelectionViewController.h"
#import "SettingsMultiTextViewController.h"
#import "SettingTableViewCell.h"
#import "SettingsTextViewController.h"
#import "SVProgressHUD+Dismiss.h"
#import "WordPress-Swift.h"
#import "WPWebViewController.h"
#import <wpxmlrpc/WPXMLRPC.h>
#import "AccountService.h"
@import WordPressKit;
NS_ENUM(NSInteger, SiteSettingsAccount) {
SiteSettingsAccountUsername = 0,
SiteSettingsAccountPassword,
SiteSettingsAccountCount,
};
NS_ENUM(NSInteger, SiteSettingsHomepage) {
SiteSettingsHomepageSettings = 0,
SiteSettingsHomepageCount,
};
NS_ENUM(NSInteger, SiteSettingsEditor) {
SiteSettingsEditorSelector = 0,
SiteSettingsEditorCount,
};
NS_ENUM(NSInteger, SiteSettingsWriting) {
SiteSettingsWritingDefaultCategory = 0,
SiteSettingsWritingTags,
SiteSettingsWritingDefaultPostFormat,
SiteSettingsWritingRelatedPosts,
SiteSettingsWritingDateAndTimeFormat,
SiteSettingsPostPerPage,
SiteSettingsSpeedUpYourSite,
};
NS_ENUM(NSInteger, SiteSettingsAdvanced) {
SiteSettingsAdvancedStartOver = 0,
SiteSettingsAdvancedExportContent,
SiteSettingsAdvancedDeleteSite,
SiteSettingsAdvancedCount,
};
NS_ENUM(NSInteger, SiteSettingsJetpack) {
SiteSettingsJetpackSecurity = 0,
SiteSettingsJetpackConnection,
SiteSettingsJetpackCount,
};
static NSString *const EmptySiteSupportURL = @"https://en.support.wordpress.com/empty-site";
@interface SiteSettingsViewController () <UITableViewDelegate, UITextFieldDelegate, JetpackConnectionDelegate, PostCategoriesViewControllerDelegate>
#pragma mark - Account Section
@property (nonatomic, strong) SettingTableViewCell *usernameTextCell;
@property (nonatomic, strong) SettingTableViewCell *passwordTextCell;
#pragma mark - Writing Section
@property (nonatomic, strong) SwitchTableViewCell *editorSelectorCell;
@property (nonatomic, strong) SettingTableViewCell *defaultCategoryCell;
@property (nonatomic, strong) SettingTableViewCell *tagsCell;
@property (nonatomic, strong) SettingTableViewCell *defaultPostFormatCell;
@property (nonatomic, strong) SettingTableViewCell *relatedPostsCell;
@property (nonatomic, strong) SettingTableViewCell *dateAndTimeFormatCell;
@property (nonatomic, strong) SettingTableViewCell *postsPerPageCell;
@property (nonatomic, strong) SettingTableViewCell *speedUpYourSiteCell;
#pragma mark - Media Section
@property (nonatomic, strong) MediaQuotaCell *mediaQuotaCell;
#pragma mark - Discussion Section
@property (nonatomic, strong) SettingTableViewCell *discussionSettingsCell;
#pragma mark - Traffic Section
@property (nonatomic, strong) SwitchTableViewCell *ampSettingCell;
#pragma mark - Jetpack Settings Section
@property (nonatomic, strong) SettingTableViewCell *jetpackSecurityCell;
@property (nonatomic, strong) SettingTableViewCell *jetpackConnectionCell;
#pragma mark - Device Section
@property (nonatomic, strong) SwitchTableViewCell *geotaggingCell;
#pragma mark - Advanced Section
@property (nonatomic, strong) SettingTableViewCell *startOverCell;
@property (nonatomic, strong) WPTableViewCell *exportContentCell;
@property (nonatomic, strong) WPTableViewCell *deleteSiteCell;
@property (nonatomic, strong) Blog *blog;
@property (nonatomic, strong) NSString *username;
@property (nonatomic, strong) NSString *password;
@property (nonatomic, strong) NSArray<NSNumber *> *tableSections;
@property (nonatomic, strong) NSArray<NSNumber *> *writingSectionRows;
@end
@implementation SiteSettingsViewController
- (instancetype)initWithBlog:(Blog *)blog
{
NSParameterAssert([blog isKindOfClass:[Blog class]]);
self = [super initWithStyle:UITableViewStyleInsetGrouped];
if (self) {
_blog = blog;
_username = blog.usernameForSite;
_password = blog.password;
[WPStyleGuide configureAutomaticHeightRowsFor:self.tableView];
}
return self;
}
- (void)viewDidLoad
{
DDLogMethod();
[super viewDidLoad];
[self.tableView registerClass:[SettingTableViewCell class] forCellReuseIdentifier:SettingsTableViewCellReuseIdentifier];
[self.tableView registerNib:MediaQuotaCell.nib forCellReuseIdentifier:MediaQuotaCell.defaultReuseIdentifier];
self.navigationItem.title = NSLocalizedString(@"Settings", @"Title for screen that allows configuration of your blog/site settings.");
self.extendedLayoutIncludesOpaqueBars = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleDataModelChange:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:self.blog.managedObjectContext];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleAccountChange:)
name:WPAccountDefaultWordPressComAccountChangedNotification
object:nil];
[WPStyleGuide configureColorsForView:self.view andTableView:self.tableView];
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(refreshTriggered:) forControlEvents:UIControlEventValueChanged];
if (self.presentingViewController) {
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismiss)];
}
[self refreshData];
[self observeTimeZoneStore];
self.tableView.accessibilityIdentifier = @"siteSettingsTable";
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.tableView reloadData];
}
- (NSArray *)tableSections
{
if (_tableSections) {
return _tableSections;
}
NSMutableArray *sections = [NSMutableArray arrayWithObjects:@(SiteSettingsSectionGeneral), nil];
if (self.bloggingSettingsRowCount > 0) {
[sections addObject:@(SiteSettingsSectionBlogging)];
}
if ([Feature enabled:FeatureFlagHomepageSettings] && [self.blog supports:BlogFeatureHomepageSettings]) {
[sections addObject:@(SiteSettingsSectionHomepage)];
}
if (!self.blog.account) {
[sections addObject:@(SiteSettingsSectionAccount)];
}
// Only add the editor section if the site is not a Simple WP.com site
if (![GutenbergSettings isSimpleWPComSite:self.blog]) {
[sections addObject:@(SiteSettingsSectionEditor)];
}
if ([self.blog supports:BlogFeatureWPComRESTAPI] && self.blog.isAdmin) {
[sections addObject:@(SiteSettingsSectionWriting)];
[sections addObject:@(SiteSettingsSectionDiscussion)];
if (self.blog.isQuotaAvailable) {
[sections addObject:@(SiteSettingsSectionMedia)];
}
if (self.blog.isHostedAtWPcom && self.blog.settings.ampSupported) {
[sections addObject:@(SiteSettingsSectionTraffic)];
}
if ([self.blog supports:BlogFeatureJetpackSettings]) {
[sections addObject:@(SiteSettingsSectionJetpackSettings)];
}
}
if ([self.blog supports:BlogFeatureSiteManagement]) {
[sections addObject:@(SiteSettingsSectionAdvanced)];
}
_tableSections = sections;
return sections;
}
- (NSArray *)writingSectionRows
{
if (_writingSectionRows) {
return _writingSectionRows;
}
NSMutableArray *rows = [NSMutableArray arrayWithObjects:
@(SiteSettingsWritingDefaultCategory),
@(SiteSettingsWritingTags),
@(SiteSettingsWritingDefaultPostFormat), nil];
BOOL jetpackFeaturesEnabled = [JetpackFeaturesRemovalCoordinator jetpackFeaturesEnabled];
if (jetpackFeaturesEnabled) {
[rows addObject:@(SiteSettingsWritingRelatedPosts)];
}
[rows addObject:@(SiteSettingsWritingDateAndTimeFormat)];
[rows addObject:@(SiteSettingsPostPerPage)];
if (jetpackFeaturesEnabled && [self.blog supports:BlogFeatureJetpackImageSettings]) {
[rows addObject:@(SiteSettingsSpeedUpYourSite)];
}
_writingSectionRows = rows;
return rows;
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.tableSections.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger settingsSection = [self.tableSections[section] integerValue];
switch (settingsSection) {
case SiteSettingsSectionGeneral:
{
return self.generalSettingsRowCount;
}
case SiteSettingsSectionBlogging:
return self.bloggingSettingsRowCount;
case SiteSettingsSectionHomepage:
{
return SiteSettingsHomepageCount;
}
case SiteSettingsSectionAccount:
{
return SiteSettingsAccountCount;
}
case SiteSettingsSectionEditor:
{
return SiteSettingsEditorCount;
}
case SiteSettingsSectionWriting:
{
return self.writingSectionRows.count;
}
case SiteSettingsSectionMedia:
{
return 1;
}
case SiteSettingsSectionDiscussion:
{
return 1;
}
case SiteSettingsSectionTraffic:
{
return 1;
}
case SiteSettingsSectionJetpackSettings:
{
if ([Feature enabled:FeatureFlagJetpackDisconnect]) {
return SiteSettingsJetpackCount;
}
return 1;
}
case SiteSettingsSectionAdvanced:
{
return SiteSettingsAdvancedCount;
}
}
return 0;
}
- (SettingTableViewCell *)usernameTextCell
{
if (_usernameTextCell){
return _usernameTextCell;
}
_usernameTextCell = [[SettingTableViewCell alloc] initWithLabel:NSLocalizedString(@"Username", @"Label for entering username in the username field")
editable:NO
reuseIdentifier:nil];
return _usernameTextCell;
}
- (SettingTableViewCell *)passwordTextCell
{
if (_passwordTextCell) {
return _passwordTextCell;
}
_passwordTextCell = [[SettingTableViewCell alloc] initWithLabel:NSLocalizedString(@"Password", @"Label for entering password in password field")
editable:YES
reuseIdentifier:nil];
return _passwordTextCell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForAccountSettingsInRow:(NSInteger)row
{
switch (row) {
case SiteSettingsAccountUsername:
if (self.blog.usernameForSite) {
[self.usernameTextCell setTextValue:self.blog.usernameForSite];
} else {
[self.usernameTextCell setTextValue:NSLocalizedString(@"Enter username", @"(placeholder) Help enter WordPress username")];
}
return self.usernameTextCell;
case SiteSettingsAccountPassword:
if (self.blog.password) {
[self.passwordTextCell setTextValue:@"••••••••"];
} else {
[self.passwordTextCell setTextValue:NSLocalizedString(@"Enter password", @"(placeholder) Help enter WordPress password")];
}
return self.passwordTextCell;
}
return nil;
}
- (SwitchTableViewCell *)editorSelectorCell
{
if (!_editorSelectorCell) {
_editorSelectorCell = [SwitchTableViewCell new];
_editorSelectorCell.name = NSLocalizedString(@"Use block editor", @"Option to enable the block editor for new posts");
_editorSelectorCell.flipSwitch.accessibilityIdentifier = @"useBlockEditorSwitch";
__weak Blog *blog = self.blog;
_editorSelectorCell.onChange = ^(BOOL value){
[GutenbergSettings setGutenbergEnabled:value forBlog:blog];
[GutenbergSettings postSettingsToRemoteForBlog:blog];
};
}
return _editorSelectorCell;
}
- (SettingTableViewCell *)defaultCategoryCell
{
if (_defaultCategoryCell){
return _defaultCategoryCell;
}
_defaultCategoryCell = [[SettingTableViewCell alloc] initWithLabel:NSLocalizedString(@"Default Category", @"Label for selecting the default category of a post")
editable:YES
reuseIdentifier:nil];
return _defaultCategoryCell;
}
- (SettingTableViewCell *)tagsCell
{
if (_tagsCell){
return _tagsCell;
}
_tagsCell = [[SettingTableViewCell alloc] initWithLabel:NSLocalizedString(@"Tags", @"Label for selecting the blogs tags")
editable: self.blog.isAdmin
reuseIdentifier:nil];
return _tagsCell;
}
- (SettingTableViewCell *)defaultPostFormatCell
{
if (_defaultPostFormatCell){
return _defaultPostFormatCell;
}
_defaultPostFormatCell = [[SettingTableViewCell alloc] initWithLabel:NSLocalizedString(@"Default Post Format", @"Label for selecting the default post format")
editable:YES
reuseIdentifier:nil];
return _defaultPostFormatCell;
}
- (SettingTableViewCell *)relatedPostsCell
{
if (_relatedPostsCell){
return _relatedPostsCell;
}
_relatedPostsCell = [[SettingTableViewCell alloc] initWithLabel:NSLocalizedString(@"Related Posts", @"Label for selecting the related posts options")
editable:YES
reuseIdentifier:nil];
return _relatedPostsCell;
}
- (SettingTableViewCell *)dateAndTimeFormatCell
{
if (_dateAndTimeFormatCell) {
return _dateAndTimeFormatCell;
}
_dateAndTimeFormatCell = [[SettingTableViewCell alloc] initWithLabel:NSLocalizedString(@"Date and Time Format", @"Label for selecting the date and time settings section")
editable:YES
reuseIdentifier:nil];
return _dateAndTimeFormatCell;
}
- (SettingTableViewCell *)postsPerPageCell
{
if (_postsPerPageCell) {
return _postsPerPageCell;
}
_postsPerPageCell = [[SettingTableViewCell alloc] initWithLabel:NSLocalizedString(@"Posts per page", @"Label for selecting the number of posts per page")
editable:YES
reuseIdentifier:nil];
return _postsPerPageCell;
}
- (SettingTableViewCell *)speedUpYourSiteCell
{
if (_speedUpYourSiteCell) {
return _speedUpYourSiteCell;
}
_speedUpYourSiteCell = [[SettingTableViewCell alloc] initWithLabel:NSLocalizedString(@"Speed up your site", @"Label for selecting the Speed up your site Settings section")
editable:YES
reuseIdentifier:nil];
return _speedUpYourSiteCell;
}
- (MediaQuotaCell *)mediaQuotaCell
{
if (_mediaQuotaCell){
return _mediaQuotaCell;
}
_mediaQuotaCell = (MediaQuotaCell *)[self.tableView dequeueReusableCellWithIdentifier:MediaQuotaCell.defaultReuseIdentifier];
_mediaQuotaCell.title = NSLocalizedString(@"Space used", @"Label for showing the available disk space quota available for media");
_mediaQuotaCell.selectionStyle = UITableViewCellSelectionStyleNone;
return _mediaQuotaCell;
}
- (SettingTableViewCell *)discussionSettingsCell
{
if (_discussionSettingsCell) {
return _discussionSettingsCell;
}
_discussionSettingsCell = [[SettingTableViewCell alloc] initWithLabel:NSLocalizedString(@"Discussion", @"Label for selecting the Blog Discussion Settings section")
editable:YES
reuseIdentifier:nil];
return _discussionSettingsCell;
}
- (SwitchTableViewCell *)ampSettingCell
{
if (_ampSettingCell) {
return _ampSettingCell;
}
_ampSettingCell = [SwitchTableViewCell new];
_ampSettingCell.name = NSLocalizedString(@"Accelerated Mobile Pages (AMP)", @"Label for selecting the Accelerated Mobile Pages (AMP) Blog Traffic Setting");
_ampSettingCell.on = self.blog.settings.ampEnabled;
__weak __typeof__(self) weakSelf = self;
_ampSettingCell.onChange = ^(BOOL value){
weakSelf.blog.settings.ampEnabled = value;
[weakSelf saveSettings];
[WPAnalytics trackSettingsChange:@"site_settings" fieldName:@"amp_enabled" value:@(value)];
};
return _ampSettingCell;
}
- (SettingTableViewCell *)jetpackSecurityCell
{
if (_jetpackSecurityCell) {
return _jetpackSecurityCell;
}
_jetpackSecurityCell = [[SettingTableViewCell alloc] initWithLabel:NSLocalizedString(@"Security", @"Label for selecting the Blog Jetpack Security Settings section")
editable:YES
reuseIdentifier:nil];
return _jetpackSecurityCell;
}
- (SettingTableViewCell *)jetpackConnectionCell
{
if (_jetpackConnectionCell) {
return _jetpackConnectionCell;
}
_jetpackConnectionCell = [[SettingTableViewCell alloc] initWithLabel:NSLocalizedString(@"Manage Connection", @"Label for managing the Blog Jetpack Connection section")
editable:YES
reuseIdentifier:nil];
return _jetpackConnectionCell;
}
- (void)configureEditorSelectorCell
{
[self.editorSelectorCell setOn:self.blog.isGutenbergEnabled];
}
- (void)configureDefaultCategoryCell
{
PostCategory *postCategory = [PostCategory lookupWithBlogObjectID:self.blog.objectID
categoryID:self.blog.settings.defaultCategoryID
inContext:[[ContextManager sharedInstance] mainContext]];
[self.defaultCategoryCell setTextValue:[postCategory categoryName]];
}
- (void)configureDefaultPostFormatCell
{
[self.defaultPostFormatCell setTextValue:self.blog.defaultPostFormatText];
}
- (void)configurePostsPerPageCell
{
[self.postsPerPageCell setTextValue:self.blog.settings.postsPerPage.stringValue];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForEditorSettingsAtRow:(NSInteger)row
{
switch (row) {
case (SiteSettingsEditorSelector):
[self configureEditorSelectorCell];
return self.editorSelectorCell;
}
return nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForWritingSettingsAtRow:(NSInteger)row
{
NSInteger writingRow = [self.writingSectionRows[row] integerValue];
switch (writingRow) {
case (SiteSettingsWritingDefaultCategory):
[self configureDefaultCategoryCell];
return self.defaultCategoryCell;
case (SiteSettingsWritingTags):
return self.tagsCell;
case (SiteSettingsWritingDefaultPostFormat):
[self configureDefaultPostFormatCell];
return self.defaultPostFormatCell;
case (SiteSettingsWritingRelatedPosts):
return self.relatedPostsCell;
case (SiteSettingsWritingDateAndTimeFormat):
return self.dateAndTimeFormatCell;
case (SiteSettingsPostPerPage):
[self configurePostsPerPageCell];
return self.postsPerPageCell;
case (SiteSettingsSpeedUpYourSite):
return self.speedUpYourSiteCell;
}
return nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForMediaSettingsAtRow:(NSInteger)row
{
if (self.blog.isQuotaAvailable) {
NSString *formatString = NSLocalizedString(@"%@ of %@ on your site", @"Amount of disk quota being used. First argument is the total percentage being used second argument is total quota allowed in GB.Ex: 33% of 14 GB on your site.");
self.mediaQuotaCell.value = [[NSString alloc] initWithFormat:formatString, self.blog.quotaPercentageUsedDescription, self.blog.quotaSpaceAllowedDescription];
self.mediaQuotaCell.percentage = self.blog.quotaPercentageUsed;
}
return self.mediaQuotaCell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForJetpackSettingsAtRow:(NSInteger)row
{
switch (row) {
case (SiteSettingsJetpackSecurity):
return self.jetpackSecurityCell;
case (SiteSettingsJetpackConnection):
return self.jetpackConnectionCell;
}
return nil;
}
- (SettingTableViewCell *)startOverCell
{
if (_startOverCell) {
return _startOverCell;
}
_startOverCell = [[SettingTableViewCell alloc] initWithLabel:NSLocalizedString(@"Start Over", @"Label for selecting the Start Over Settings item")
editable:YES
reuseIdentifier:nil];
return _startOverCell;
}
- (WPTableViewCell *)exportContentCell
{
if (_exportContentCell) {
return _exportContentCell;
}
_exportContentCell = [[WPTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
[WPStyleGuide configureTableViewActionCell:_exportContentCell];
_exportContentCell.textLabel.text = NSLocalizedString(@"Export Content", @"Label for selecting the Export Content Settings item");
return _exportContentCell;
}
- (WPTableViewCell *)deleteSiteCell
{
if (_deleteSiteCell) {
return _deleteSiteCell;
}
_deleteSiteCell = [[WPTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
[WPStyleGuide configureTableViewActionCell:_deleteSiteCell];
_deleteSiteCell.textLabel.text = NSLocalizedString(@"Delete Site", @"Label for selecting the Delete Site Settings item");
return _deleteSiteCell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForAdvancedSettingsAtRow:(NSInteger)row
{
switch (row) {
case SiteSettingsAdvancedStartOver:
return self.startOverCell;
case SiteSettingsAdvancedExportContent:
return self.exportContentCell;
case SiteSettingsAdvancedDeleteSite:
return self.deleteSiteCell;
}
NSAssert(false, @"Missing Advanced section cell");
return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"NoCell"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger settingsSection = [self.tableSections[indexPath.section] integerValue];
switch (settingsSection) {
case SiteSettingsSectionGeneral:
return [self tableView:tableView cellForGeneralSettingsInRow:indexPath.row];
case SiteSettingsSectionBlogging:
return [self tableView:tableView cellForBloggingSettingsInRow:indexPath.row];
case SiteSettingsSectionHomepage:
return self.homepageSettingsCell;
case SiteSettingsSectionAccount:
return [self tableView:tableView cellForAccountSettingsInRow:indexPath.row];
case SiteSettingsSectionEditor:
return [self tableView:tableView cellForEditorSettingsAtRow:indexPath.row];
case SiteSettingsSectionWriting:
return [self tableView:tableView cellForWritingSettingsAtRow:indexPath.row];
case SiteSettingsSectionMedia:
return [self tableView:tableView cellForMediaSettingsAtRow:indexPath.row];
case SiteSettingsSectionDiscussion:
return self.discussionSettingsCell;
case SiteSettingsSectionTraffic:
return self.ampSettingCell;
case SiteSettingsSectionJetpackSettings:
return [self tableView:tableView cellForJetpackSettingsAtRow:indexPath.row];
case SiteSettingsSectionAdvanced:
return [self tableView:tableView cellForAdvancedSettingsAtRow:indexPath.row];
}
NSAssert(false, @"Missing section handler");
return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger settingsSection = [self.tableSections[indexPath.section] integerValue];
switch (settingsSection) {
case SiteSettingsSectionMedia:
return MediaQuotaCell.height;
default:
return UITableViewAutomaticDimension;
}
}
#pragma mark - UITableViewDelegate
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSInteger settingsSection = [self.tableSections[section] integerValue];
return [self titleForHeaderInSection:settingsSection];
}
- (NSString *)titleForHeaderInSection:(NSInteger)section
{
NSString *headingTitle = nil;
switch (section) {
case SiteSettingsSectionGeneral:
headingTitle = NSLocalizedString(@"General", @"Title for the general section in site settings screen");
break;
case SiteSettingsSectionBlogging:
headingTitle = NSLocalizedString(@"Blogging", @"Title for the blogging section in site settings screen");
break;
case SiteSettingsSectionHomepage:
headingTitle = NSLocalizedString(@"Homepage", @"Title for the homepage section in site settings screen");
break;
case SiteSettingsSectionAccount:
headingTitle = NSLocalizedString(@"Account", @"Title for the account section in site settings screen");
break;
case SiteSettingsSectionEditor:
headingTitle = NSLocalizedString(@"Editor", @"Title for the editor settings section");
break;
case SiteSettingsSectionWriting:
headingTitle = NSLocalizedString(@"Writing", @"Title for the writing section in site settings screen");
break;
case SiteSettingsSectionTraffic:
headingTitle = NSLocalizedString(@"Traffic", @"Title for the traffic section in site settings screen");
break;
case SiteSettingsSectionJetpackSettings:
headingTitle = NSLocalizedString(@"Jetpack", @"Title for the Jetpack section in site settings screen");
break;
case SiteSettingsSectionAdvanced:
headingTitle = NSLocalizedString(@"Advanced", @"Title for the advanced section in site settings screen");
break;
case SiteSettingsSectionMedia:
headingTitle = NSLocalizedString(@"Media", @"Title for the media section in site settings screen");
break;
}
return headingTitle;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
NSInteger settingsSection = [self.tableSections[section] integerValue];
UIView *footerView = nil;
switch (settingsSection) {
case SiteSettingsSectionEditor:
footerView = [self getEditorSettingsSectionFooterView];
break;
case SiteSettingsSectionTraffic:
footerView = [self getTrafficSettingsSectionFooterView];
break;
}
return footerView;
}
- (void)showPrivacySelector
{
NSArray *values = [BlogSiteVisibilityHelper siteVisibilityValuesForBlog:self.blog];
NSArray *titles = [BlogSiteVisibilityHelper titlesForSiteVisibilityValues:values];
NSArray *hints = [BlogSiteVisibilityHelper hintsForSiteVisibilityValues:values];
NSNumber *currentPrivacy = @(self.blog.siteVisibility);
if (!currentPrivacy) {
currentPrivacy = [values firstObject];
}
NSDictionary *settingsSelectionConfiguration = @{
SettingsSelectionDefaultValueKey : [values firstObject],
SettingsSelectionTitleKey : NSLocalizedString(@"Privacy", @"Title for screen to select the privacy options for a blog"),
SettingsSelectionTitlesKey : titles,
SettingsSelectionValuesKey : values,
SettingsSelectionCurrentValueKey : currentPrivacy,
SettingsSelectionHintsKey : hints
};
SettingsSelectionViewController *vc = [[SettingsSelectionViewController alloc] initWithDictionary:settingsSelectionConfiguration];
__weak __typeof__(self) weakSelf = self;
vc.onItemSelected = ^(NSNumber *status) {
// Check if the object passed is indeed an NSString, otherwise we don't want to try to set it as the post format
if ([status isKindOfClass:[NSNumber class]]) {
SiteVisibility newSiteVisibility = (SiteVisibility)[status integerValue];
if (weakSelf.blog.siteVisibility != newSiteVisibility) {
weakSelf.blog.siteVisibility = newSiteVisibility;
[weakSelf saveSettings];
[WPAnalytics trackSettingsChange:@"site_settings" fieldName:@"privacy" value:status];
}
}
};
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showLanguageSelectorForBlog:(Blog *)blog
{
NSParameterAssert(blog);
__weak __typeof__(self) weakSelf = self;
LanguageViewController *languageViewController = [[LanguageViewController alloc] initWithBlog:blog];
languageViewController.onChange = ^(NSNumber *newLanguageID){
weakSelf.blog.settings.languageID = newLanguageID;
[weakSelf saveSettings];
[WPAnalytics trackSettingsChange:@"site_settings" fieldName:@"language" value:newLanguageID];
};
[self.navigationController pushViewController:languageViewController animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectInAccountSectionRow:(NSInteger)row
{
if (row != SiteSettingsAccountPassword) {
return;
}
SettingsTextViewController *siteTitleViewController = [[SettingsTextViewController alloc] initWithText:self.blog.password
placeholder:NSLocalizedString(@"Enter password", @"(placeholder) Help enter WordPress password")
hint:@""];
siteTitleViewController.title = NSLocalizedString(@"Password", @"Title for screen that shows self hosted password editor.");
siteTitleViewController.mode = SettingsTextModesPassword;
siteTitleViewController.onValueChanged = ^(id value) {
if (![value isEqualToString:self.blog.password]) {
self.password = value;
[self validateLoginCredentials];
}
};
[self.navigationController pushViewController:siteTitleViewController animated:YES];
}
- (void)showDefaultCategorySelector
{
NSNumber *defaultCategoryID = self.blog.settings.defaultCategoryID ?: @(PostCategoryUncategorized);
PostCategory *postCategory = [PostCategory lookupWithBlogObjectID:self.blog.objectID
categoryID:defaultCategoryID
inContext:[[ContextManager sharedInstance] mainContext]];
NSArray *currentSelection = @[];
if (postCategory){
currentSelection = @[postCategory];
}
PostCategoriesViewController *postCategoriesViewController = [[PostCategoriesViewController alloc] initWithBlog:self.blog
currentSelection:currentSelection
selectionMode:CategoriesSelectionModeBlogDefault];
postCategoriesViewController.delegate = self;
[self.navigationController pushViewController:postCategoriesViewController animated:YES];
}
- (void)showTagList
{
SiteTagsViewController *tagsAdmin = [[SiteTagsViewController alloc] initWithBlog:self.blog];
[self.navigationController pushViewController:tagsAdmin animated:YES];
}
- (void)showPostFormatSelector
{
NSArray *titles = self.blog.sortedPostFormatNames;
NSArray *formats = self.blog.sortedPostFormats;
if (titles.count == 0 || self.blog.defaultPostFormatText == nil) {
return;
}
NSString *currentDefaultPostFormat = self.blog.settings.defaultPostFormat;
if (!currentDefaultPostFormat) {
currentDefaultPostFormat = formats[0];
}
NSDictionary *postFormatsDict = @{
SettingsSelectionDefaultValueKey : [formats firstObject],
SettingsSelectionTitleKey : NSLocalizedString(@"Default Post Format", @"Title for screen to select a default post format for a blog"),
SettingsSelectionTitlesKey : titles,
SettingsSelectionValuesKey : formats,
SettingsSelectionCurrentValueKey : currentDefaultPostFormat
};
SettingsSelectionViewController *vc = [[SettingsSelectionViewController alloc] initWithDictionary:postFormatsDict];
__weak __typeof__(self) weakSelf = self;
vc.onItemSelected = ^(NSString *status) {
// Check if the object passed is indeed an NSString, otherwise we don't want to try to set it as the post format
if ([status isKindOfClass:[NSString class]]) {
if (weakSelf.blog.settings.defaultPostFormat != status) {
weakSelf.blog.settings.defaultPostFormat = status;
if ([weakSelf savingWritingDefaultsIsAvailable]) {
[WPAnalytics trackSettingsChange:@"site_settings" fieldName:@"default_post_format"];
[weakSelf saveSettings];
}
}
}
};
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showRelatedPostsSettings
{
RelatedPostsSettingsViewController *relatedPostsViewController = [[RelatedPostsSettingsViewController alloc] initWithBlog:self.blog];
[self.navigationController pushViewController:relatedPostsViewController animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectInWritingSectionRow:(NSInteger)row
{
NSInteger writingRow = [self.writingSectionRows[row] integerValue];
switch (writingRow) {
case SiteSettingsWritingDefaultCategory:
[self showDefaultCategorySelector];
break;
case SiteSettingsWritingTags:
[self showTagList];
break;
case SiteSettingsWritingDefaultPostFormat:
[self showPostFormatSelector];
break;
case SiteSettingsWritingRelatedPosts:
[self showRelatedPostsSettings];
break;
case SiteSettingsWritingDateAndTimeFormat:
[self showDateAndTimeFormatSettings];
break;
case SiteSettingsPostPerPage:
[self showPostPerPageSetting];
break;
case SiteSettingsSpeedUpYourSite:
[self showSpeedUpYourSiteSettings];
break;
}
}
- (void)tableView:(UITableView *)tableView didSelectInJetpackSectionRow:(NSInteger)row
{
switch (row) {
case SiteSettingsJetpackSecurity:
[self showJetpackSettingsForBlog:self.blog];
break;
case SiteSettingsJetpackConnection:
[self showJetpackConnectionForBlog:self.blog];
break;
}
}
- (void)showStartOverForBlog:(Blog *)blog
{
NSParameterAssert([blog supportsSiteManagementServices]);
[WPAppAnalytics track:WPAnalyticsStatSiteSettingsStartOverAccessed withBlog:self.blog];
if ([SupportConfigurationObjC isStartOverSupportEnabled] && self.blog.hasPaidPlan) {
StartOverViewController *viewController = [[StartOverViewController alloc] initWithBlog:blog];
[self.navigationController pushViewController:viewController animated:YES];
} else {
NSURL *targetURL = [NSURL URLWithString:EmptySiteSupportURL];
UIViewController *webViewController = [WebViewControllerFactory controllerWithUrl:targetURL source:@"site_settings_start_over"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:webViewController];
[self presentViewController:navController animated:YES completion:nil];
}
}
- (void)tableView:(UITableView *)tableView didSelectInAdvancedSectionRow:(NSInteger)row
{
switch (row) {
case SiteSettingsAdvancedStartOver:
[self showStartOverForBlog:self.blog];
break;
case SiteSettingsAdvancedExportContent:
[self confirmExportContent];
break;
case SiteSettingsAdvancedDeleteSite:
[self checkSiteDeletable];
break;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger settingsSection = [self.tableSections[indexPath.section] intValue];
switch (settingsSection) {
case SiteSettingsSectionGeneral:
[self tableView:tableView didSelectInGeneralSettingsAt:indexPath];
break;
case SiteSettingsSectionBlogging:
[self tableView:tableView didSelectInBloggingSettingsAt:indexPath];
break;
case SiteSettingsSectionHomepage: