Skip to content
Closed
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
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
WordPress for iOS

Resources
---------------------------------------------------------------
Developer blog:
## Resources

### Developer blog

http://dev.ios.wordpress.org/

Source code:
http://ios.trac.wordpress.org/
http://ios.svn.wordpress.org/
### Style guide

https://github.com/wordpress-mobile/WordPress-iOS/wiki/WordPress-for-iOS-Style-Guide

### To report an issue

http://ios.trac.wordpress.org/newticket

You'll need a WordPress.org account. If you don't have one you can
register here:

http://wordpress.org/support/register.php

### Source Code

SVN: http://ios.svn.wordpress.org/

SVN browser: http://ios.trac.wordpress.org/browser

Github mirror: https://github.com/wordpress-mobile/WordPress-iOS/

## Building

Building
---------------------------------------------------------------
Starting with changeset 3633 version 3.2, WordPress for iOS uses Cocoapods (http://cocoapods.org/) to manage third party libraries. Trying to build the project by itself (WordPress.xcproj) after launching will result in an error, as the resources managed by cocoapods are not included. Instead, launch the workspace by either double clicking on WordPress.xcworkspace file, or launch Xcode and choose File > Open and browse to WordPress.xcworkspace.


10 changes: 1 addition & 9 deletions WordPress/Classes/AboutViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,5 @@
#import <UIKit/UIKit.h>
#import "WordPressAppDelegate.h"

@interface AboutViewController : UIViewController <MFMailComposeViewControllerDelegate>

@property (nonatomic, strong) IBOutlet UIView *logoView;
@property (nonatomic, strong) IBOutlet UIView *buttonsView;

- (IBAction)viewTermsOfService:(id)sender;
- (IBAction)viewPrivacyPolicy:(id)sender;
- (IBAction)viewWebsite:(id)sender;

@interface AboutViewController : UIViewController
@end
28 changes: 15 additions & 13 deletions WordPress/Classes/AboutViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@
#import "ReachabilityUtils.h"
#import "WPWebViewController.h"

@interface AboutViewController (Private)
- (void)dismiss;
- (void)openURLWithString:(NSString *)path;
@interface AboutViewController()

@property (nonatomic, strong) IBOutlet UIView *logoView;
@property (nonatomic, strong) IBOutlet UIView *buttonsView;

@end

@implementation AboutViewController

@synthesize buttonsView;
@synthesize logoView;

CGFloat const AboutViewLandscapeButtonsY = -20.0f;
CGFloat const AboutViewPortraitButtonsY = 90.0f;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[FileLogger log:@"%@ %@", self, NSStringFromSelector(_cmd)];
Expand All @@ -28,7 +33,7 @@ - (void)viewDidLoad {
self.navigationItem.title = NSLocalizedString(@"About", @"About this app (information page title)");
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"welcome_bg_pattern.png"]];

if( [self.navigationController.viewControllers count] == 1 )
if([self.navigationController.viewControllers count] == 1)
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", @"") style:UIBarButtonItemStyleBordered target:self action:@selector(dismiss)];
}

Expand All @@ -37,20 +42,17 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}


- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if( IS_IPHONE ) {
if ( YES == UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ) {
if (IS_IPHONE) {
CGRect frame = buttonsView.frame;
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
self.logoView.hidden = YES;
CGRect frame = buttonsView.frame;
frame.origin.y = -20.0f;
self.buttonsView.frame = frame;
frame.origin.y = AboutViewLandscapeButtonsY;
} else {
self.logoView.hidden = NO;
CGRect frame = buttonsView.frame;
frame.origin.y = 90.0f;
self.buttonsView.frame = frame;
frame.origin.y = AboutViewPortraitButtonsY;
}
self.buttonsView.frame = frame;
}
}

Expand Down
4 changes: 1 addition & 3 deletions WordPress/Classes/AddSiteViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
#import <UIKit/UIKit.h>
#import "EditSiteViewController.h"

@interface AddSiteViewController : EditSiteViewController {
}

@interface AddSiteViewController : EditSiteViewController
@end
130 changes: 78 additions & 52 deletions WordPress/Classes/AddSiteViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ - (void)validationDidFail:(id)wrong;

