Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
249 changes: 2 additions & 247 deletions Sources/WordPressData/Objective-C/Blog.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@

@class Comment;

static NSInteger const JetpackProfessionalYearlyPlanId = 2004;
static NSInteger const JetpackProfessionalMonthlyPlanId = 2001;

NSString * const BlogEntityName = @"Blog";
NSString * const PostFormatStandard = @"standard";
NSString * const ActiveModulesKeyStats = @"stats";
NSString * const ActiveModulesKeyPublicize = @"publicize";
NSString * const ActiveModulesKeySharingButtons = @"sharedaddy";
NSString * const OptionsKeyActiveModules = @"active_modules";
NSString * const OptionsKeyPublicizeDisabled = @"publicize_permanently_disabled";

@interface Blog ()

Expand Down Expand Up @@ -181,227 +174,11 @@ - (void)setPassword:(NSString *)password
}
}

- (BOOL)supports:(BlogFeature)feature
{
switch (feature) {
case BlogFeatureRemovable:
return ![self accountIsDefaultAccount];
case BlogFeatureVisibility:
/*
See -[BlogListViewController fetchRequestPredicateForHideableBlogs]
If the logic for this changes that needs to be updated as well
*/
return [self accountIsDefaultAccount];
case BlogFeaturePeople:
return [self supportsRestApi] && self.isListingUsersAllowed;
case BlogFeatureWPComRESTAPI:
case BlogFeatureCommentLikes:
return [self supportsRestApi];
case BlogFeatureStats:
return [self supportsRestApi] && [self isViewingStatsAllowed];
case BlogFeatureStockPhotos:
return [self supportsRestApi];
case BlogFeatureSharing:
return [self supportsSharing];
case BlogFeatureOAuth2Login:
return [self isHostedAtWPcom];
case BlogFeatureMentions:
return [self isAccessibleThroughWPCom];
case BlogFeatureXposts:
return [self isAccessibleThroughWPCom];
case BlogFeatureReblog:
case BlogFeaturePlans:
return [self isHostedAtWPcom] && [self isAdmin];
case BlogFeaturePluginManagement:
return [self supportsPluginManagement] && [self isAdmin];
case BlogFeatureJetpackImageSettings:
return [self supportsJetpackImageSettings];
case BlogFeatureJetpackSettings:
return [self supportsRestApi] && ![self isHostedAtWPcom] && [self isAdmin];
case BlogFeaturePushNotifications:
return [self supportsPushNotifications];
case BlogFeatureThemeBrowsing:
return [self supportsRestApi] && [self isAdmin];
case BlogFeatureActivity: {
// For now Activity is suported for admin users
return [self supportsRestApi] && [self isAdmin];
}
case BlogFeatureCustomThemes:
return [self supportsRestApi] && [self isAdmin] && ![self isHostedAtWPcom];
case BlogFeaturePremiumThemes:
return [self supports:BlogFeatureCustomThemes] && (self.planID.integerValue == JetpackProfessionalYearlyPlanId
|| self.planID.integerValue == JetpackProfessionalMonthlyPlanId);
case BlogFeatureMenus:
return [self supportsRestApi] && [self isAdmin];
case BlogFeaturePrivate:
// Private visibility is only supported by wpcom blogs
return [self isHostedAtWPcom];
case BlogFeatureSiteManagement:
return [self supportsSiteManagementServices];
case BlogFeatureDomains:
return ([self isHostedAtWPcom] || [self isAtomic]) && [self isAdmin] && ![self isWPForTeams];
case BlogFeatureNoncePreviews:
return [self supportsRestApi] && ![self isHostedAtWPcom];
case BlogFeatureMediaMetadataEditing:
return [self isAdmin];
case BlogFeatureMediaAltEditing:
// alt is not supported via XML-RPC API
// https://core.trac.wordpress.org/ticket/58582
// https://github.com/wordpress-mobile/WordPress-Android/issues/18514#issuecomment-1589752274
return [self supportsRestApi] || [self supportsCoreRestApi];
case BlogFeatureMediaDeletion:
return [self isAdmin];
case BlogFeatureHomepageSettings:
return [self supportsRestApi] && [self isAdmin];
case BlogFeatureContactInfo:
return [self supportsContactInfo];
case BlogFeatureBlockEditorSettings:
return [self supportsBlockEditorSettings];
case BlogFeatureLayoutGrid:
return [self supportsLayoutGrid];
case BlogFeatureTiledGallery:
return [self supportsTiledGallery];
case BlogFeatureVideoPress:
return [self supportsVideoPress];
case BlogFeatureVideoPressV5:
return [self supportsVideoPressV5];
case BlogFeatureFacebookEmbed:
return [self supportsEmbedVariation: @"9.0"];
case BlogFeatureInstagramEmbed:
return [self supportsEmbedVariation: @"9.0"];
case BlogFeatureLoomEmbed:
return [self supportsEmbedVariation: @"9.0"];
case BlogFeatureSmartframeEmbed:
return [self supportsEmbedVariation: @"10.2"];
case BlogFeatureFileDownloadsStats:
return [self isHostedAtWPcom];
case BlogFeatureBlaze:
return [self canBlaze];
case BlogFeaturePages:
return [self isListingPagesAllowed];
case BlogFeatureSiteMonitoring:
return [self isAdmin] && [self isAtomic];
case BlogFeaturePublicize:
return [self supportsPublicize];
case BlogFeatureShareButtons:
return [self supportsShareButtons];
}
}

