// // MGMAdinline.m // Adinline // // Created by Mr. Gecko on 2/4/11. // Copyright (c) 2011 Mr. Gecko's Media (James Coleman). All rights reserved. http://mrgeckosmedia.com/ // #import "MGMAdinline.h" #import @protocol MGMChatViewController - (AIWebKitMessageViewController *)messageDisplayController; @end @implementation MGMAdinline + (id)adium { return adium; } - (void)installPlugin { [[adium contentController] registerHTMLContentFilter:self direction:AIFilterIncoming]; [[adium contentController] registerHTMLContentFilter:self direction:AIFilterOutgoing]; } - (void)uninstallPlugin { [[adium contentController] unregisterHTMLContentFilter:self]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (NSString *)filterHTMLString:(NSString *)theHTMLString content:(AIContentObject *)theContent { NSArray *imageExtensions = [NSArray arrayWithObjects:@"png", @"jpg", @"jpeg", @"tif", @"tiff", @"gif", @"bmp", nil]; NSMutableString *html = [[theHTMLString mutableCopy] autorelease]; NSRange range = NSMakeRange(0, [html length]); NSString *shouldScroll = nil; while (range.length>1) { NSAutoreleasePool *pool = [NSAutoreleasePool new]; NSRange linkRange = [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:[[link pathExtension] lowercaseString]]) { if (shouldScroll==nil) { WebView *webview = (WebView *)[[(id)[[[theContent chat] chatContainer] chatViewController] messageDisplayController] messageView]; shouldScroll = [webview stringByEvaluatingJavaScriptFromString:@"nearBottom();"]; } NSString *image = [NSString stringWithFormat:@"", link, shouldScroll]; [html replaceCharactersInRange:linkRange withString:image]; range.location += [image length]-linkRange.length; range.length = [html length]-range.location; } } else { break; } [pool drain]; } return html; } - (CGFloat)filterPriority { return (CGFloat)LOWEST_FILTER_PRIORITY; } @end