-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathLocalPhotoDeliverer.m
80 lines (67 loc) · 2.16 KB
/
LocalPhotoDeliverer.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
/**
* @file: LocalPhotoDeliverer.m
* @brief: LocalPhotoDeliverer class implementation
* @author: Masayuki YAMAYA
* @date: 2008-03-03
*/
#import "LocalPhotoDeliverer.h"
#import "DebugLog.h"
#import <WebKit/WebView.h>
static NSString * TumblrfulWebElementImageKey = @"TumblrfulWebElementImage"
static NSString * TYPE = @"Local Photo";
@interface LocalPhotoDeliverer ()
- (NSString *)selectedString;
@end
@implementation LocalPhotoDeliverer
+ (id<Deliverer>)create:(DOMHTMLDocument *)document element:(NSDictionary *)clickedElement
{
LocalPhotoDeliverer * deliverer = nil;
id image = [clickedElement objectForKey:TumblrfulWebElementImageKey];
if (image != nil) {
deliverer = [[LocalPhotoDeliverer alloc] initWithDocument:document target:clickedElement];
if (deliverer == nil) {
D(@"Could not alloc+init %@Deliverer.", TYPE);
}
}
return deliverer;
}
- (id)initWithDocument:(DOMHTMLDocument *)document target:(NSDictionary *)targetElement
{
if ((self = [super initWithDocument:document target:targetElement]) != nil) {
clickedElement_ = [targetElement retain];
}
return self;
}
- (NSString *)titleForMenuItem
{
return [NSString stringWithFormat:@"%@ (Local)", [self postType]];
}
- (void)action:(id)sender
{
#pragma unused (sender)
@try {
// コンテンツを得る
NSDictionary * contents = [self photoContents];
// ポストする
[super postPhoto:@""
caption:[contents objectForKey:@"caption"]
through:[contents objectForKey:@"throughURL"]
image:[contents objectForKey:@"data"]];
}
@catch (NSException * e) {
D0([e description]);
[self failedWithException:e];
}
}
- (NSDictionary *)photoContents
{
NSData * data = [clickedElement_ objectForKey:TumblrfulWebElementImageKey];
// キャプション - セレクションがあればそれを blockquoteで囲って追加する
NSString * caption = context_.anchorToDocument;
NSString * selection = [self selectedStringWithBlockquote];
if (selection != nil && [selection length] > 0) {
caption = [caption stringByAppendingFormat:@"\r%@", selection];
}
return [NSDictionary dictionaryWithObjectsAndKeys:data, @"data", caption, @"caption", context_.documentURL, @"throughURL", nil];
}
@end