Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 14    Views: 313

awesome123
Aspiring developer
Profile
Posts: 132
Reg: Dec 27, 2011
location unknow...
2,320
08/08/13 08:48 PM (12 years ago)

simple (but ninja) PHP question - plugin's index.php

hey guys is there a php guru here who can guide me on how to rotate my jsonproperty in the index.php? what i do is i have 4 numbers and i want to rotate them everyday. these numbers are connected to different ad code in my xcode project. meaning to say, if i have set 1 in buzztouch - revmob code will fire... if i set it 2 in buzztouch, a different ad will fire. i have my app set to auto-refresh so no need to worry about updating the config. i have set them up already both in my index.php and xcode. the only thing missing is the php code that rotates the number! :) if there's anyone who can help me out on this then i'd totally appreciate it.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
08/08/13 08:55 PM (12 years ago)
Rotate the number as in a cyclic value? 1, then 2, then 3, then 4...? And you want this to be embedded in the plugin's index.php file? Cheers! -- Smug
 
awesome123
Aspiring developer
Profile
Posts: 132
Reg: Dec 27, 2011
location unknow...
2,320
like
08/08/13 10:56 PM (12 years ago)
yes, either in a cycle or random. :) also, yes. if that's possible. everything's all set up already and here is my code in the index.php file <div style='padding-top:10px;'> <b>Should We Show the Ad?</b><br/> Type A Number Only: <br/> 0 = No Ad<br/> 1 = Show Our Ad <br/> 2 = Show Applovin Ad <br/> 3 = Show Revmob Ad </br> 4 = Show Chartboost Ad<br/><br/> <input type="text" name="json_mycustomad" id="json_mycustomad" value="<?php echo fnFormOutput(fnGetJsonProperyValue("mycustomad", $jsonVars));?>"> </div>
 
awesome123
Aspiring developer
Profile
Posts: 132
Reg: Dec 27, 2011
location unknow...
2,320
like
08/08/13 11:14 PM (12 years ago)
^this is the simpler version. i was originally planning to have an option to set a specific number to randomize (let's say 3 and 4 only and exclude the others) so i can set the option to: 0 - if i have no ad to show up 1 - if i want to show my own ad 2,4 - if i want to show ads 2 and 4 is this possible???
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
08/09/13 04:12 AM (12 years ago)
Let me chew on it a bit... Right now I'm distracted with other issues... I'll get back to you. Cheers! -- Smug
 
awesome123
Aspiring developer
Profile
Posts: 132
Reg: Dec 27, 2011
location unknow...
2,320
like
08/09/13 05:25 AM (12 years ago)
thanks smug. it seems to be more complicated than i thought :P
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
08/09/13 06:27 AM (12 years ago)
I'm on my phone so can't give you exact syntax right now, but here's an idea: get the numerical value of the day of week, and do an if/then or switch/case to echo out the appropriate JSON property value for that day. Won't be perfect since you're wanting a 4-day rotation not a 7-day one, but its a simple start. Could also do something similar using the numerical value of the day of month. Or perhaps you could rig up a formula based on the numerical value of the date (divide unix time by 60*60*24). I just woke up so my formula creating brain isn't on at the moment, but I'm sure there's an easy way to do it. ;)
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
08/09/13 06:49 AM (12 years ago)
Ok I took my shower an gave it some thought: Get unix time, divide by seconds in a day. Then get remainder of that value when divided by 4, and convert to your value. So, for instance, something like this: $Json = "A"; $today = floor(time() / (60*60*24)); $remainder = $today/4 - $today; If ($remainder == 0) $Json = "A"; else if ($remainder == .25) $Json = "B"; else if ($remainder == .50) $Json = "C"; else if ($remainder == .75) $Json = "D"; echo $Json;
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
08/09/13 06:50 AM (12 years ago)
Just looked back at your example and noticed you have 5 options not 4. Same logic should apply though
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
08/09/13 09:41 PM (12 years ago)
Mulling over this for a bit, I think you're going to want to do this in your app code. The index.php file of the plugin will insert values into your database. The database is where the BT_config.txt file is getting it's values from, not your index.php file. So random or not, it's not the right 'source'. And you won't be pulling 'random' values from the database. A different approach might be to have 'choices' of valid revenue streams in your index.php file and subsequently your database, to let your app know 'which' ad networks are valid, and within the app, do a random choice of available values. So in your index.php file, keep the values and options you have, and have the value of "mycustomad" be a numerical value such as "0000" with each zero being a placeholder for a boolean value of eligibility for an ad network. For instance, "1111" would mean all 4 ad networks were available, "0110" would mean ad networks 2 and 3 were available, but 1 and 4 are not... Then in your code, you can do an 'if' statement, or a 'switch' statement to detect the value of "mycustomad" and from there, decide which (if any) ad network to utilize. Just my opinion. Cheers! -- Smug
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
08/09/13 10:02 PM (12 years ago)
Good point Smug - the way plugins are normally written, values from the control panel are saved to the database, and the JSON is retrieved from the database. My approach would work using a typical 'dataURL' approach, where the plugin code (in Xcode, Eclipse, Android Studio, etc) looks to see if a dataURL property is set, and if so, loads the screenData from that url. Using my approach, the 'control panel' page would need to have a url property (hidden or otherwise) that points to a php script to generate the 'random' value needed. The plugin code would then look to see what URL is specified, go to it, retrieve the printed 'random' value, and use that in its logic.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
08/09/13 10:18 PM (12 years ago)
Chris, You're right; that would work just as well. I guess it would be a decision based on ability, preference, and convenience. And if the app is going to be online most of the time. :) Cheers! -- Smug
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
08/09/13 10:32 PM (12 years ago)
Definitely. Not sure what's easier to learn - programming via PHP or programming via Objective-C. But certainly all three (ability, preference and convenience) need to be taken into account. Also I add to that list 'target market'. That should tell you how likely it is for the users to have online access. For instance, most smartphone users in the US will have data plans. But users in another country might not. Even in the US, users who are mountain hikers (if it's hiking app for instance) will likely not have data access when they are using the app. Point being ... know your audience and know your own abiliities...
 
awesome123
Aspiring developer
Profile
Posts: 132
Reg: Dec 27, 2011
location unknow...
2,320
like
08/09/13 11:23 PM (12 years ago)
thanks for the wonderful responses! i really appreciate the help. as a non-programmer, looks like i need more than learning how to create buzztouch plugins to implement this feature. LOL
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
08/09/13 11:36 PM (12 years ago)
Well, like chris said, you can host a php file on a server somewhere, and have it feed the info to you when the plugin loads... You've got most of the work done, you just need to implement some code on one side or the other, to make use of the values, i.e. which ads to show and when. In PHP you can use a "rand(0,3)" function to get a random value from a specified range (in this instance, between zero and three) or in xcode you can use code similar to this: +(int) getRandomNumberBetweenMin:(int)min andMax:(int)max { return ( (arc4random() % (max-min+1)) + min ); } In any event, you're pretty close. You just have to organize your plan now and start taking steps. Cheers! -- Smug Oh; did you want to show advertisements "throughout the app" or just "within the plugin"... If you wanted "throughout the app" you're not going to be coding in your plugin; you'll need to alter the app a bit.
 

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.