-(BOOL)supportsSharing
{
return [self supports:BlogFeaturePublicize] || [self supports:BlogFeatureShareButtons];
}

- (BOOL)supportsPublicize
{
// Publicize is only supported via REST
if (![self supports:BlogFeatureWPComRESTAPI]) {
return NO;
}

if (![self isPublishingPostsAllowed]) {
return NO;
}

if (self.isHostedAtWPcom) {
// For WordPress.com YES unless it's disabled
return ![[self getOptionValue:OptionsKeyPublicizeDisabled] boolValue];

} else {
// For Jetpack, check if the module is enabled
return [self jetpackPublicizeModuleEnabled];
}
}

- (BOOL)supportsShareButtons
{
// Share Button settings are only supported via REST, and for admins
if (![self isAdmin] || ![self supports:BlogFeatureWPComRESTAPI]) {
return NO;
}

if (self.isHostedAtWPcom) {
// For WordPress.com YES
return YES;

} else {
// For Jetpack, check if the module is enabled
return [self jetpackSharingButtonsModuleEnabled];
}
}

- (BOOL)isStatsActive
{
return [self jetpackStatsModuleEnabled] || [self isHostedAtWPcom];
}

- (BOOL)supportsPushNotifications
{
return [self accountIsDefaultAccount];
}

- (BOOL)supportsJetpackImageSettings
{
return [self hasRequiredJetpackVersion:@"5.6"];
}

- (BOOL)supportsPluginManagement
{
BOOL hasRequiredJetpack = [self hasRequiredJetpackVersion:@"5.6"];

BOOL isTransferrable = self.isHostedAtWPcom
&& self.hasBusinessPlan
&& self.siteVisibility != SiteVisibilityPrivate;

BOOL supports = isTransferrable || hasRequiredJetpack;

// If the site is not hosted on WP.com we can still manage plugins directly using the WP.org rest API
// Reference: https://make.wordpress.org/core/2020/07/16/new-and-modified-rest-api-endpoints-in-wordpress-5-5/
if(!supports && !self.account){
supports = !self.isHostedAtWPcom
&& self.selfHostedSiteRestApi
&& [self hasRequiredWordPressVersion:@"5.5"];
}

return supports;
}

- (BOOL)supportsContactInfo
{
return [self hasRequiredJetpackVersion:@"8.5"] || self.isHostedAtWPcom;
}

- (BOOL)supportsLayoutGrid
{
return self.isHostedAtWPcom || self.isAtomic;
}

- (BOOL)supportsTiledGallery
{
return self.isHostedAtWPcom;
}

- (BOOL)supportsVideoPress
{
return self.isHostedAtWPcom;
}

- (BOOL)supportsVideoPressV5
{
return self.isHostedAtWPcom || self.isAtomic || [self hasRequiredJetpackVersion:@"8.5"];
}

- (BOOL)supportsEmbedVariation:(NSString *)requiredJetpackVersion
{
return [self hasRequiredJetpackVersion:requiredJetpackVersion] || self.isHostedAtWPcom;
}

- (BOOL)accountIsDefaultAccount
{
return [[self account] isDefaultWordPressComAccount];
}

