Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 5    Views: 85

shaun
Aspiring developer
Profile
Posts: 4
Reg: Oct 22, 2011
location unknow...
2,990
01/06/14 05:00 AM (11 years ago)

Adding Merge Fields capability to the Menu Image Advanced plugin

I am using the Menu Image Advanced plugin and would like to pull the header image from a URL using merge fields. Unfortunately, this option wasn't available out-of-the-box, so I am attempting to modify the source code. Since this is my first attempt at modifying anything, I would appreciate some feedback. So far, I just cut and paste some code from another plugin. My PHP script then uses a redirect to the image file: header("Location: http://www.webpage.org/image.png"); It seems to be sort of working except that I get the IOS "loading" image as a second image beneath the actual loaded image. Any thoughts? Also, will the Android code be similar when I get to that stage? In the Cr_menu_advanced.m file I changed the following code: if([imageURL length] > 0){ NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imageURL]]; tmpImage = [[UIImage alloc] initWithData:imageData]; } and replaced it with this: if([imageURL length] > 0){ if([self.imageURL length] > 3){ //merge possible variables in URL imageURL = [BT_strings mergeBTVariablesInString:self.imageURL]; } //escape bogus characters in URL NSString *escapedURL = [imageURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; if([escapedURL length] > 3){ [self showProgress]; [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"Downloading URL, not caching%@", @""]]; NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:escapedURL]]; tmpImage = [[UIImage alloc] initWithData:imageData]; }else{ [self showAlert:nil theMessage:NSLocalizedString(@"noLocalDataAvailable", @"Data for this screen has not been downloaded. Please check your internet connection.") alertTag:0]; } }
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
01/06/14 05:22 AM (11 years ago)
I don't understand what you're asking. The Menu with Image Advanced will allow a header image via url, you don't need to use merge fields. It works in both Android and iOS. http://www.yourserver.com/path/to/imageHeader.png I use a php script to randomly change the banner image as well. If I don't understand your question correctly, would you rephrase it? Cheers! -- Smug
 
shaun
Aspiring developer
Profile
Posts: 4
Reg: Oct 22, 2011
location unknow...
2,990
like
01/06/14 06:48 AM (11 years ago)
I am sending the current screen ID to the php script in order to select the correct image. The url path didn't accept merge fields until I made the source code changes. Do I have an older version of the plugin? I downloaded it about a month ago. I have to go to work now, but will check back later. Thanks for any of your thoughts.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/06/14 10:00 AM (11 years ago)
Try something like this: Old: if([imageURL length] > 0){ NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imageURL]]; tmpImage = [[UIImage alloc] initWithData:imageData]; } New: if([imageURL length] > 0){ imageURL = [NSString stringWithFormat:@"%@?screenId=%@", imageURL, self.screenData.itemId]; NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imageURL]]; tmpImage = [[UIImage alloc] initWithData:imageData]; }
 
shaun
Aspiring developer
Profile
Posts: 4
Reg: Oct 22, 2011
location unknow...
2,990
like
01/07/14 06:41 AM (11 years ago)
Thanks chris (and smug). If I understand correctly, your suggested code will append the screenId to whatever url is in the json data rather than use the buzztouch merge field variables. I'll explore whether that makes sense for my application. The main problem I'm having is the double image thing I mentioned earlier. I will post here if I can solve it. Thanks, shaun
 
shaun
Aspiring developer
Profile
Posts: 4
Reg: Oct 22, 2011
location unknow...
2,990
like
01/09/14 04:17 AM (11 years ago)
I finally solved it. I just needed to delete the following line from my original post: [self showProgress];
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.