Made it check the path of the url and not the full url to prevent it from allowing urls with the parameters of an image extension. Made it not embed images from people that are strangers unless you set a default to allow images by strangers.
This commit is contained in:
parent
1bc7849cee
commit
1002a9616f
@ -10,13 +10,15 @@
|
|||||||
#import <Adium/AIPlugin.h>
|
#import <Adium/AIPlugin.h>
|
||||||
#import <Adium/AISharedAdium.h>
|
#import <Adium/AISharedAdium.h>
|
||||||
#import <Adium/AIChat.h>
|
#import <Adium/AIChat.h>
|
||||||
|
#import <Adium/AIListObject.h>
|
||||||
|
#import <Adium/AIContactControllerProtocol.h>
|
||||||
#import <Adium/AICorePluginLoader.h>
|
#import <Adium/AICorePluginLoader.h>
|
||||||
#import <Adium/AIContentControllerProtocol.h>
|
#import <Adium/AIContentControllerProtocol.h>
|
||||||
#import <Adium/AIInterfaceControllerProtocol.h>
|
#import <Adium/AIInterfaceControllerProtocol.h>
|
||||||
#import "WebKit Message View/AIWebKitMessageViewController.h"
|
#import "WebKit Message View/AIWebKitMessageViewController.h"
|
||||||
|
|
||||||
@interface MGMAdinline : AIPlugin <AIHTMLContentFilter> {
|
@interface MGMAdinline : AIPlugin <AIHTMLContentFilter> {
|
||||||
|
BOOL allowsStrangers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
@ -9,6 +9,8 @@
|
|||||||
#import "MGMAdinline.h"
|
#import "MGMAdinline.h"
|
||||||
#import <WebKit/Webkit.h>
|
#import <WebKit/Webkit.h>
|
||||||
|
|
||||||
|
NSString * const MGMAIAllowStrangers = @"MGMAIAllowStrangers";
|
||||||
|
|
||||||
@protocol MGMChatViewController <AIChatViewController>
|
@protocol MGMChatViewController <AIChatViewController>
|
||||||
- (AIWebKitMessageViewController *)messageDisplayController;
|
- (AIWebKitMessageViewController *)messageDisplayController;
|
||||||
@end
|
@end
|
||||||
@ -19,6 +21,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)installPlugin {
|
- (void)installPlugin {
|
||||||
|
allowsStrangers = [[NSUserDefaults standardUserDefaults] boolForKey:MGMAIAllowStrangers];
|
||||||
[[adium contentController] registerHTMLContentFilter:self direction:AIFilterIncoming];
|
[[adium contentController] registerHTMLContentFilter:self direction:AIFilterIncoming];
|
||||||
[[adium contentController] registerHTMLContentFilter:self direction:AIFilterOutgoing];
|
[[adium contentController] registerHTMLContentFilter:self direction:AIFilterOutgoing];
|
||||||
}
|
}
|
||||||
@ -28,44 +31,48 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)filterHTMLString:(NSString *)theHTMLString content:(AIContentObject *)theContent {
|
- (NSString *)filterHTMLString:(NSString *)theHTMLString content:(AIContentObject *)theContent {
|
||||||
NSArray *imageExtensions = [NSArray arrayWithObjects:@"png", @"jpg", @"jpeg", @"tif", @"tiff", @"gif", @"bmp", nil];
|
AIListObject *source = [theContent source];
|
||||||
NSMutableString *html = [[theHTMLString mutableCopy] autorelease];
|
if (allowsStrangers || ![source isStranger]) {
|
||||||
NSRange range = NSMakeRange(0, [html length]);
|
NSArray *imageExtensions = [NSArray arrayWithObjects:@"png", @"jpg", @"jpeg", @"tif", @"tiff", @"gif", @"bmp", nil];
|
||||||
NSString *shouldScroll = nil;
|
NSMutableString *html = [[theHTMLString mutableCopy] autorelease];
|
||||||
while (range.length>1) {
|
NSRange range = NSMakeRange(0, [html length]);
|
||||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
NSString *shouldScroll = nil;
|
||||||
NSRange linkRange = [html rangeOfString:@"<a " options:NSCaseInsensitiveSearch range:range];
|
while (range.length>1) {
|
||||||
if (linkRange.location!=NSNotFound) {
|
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||||
range.location = linkRange.location+linkRange.length;
|
NSRange linkRange = [html rangeOfString:@"<a " options:NSCaseInsensitiveSearch range:range];
|
||||||
range.length = [html length]-range.location;
|
if (linkRange.location!=NSNotFound) {
|
||||||
NSRange linkStartRange = [html rangeOfString:@">" options:NSCaseInsensitiveSearch range:range];
|
range.location = linkRange.location+linkRange.length;
|
||||||
if (linkStartRange.location==NSNotFound)
|
|
||||||
continue;
|
|
||||||
range.location = linkStartRange.location+linkStartRange.length;
|
|
||||||
range.length = [html length]-range.location;
|
|
||||||
NSRange linkEndRange = [html rangeOfString:@"<" options:NSCaseInsensitiveSearch range:range];
|
|
||||||
if (linkEndRange.location==NSNotFound)
|
|
||||||
continue;
|
|
||||||
range.location = linkEndRange.location+linkEndRange.length;
|
|
||||||
range.length = [html length]-range.location;
|
|
||||||
linkRange = NSMakeRange(linkStartRange.location+linkStartRange.length, linkEndRange.location-(linkStartRange.location+linkStartRange.length));
|
|
||||||
NSString *link = [html substringWithRange:linkRange];
|
|
||||||
if ([imageExtensions containsObject:[[link pathExtension] lowercaseString]]) {
|
|
||||||
if (shouldScroll==nil) {
|
|
||||||
WebView *webview = (WebView *)[[(id<MGMChatViewController>)[[[theContent chat] chatContainer] chatViewController] messageDisplayController] messageView];
|
|
||||||
shouldScroll = [webview stringByEvaluatingJavaScriptFromString:@"nearBottom();"];
|
|
||||||
}
|
|
||||||
NSString *image = [NSString stringWithFormat:@"<img src=\"%@\" style=\"max-width: 100%%; max-height: 100%%;\" onLoad=\"imageSwap(this, false);alignChat(%@);\" />", link, shouldScroll];
|
|
||||||
[html replaceCharactersInRange:linkRange withString:image];
|
|
||||||
range.location += [image length]-linkRange.length;
|
|
||||||
range.length = [html length]-range.location;
|
range.length = [html length]-range.location;
|
||||||
|
NSRange linkStartRange = [html rangeOfString:@">" options:NSCaseInsensitiveSearch range:range];
|
||||||
|
if (linkStartRange.location==NSNotFound)
|
||||||
|
continue;
|
||||||
|
range.location = linkStartRange.location+linkStartRange.length;
|
||||||
|
range.length = [html length]-range.location;
|
||||||
|
NSRange linkEndRange = [html rangeOfString:@"<" options:NSCaseInsensitiveSearch range:range];
|
||||||
|
if (linkEndRange.location==NSNotFound)
|
||||||
|
continue;
|
||||||
|
range.location = linkEndRange.location+linkEndRange.length;
|
||||||
|
range.length = [html length]-range.location;
|
||||||
|
linkRange = NSMakeRange(linkStartRange.location+linkStartRange.length, linkEndRange.location-(linkStartRange.location+linkStartRange.length));
|
||||||
|
NSString *link = [html substringWithRange:linkRange];
|
||||||
|
if ([imageExtensions containsObject:[[[[NSURL URLWithString:link] path] pathExtension] lowercaseString]]) {
|
||||||
|
if (shouldScroll==nil) {
|
||||||
|
WebView *webview = (WebView *)[[(id<MGMChatViewController>)[[[theContent chat] chatContainer] chatViewController] messageDisplayController] messageView];
|
||||||
|
shouldScroll = [webview stringByEvaluatingJavaScriptFromString:@"nearBottom();"];
|
||||||
|
}
|
||||||
|
NSString *image = [NSString stringWithFormat:@"<img src=\"%@\" style=\"max-width: 100%%; max-height: 100%%;\" onLoad=\"imageSwap(this, false);alignChat(%@);\" />", link, shouldScroll];
|
||||||
|
[html replaceCharactersInRange:linkRange withString:image];
|
||||||
|
range.location += [image length]-linkRange.length;
|
||||||
|
range.length = [html length]-range.location;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
[pool drain];
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
[pool drain];
|
return html;
|
||||||
}
|
}
|
||||||
return html;
|
return theHTMLString;
|
||||||
}
|
}
|
||||||
- (CGFloat)filterPriority {
|
- (CGFloat)filterPriority {
|
||||||
return (CGFloat)LOWEST_FILTER_PRIORITY;
|
return (CGFloat)LOWEST_FILTER_PRIORITY;
|
||||||
|
Loading…
Reference in New Issue
Block a user