Permalink
Browse files

fixed bug in newlines in captions and removed weird custom caption op…

…tion
  • Loading branch information...
aarone committed Sep 19, 2010
1 parent 446b9cf commit f77e6cac8a1fb1705f60eb1ad65477e64ad14000
Showing with 30 additions and 37 deletions.
  1. +19 −11 SmugMugCore/SMEUploadRequest.m
  2. +11 −26 SmugMugExport/Source/SMEExportPlugin.m
@@ -134,15 +134,23 @@ -(NSString *)imageHeadersForRequest:(CFHTTPMessageRef *)myRequest {
return result;
}
+/*
+ * This is weird. The SmugMug API says that '\n' should be sent as '\r'; presumably
+ * because many clients/servers don't like '\n' in values (HTTP has line-endings
+ * marked by "\r\n" (CRLF).
+ *
+ * The problem is that CFHTTP doesn't like either '\r' in values and will disregard
+ * such values.
+ *
+ * The workaround is to change '\n' with <br /> which ends up magically showing up
+ * as an HTML entity on the page.
+ *
+ * see:
+ * [1] http://wiki.smugmug.net/display/SmugMug/Uploading
+ * [2] http://www.opensource.apple.com/source/CFNetwork/CFNetwork-128/HTTP/CFHTTPMessage.c
+ */
-(NSString *)cleanNewlines:(NSString *)aString {
- // adding a newline to a header will cause the sent request to be invalid.
- // use carriage returns instead of newlines.
- NSMutableString *cleanedString = [NSMutableString stringWithString:aString];
- [cleanedString replaceOccurrencesOfString:@"\n"
- withString:@"\r"
- options:0
- range:NSMakeRange(0, [cleanedString length])];
- return [NSString stringWithString:cleanedString];
+ return [[aString componentsSeparatedByString:@"\n"] componentsJoinedByString:@"<br />"];
}
-(NSString *)cleanKeywords:(NSArray *)theKeywords {
@@ -186,9 +194,9 @@ -(void)startImageUpload {
if(!IsEmpty([[self image] altitude]))
CFHTTPMessageSetHeaderFieldValue(myRequest, CFSTR("X-Smug-Altitude"), (CFStringRef)[[[self image] altitude] stringValue]);
-
+
if(!IsEmpty([[self image] caption]))
- CFHTTPMessageSetHeaderFieldValue(myRequest, CFSTR("X-Smug-Caption"), (CFStringRef)[self cleanNewlines:[[self image] caption]]);
+ CFHTTPMessageSetHeaderFieldValue(myRequest, CFSTR("X-Smug-Caption"), (CFStringRef)([self cleanNewlines:[[self image] caption]]));
if(!IsEmpty([[self image] keywords]))
CFHTTPMessageSetHeaderFieldValue(myRequest, CFSTR("X-Smug-Keywords"), (CFStringRef)[self cleanKeywords:[[self image] keywords]]);
@@ -223,7 +231,7 @@ -(void)startImageUpload {
[NSThread detachNewThreadSelector:@selector(beingUploadProgressTracking) toTarget:self withObject:nil];
- // CFRunLoop is not toll-free bridges to NSRunLoop
+ // CFRunLoop is not toll-free bridge to NSRunLoop
while ([self isUploading])
CFRunLoopRun();
@@ -159,7 +159,6 @@ -(void)resetAlbumUrlFetchAttemptCount;
-(void)performUploadCompletionTasks:(BOOL)wasSuccessful;
-(NSData *)sourceDataAtPath:(NSString *)pathToImage shouldScale:(BOOL)shouldScale errorString:(NSString **)err;
--(NSString *)formatCaptionWithTitle:(NSString *)title caption:(NSString *)caption;
-(SMEImage *)nextImage;
-(void)uploadNextImage;
@@ -1161,8 +1160,8 @@ -(SMEImage *)nextImage {
[[self exportManager] imageCaptionAtIndex:[self imagesUploaded]];
NSString *selectedUploadFilenameOption = [[NSUserDefaults smugMugUserDefaults] objectForKey:SMUploadedFilename];
NSString *title = [selectedUploadFilenameOption isEqualToString:SMUploadedFilenameOptionTitle] ?
- iPhotoTitle:[nextFile lastPathComponent];
- NSString *caption = [self formatCaptionWithTitle:title caption:[[self exportManager] imageCommentsAtIndex:[self imagesUploaded]]];
+ iPhotoTitle:[nextFile lastPathComponent];
+ NSString *caption = [[self exportManager] imageCommentsAtIndex:[self imagesUploaded]];
SMEImage *img = [SMEImage imageWithTitle:title
caption:caption
@@ -1175,8 +1174,15 @@ -(SMEImage *)nextImage {
struct IPPhotoInfo *photoInfo = [[self exportManager] photoAtIndex:[self imagesUploaded]];
Class _LocationCommon = NSClassFromString(@"LocationCommon");
NSDictionary *location = [_LocationCommon locationDictFromPhoto:photoInfo];
- [img setLatitude:[location objectForKey:@"latitude"]];
- [img setLongitude:[location objectForKey:@"longitude"]];
+
+ if([[location objectForKey:@"latitude"] floatValue] <= 90.0 &&
+ [[location objectForKey:@"latitude"] floatValue] >= -90.0)
+ [img setLatitude:[location objectForKey:@"latitude"]];
+
+ if([[location objectForKey:@"longitude"] floatValue] <= 180.0 &&
+ [[location objectForKey:@"longitude"] floatValue] >= -180.0)
+ [img setLongitude:[location objectForKey:@"longitude"]];
+
} else if([self iPhotoMajorVersion] < 8) {
// we get the gps data for older versions from the photo
CGImageSourceRef source = CGImageSourceCreateWithData( (CFDataRef) srcData, NULL);
@@ -1266,27 +1272,6 @@ -(NSData *)sourceDataAtPath:(NSString *)pathToImage shouldScale:(BOOL)shouldScal
return imgData;
}
--(NSString *)formatCaptionWithTitle:(NSString *)title caption:(NSString *)caption {
- NSString *captionFormat = [[NSUserDefaults smugMugUserDefaults] objectForKey:@"SMECaptionFormatString"];
- if(captionFormat == nil)
- captionFormat = SMEDefaultCaptionFormat;
-
-
- NSMutableString *result = [NSMutableString stringWithString:captionFormat];
- if(title != nil)
- [result replaceOccurrencesOfString:@"%title"
- withString:title
- options:0
- range:NSMakeRange(0, [result length])];
- if(caption != nil)
- [result replaceOccurrencesOfString:@"%caption"
- withString:caption
- options:0
- range:NSMakeRange(0, [result length])];
- return [NSString stringWithString:result];
-
-}
-
-(int)iPhotoMajorVersion {
NSString *versionString = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];

0 comments on commit f77e6ca

Please sign in to comment.