@implementation AddSiteViewController

CGSize const AddSiteLogoSize = { 320.0, 70.0 };

- (void)viewDidLoad {
[super viewDidLoad];

UIImageView *logoImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo_wporg"]];
logoImage.frame = CGRectMake(0.0f, 0.0f, 320.0f, 70.0f);
logoImage.frame = CGRectMake(0.0f, 0.0f, AddSiteLogoSize.width, AddSiteLogoSize.height);
logoImage.autoresizingMask = UIViewAutoresizingFlexibleWidth;
logoImage.contentMode = UIViewContentModeCenter;
tableView.tableHeaderView = logoImage;
Expand All @@ -35,64 +37,26 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInte
return nil;
}

- (void)validationSuccess:(NSString *)xmlrpc {
WordPressAppDelegate *appDelegate = [WordPressAppDelegate sharedWordPressApplicationDelegate];
NSLog(@"hasSubsites: %@", subsites);
- (void)validationSuccess:(NSString *)xmlRpc {
WPFLog(@"hasSubsites: %@", subsites);

if ([subsites count] > 0) {
// If the user has entered the URL of a site they own on a MultiSite install,
// assume they want to add that specific site.
NSDictionary *subsite = nil;
if ([subsites count] > 1)
subsite = [[subsites filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"xmlrpc = %@", xmlrpc]] lastObject];
if ([subsites count] > 1) {
subsite = [[subsites filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"xmlrpc = %@", xmlRpc]] lastObject];
}

if (subsite == nil) {
subsite = [subsites objectAtIndex:0];
}

if ([subsites count] > 1 && [[subsite objectForKey:@"blogid"] isEqualToString:@"1"]) {
AddUsersBlogsViewController *addUsersBlogsView = [[AddUsersBlogsViewController alloc] initWithNibName:@"AddUsersBlogsViewController" bundle:nil];
addUsersBlogsView.isWPcom = NO;
addUsersBlogsView.usersBlogs = subsites;
addUsersBlogsView.url = xmlrpc;
addUsersBlogsView.username = self.username;
addUsersBlogsView.password = self.password;
addUsersBlogsView.geolocationEnabled = self.geolocationEnabled;
[self.navigationController pushViewController:addUsersBlogsView animated:YES];
[self displayAddUsersBlogsForXmlRpc:xmlRpc];
} else {
NSMutableDictionary *newBlog;
if(subsite)
newBlog = [NSMutableDictionary dictionaryWithDictionary:subsite];
else
newBlog = [NSMutableDictionary dictionaryWithDictionary:[subsites objectAtIndex:0]];
[newBlog setObject:self.username forKey:@"username"];
[newBlog setObject:self.password forKey:@"password"];
[newBlog setObject:xmlrpc forKey:@"xmlrpc"];

self.blog = [Blog createFromDictionary:newBlog withContext:appDelegate.managedObjectContext];
self.blog.geolocationEnabled = self.geolocationEnabled;
[self.blog dataSave];
[SVProgressHUD showWithStatus:NSLocalizedString(@"Reading blog options", @"") maskType:SVProgressHUDMaskTypeBlack];
[self.blog syncBlogWithSuccess:^{
[[WordPressComApi sharedApi] syncPushNotificationInfo];
if ([self.blog hasJetpack]) {
NSString *wpcomUsername = [[WordPressComApi sharedApi] username];
NSString *wpcomPassword = [[WordPressComApi sharedApi] password];
if (wpcomPassword && wpcomPassword) {
// Try with a known WordPress.com username first
[SVProgressHUD showWithStatus:NSLocalizedString(@"Connecting to Jetpack", @"") maskType:SVProgressHUDMaskTypeBlack];
[self.blog validateJetpackUsername:wpcomUsername
password:wpcomPassword
success:^{
[self dismiss];
} failure:^(NSError *error) {
[self showJetpackAuthentication];
}];
} else {
[self showJetpackAuthentication];
}
} else {
[self dismiss];
}
} failure:^(NSError *error) {
[SVProgressHUD dismiss];
}];
[self createBlogWithXmlRpc:xmlRpc andBlogDetails:subsite];
[self synchronizeNewlyAddedBlog];
}
} else {
NSError *error = [NSError errorWithDomain:@"WordPress" code:0 userInfo:@{NSLocalizedDescriptionKey: NSLocalizedString(@"Sorry, you credentials were good but you don't seem to have access to any blogs", @"")}];
Expand All @@ -102,13 +66,75 @@ - (void)validationSuccess:(NSString *)xmlrpc {
saveButton.enabled = YES;
}

- (void)displayAddUsersBlogsForXmlRpc:(NSString *)xmlRpc
{
AddUsersBlogsViewController *addUsersBlogsView = [[AddUsersBlogsViewController alloc] init];
addUsersBlogsView.isWPcom = NO;
addUsersBlogsView.usersBlogs = subsites;
addUsersBlogsView.url = xmlRpc;
addUsersBlogsView.username = self.username;
addUsersBlogsView.password = self.password;
addUsersBlogsView.geolocationEnabled = self.geolocationEnabled;
[self.navigationController pushViewController:addUsersBlogsView animated:YES];
}

- (void)createBlogWithXmlRpc:(NSString *)xmlRpc andBlogDetails:(NSDictionary *)blogDetails
{
NSAssert(blogDetails != nil, nil);

NSMutableDictionary *newBlog = [NSMutableDictionary dictionaryWithDictionary:blogDetails];
[newBlog setObject:self.username forKey:@"username"];
[newBlog setObject:self.password forKey:@"password"];
[newBlog setObject:xmlRpc forKey:@"xmlrpc"];

WordPressAppDelegate *appDelegate = [WordPressAppDelegate sharedWordPressApplicationDelegate];
self.blog = [Blog createFromDictionary:newBlog withContext:appDelegate.managedObjectContext];
self.blog.geolocationEnabled = self.geolocationEnabled;
[self.blog dataSave];
}

- (void)synchronizeNewlyAddedBlog
{
void (^successBlock)() = ^{
[[WordPressComApi sharedApi] syncPushNotificationInfo];
if ([self.blog hasJetpack]) {
[self connectToJetpack];
} else {
[self dismiss];
}
};
void (^failureBlock)(NSError*) = ^(NSError * error) {
[SVProgressHUD dismiss];
};
[SVProgressHUD showWithStatus:NSLocalizedString(@"Reading blog options", @"") maskType:SVProgressHUDMaskTypeBlack];
[self.blog syncBlogWithSuccess:successBlock failure:failureBlock];
}

- (void)connectToJetpack
{
NSString *wpcomUsername = [WordPressComApi sharedApi].username;
NSString *wpcomPassword = [WordPressComApi sharedApi].password;
if ((wpcomUsername != nil) && (wpcomPassword != nil)) {
// Try with a known WordPress.com username first
[SVProgressHUD showWithStatus:NSLocalizedString(@"Connecting to Jetpack", @"") maskType:SVProgressHUDMaskTypeBlack];
[self.blog validateJetpackUsername:wpcomUsername
password:wpcomPassword
success:^{ [self dismiss]; }
failure:^(NSError *error) { [self showJetpackAuthentication]; }
];
} else {
[self showJetpackAuthentication];
}
}

- (void)dismiss {
[SVProgressHUD dismiss];
if (IS_IPAD) {
[self dismissModalViewControllerAnimated:YES];
}
else
else {
[self.navigationController popToRootViewControllerAnimated:YES];
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"BlogsRefreshNotification" object:nil];
}

Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Blog.m
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ - (void)mergePages:(NSArray *)newPages {

NSMutableArray *pagesToKeep = [NSMutableArray array];
for (NSDictionary *pageInfo in newPages) {
NSNumber *pageID = [[pageInfo objectForKey:@"postid"] numericValue];
NSNumber *pageID = [[pageInfo objectForKey:@"page_id"] numericValue];
Page *newPage = [Page findOrCreateWithBlog:self andPageID:pageID];
if (newPage.remoteStatus == AbstractPostRemoteStatusSync) {
[newPage updateFromDictionary:pageInfo];
Expand Down
Loading