- (NSNumber *)dotComID
{
[self willAccessValueForKey:@"blogID"];
Expand Down Expand Up @@ -469,25 +246,10 @@ - (BOOL)supportsRestApi {

#pragma mark - Jetpack

- (BOOL)jetpackActiveModule:(NSString *)moduleName
{
NSArray *activeModules = (NSArray *)[self getOptionValue:OptionsKeyActiveModules];
return [activeModules containsObject:moduleName] ?: NO;
}

- (BOOL)jetpackStatsModuleEnabled
{
return [self jetpackActiveModule:ActiveModulesKeyStats];
}

- (BOOL)jetpackPublicizeModuleEnabled
{
return [self jetpackActiveModule:ActiveModulesKeyPublicize];
}

- (BOOL)jetpackSharingButtonsModuleEnabled
{
return [self jetpackActiveModule:ActiveModulesKeySharingButtons];
NSArray *activeModules = (NSArray *)[self getOptionValue:@"active_modules"];
return [activeModules containsObject:ActiveModulesKeyStats] ?: NO;
}

- (BOOL)isBasicAuthCredentialStored
Expand All @@ -505,13 +267,6 @@ - (BOOL)isBasicAuthCredentialStored
return NO;
}

- (BOOL)hasRequiredJetpackVersion:(NSString *)requiredJetpackVersion
{
return [self supportsRestApi]
&& ![self isHostedAtWPcom]
&& [self.jetpack.version compare:requiredJetpackVersion options:NSNumericSearch] != NSOrderedAscending;
}

/// Checks the blogs installed WordPress version is more than or equal to the requiredVersion
/// @param requiredVersion The minimum version to check for
- (BOOL)hasRequiredWordPressVersion:(NSString *)requiredVersion
Expand Down
98 changes: 0 additions & 98 deletions Sources/WordPressData/Objective-C/include/Blog.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,103 +24,6 @@ NS_ASSUME_NONNULL_BEGIN
extern NSString * const BlogEntityName;
extern NSString * const PostFormatStandard;

/// - warning: These flags are app-agnostic and define whether the _blog_ supports
/// the given feature. If the app needs to determine whether to show a feature or
/// not, it has to implement additional logic on top of it.
typedef NS_ENUM(NSUInteger, BlogFeature) {
/// Can the blog be removed?
BlogFeatureRemovable,
/// Can the blog be hidden?
BlogFeatureVisibility,
/// Can the blog use the WordPress.com REST API?
BlogFeatureWPComRESTAPI,
/// Can we use an OAuth2 token with wp-login.php?
BlogFeatureOAuth2Login,
/// Does the blog support reblogs?
BlogFeatureReblog,
/// Does the blog support comment likes?
BlogFeatureCommentLikes,
/// Can we show stats for the blog?
BlogFeatureStats,
/// Can we show activity for the blog?
BlogFeatureActivity,
/// Does the blog support mentions?
BlogFeatureMentions,
/// Does the blog support xposts?
BlogFeatureXposts,
/// Does the blog support push notifications?
BlogFeaturePushNotifications,
/// Does the blog support theme browsing?
BlogFeatureThemeBrowsing,
/// Does the blog support custom themes?
BlogFeatureCustomThemes,
/// Does the blog support premium themes?
BlogFeaturePremiumThemes,
/// Does the blog support Menus management?
BlogFeatureMenus,
/// Does the blog support private visibility?
BlogFeaturePrivate,
/// Does the blog support sharing?
BlogFeatureSharing,
/// Does the blog support people management?
BlogFeaturePeople,
/// Can the blog's site be changed or deleted?
BlogFeatureSiteManagement,
/// Does the blog support different paid plans?
BlogFeaturePlans,
/// Does the blog support plugins?
BlogFeaturePluginManagement,
/// Does the blog support Jetpack image settings?
BlogFeatureJetpackImageSettings,
/// Does the blog support Jetpack settings
BlogFeatureJetpackSettings,
/// Does the blog support custom domains?
BlogFeatureDomains,
/// Does the blog support frame-nonce to authenticate previews?
BlogFeatureNoncePreviews,
/// Does the blog support editing media metadata?
BlogFeatureMediaMetadataEditing,
/// Does the blog support editing media alternative text?
BlogFeatureMediaAltEditing,
/// Does the blog support deleting media?
BlogFeatureMediaDeletion,
/// Does the blog support Stock Photos feature (free photos library)
BlogFeatureStockPhotos,
/// Does the blog support setting the homepage type and pages?
BlogFeatureHomepageSettings,
/// Does the blog support Jetpack contact info block?
BlogFeatureContactInfo,
BlogFeatureBlockEditorSettings,
/// Does the blog support the Layout grid block?
BlogFeatureLayoutGrid,
/// Does the blog support the tiled gallery block?
BlogFeatureTiledGallery,
/// Does the blog support the VideoPress block?
BlogFeatureVideoPress,
/// Does the blog support v5 of the VideoPress block?
BlogFeatureVideoPressV5,
/// Does the blog support Facebook embed block?
BlogFeatureFacebookEmbed,
/// Does the blog support Instagram embed block?
BlogFeatureInstagramEmbed,
/// Does the blog support Loom embed block?
BlogFeatureLoomEmbed,
/// Does the blog support Smartframe embed block?
BlogFeatureSmartframeEmbed,
/// Does the blog support File Downloads section in stats?
BlogFeatureFileDownloadsStats,
/// Does the blog support Blaze?
BlogFeatureBlaze,
/// Does the blog support listing and editing Pages?
BlogFeaturePages,
/// Does the blog support Site Monitoring?
BlogFeatureSiteMonitoring,
/// Does the blog support Publicize?
BlogFeaturePublicize,
/// Does the blog support share buttons?
BlogFeatureShareButtons,
};

typedef NS_ENUM(NSInteger, SiteVisibility) {
SiteVisibilityPrivate = -1,
SiteVisibilityHidden = 0,
Expand Down Expand Up @@ -215,7 +118,6 @@ typedef NS_ENUM(NSInteger, SiteVisibility) {

- (nullable id)getOptionValue:(NSString *) name;
- (void)setValue:(id)value forOption:(NSString *)name;
- (BOOL)supports:(BlogFeature)feature;
- (BOOL)isStatsActive;

/**
Expand Down
Loading