Posts: 679
Threads: 80
Joined: Nov 2009
Hey guys,
I am working on my plugin, and I cant figure this out:
I would like to create an if statement within an if statement, does this make sense?
I want it to look like this:
Code: if (condition = 'condition') {
if (2nd condition = '2 condition') {
code to be executed
}
}
Is this right, if so why doesn't it work for me:/ and if not, how can i do this?
Thanks
Posts: 339
Threads: 27
Joined: Nov 2009
Try something like this:
$a = 1;
$b = 2;
$c = 3;
if ($a == 1) {
if ($b == 2) {
code to be executed
}
if ($c == ($a + $b)) {
code to be executed
}
}
That only works if things are true.
If something is not true and you need out put for it, then add an else clause.
IE:
if ($b == 2) {
code to be executed
} else {
code to be executed if $b != 2 // != means "does not equal"
}
Posts: 679
Threads: 80
Joined: Nov 2009
2010-03-16, 10:07:11
(This post was last modified: 2010-03-16, 10:07:41 by madguy.)
I changed my code, now it will only display the iPhone theme on the iPhone if the theme exists. But if it doesn't exist, it just generates a blank page...
does any one know how I could just tell it to set $TEMPLATE == (current theme)???
Thanks.
here is my current code:
Code: // Check browser, and change theme
function sic_change_theme() {
global $TEMPLATE;
$file = '../theme/iPhone/template.php';
if (file_exists($file) !== FALSE){
}
else
{
if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE) {
$TEMPLATE = 'iPhone';
}
}
}
Posts: 339
Threads: 27
Joined: Nov 2009
Try this.
Code: function sic_change_theme() {
global $TEMPLATE;
$file = '../theme/iPhone/template.php';
if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') == TRUE) {
if (file_exists($file) {
$TEMPLATE = 'iPhone';
}
}
}
Posts: 679
Threads: 80
Joined: Nov 2009
this causes a crash... like your missing a } or { I am looking for the error now.
Posts: 679
Threads: 80
Joined: Nov 2009
with this code, it causes the whole site to crash. No pages are accessible.
I can't find any errors though..
thanks for trying to help..
Posts: 28
Threads: 6
Joined: Mar 2010
2010-03-16, 12:47:39
(This post was last modified: 2010-03-16, 12:49:27 by staseo.)
The line below misses a bracket:
Code: if (file_exists($file) {
Should be like this:
Code: if (file_exists($file)) {
Posts: 679
Threads: 80
Joined: Nov 2009
I was just about to post that, but this script still doesn't work for me?
any other suggestions?
Posts: 28
Threads: 6
Joined: Mar 2010
There should be a problem with the filename then.
Posts: 679
Threads: 80
Joined: Nov 2009
I can not find one.
I am going to attach my plugin, maybe you can look and see if you can find anything...
Thanks for your help.
######## PLEASE NOT THE FILE ATTACHED IS NOT A WORKING PLUGIN, TO GET THE WORKING PLUGIN, VISIT THE PLUGINS ######## FORUM...
Posts: 28
Threads: 6
Joined: Mar 2010
First thing caught my attention is the plugin description. I'm not sure but it'd be better if you'd remove the double quotes.
Posts: 679
Threads: 80
Joined: Nov 2009
fixed, I did this because with just ' ' when I typed user's it ended the '.. make sense. I believe " " will work the same way though.
Posts: 28
Threads: 6
Joined: Mar 2010
2010-03-16, 14:07:58
(This post was last modified: 2010-03-16, 14:09:29 by staseo.)
Wait... How is the plugin gonna decide which theme is the iPhone theme and how is it gonna load it? The plugin just changes the value of the $TEMPLATE variable to "iPhone" if the file (which has a constant theme folder name???) exists.
I think the plugin should work like this:
- Make the admin to choose the iPhone theme from a dropdown list of the themes in the plugin options page.
- Load the selected theme if the user agent is iPhone.
Otherwise, it'd just look for an "iPhone" folder in the "theme" folder.
PS: Just to be safe, let's change the plugin description line with the line below:
Code: 'This plugin automatically detects a user\'s browser and sets the theme accordingly.', // Plugin Description
Posts: 679
Threads: 80
Joined: Nov 2009
2010-03-16, 14:16:23
(This post was last modified: 2010-03-16, 14:18:21 by madguy.)
I would love it to work this way, I am not good enough at PHP to write this though.
My reason for checking to see if the theme folder called iPhone exist is so if it doesn't,
it will not just display a blank page. Also, Zegnat I believe is the one who told me to change
the theme like I am wanting to all I need to do is set the $TEMPLATE to the name of the iPhone
theme if the browser is an iPhone.
If you would be willing to assist me in the code for this, I would be very willing to do this.
I think it would require the following:
Admin function with the options:
1. Enable/Disable (Using xml)
2. Select theme from list of available themes
3. Save
End user:
1. Automatically change theme to Admin selected theme
2. Enable/Disable switch (Using a cookie)
Does this all make sense?
Would you will be willing to co-develop this plugin with me?
Thanks
Posts: 28
Threads: 6
Joined: Mar 2010
I'm not good at PHP either, you'd do better with someone besides me!
Although, I don't get a blank page if the iPhone theme doesn't exist. In fact, I'm not sure but the site opens with the existing theme in any circumstances ).
BTW, why is there an empty array in the 7th line?
Posts: 679
Threads: 80
Joined: Nov 2009
2010-03-16, 14:28:02
(This post was last modified: 2010-03-16, 14:29:10 by madguy.)
I am not sure why the array was there... I took it out though.
have you tried my current release of the iPhone theme changer?
Without the if statement for file_exists($file) the theme works great, unless I rename or delete the
iPhone theme. I need it to automatically select the other theme if the iPhone theme doesn't exist.
I really wish some one would step up and co-program this plugin with me, I really think this would be
a good plugin, but I really can't do it myself.
Posts: 28
Threads: 6
Joined: Mar 2010
2010-03-16, 14:33:56
(This post was last modified: 2010-03-16, 14:36:21 by staseo.)
Maybe you should set the $file variable like this:
Code: $file = $SITEURL . '/theme/iPhone/template.php';
But of course, you'll also need to add:
Posts: 679
Threads: 80
Joined: Nov 2009
Posts: 28
Threads: 6
Joined: Mar 2010
I edited my post and reminded that you should also add global $SITEURL;, you did that too?
Posts: 679
Threads: 80
Joined: Nov 2009
I added both, and it still doesn't work, I am pretty sure this is an error with the if statements.. I just can't figure out a different way to check weather the file exists.
Posts: 28
Threads: 6
Joined: Mar 2010
Why don't we check just the folder?
Code: function sic_change_theme() {
global $TEMPLATE, $SITEURL;
$iPhoneTemplate = 'iPhone';
$file = $SITEURL . '/theme/' . $iPhoneTemplate;
$found = strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone');
if (file_exists($file) && $found == true) {
$TEMPLATE = $iPhoneTemplate;
}
}
Posts: 679
Threads: 80
Joined: Nov 2009
Nope. Nothing.
I have been working on this for about 7 hours. I am getting a little annoyed.
Posts: 28
Threads: 6
Joined: Mar 2010
I can't think of anything either It's 7.20 AM here in Turkey and I'm really really tired, so I have to leave the forum for now . I attached a debug version of your plugin but notice that I've made another change to the $file variable (turns out there's a constant named GSTHEMESPATH in GS core!) and as I said, I added some debug stuff (but I used echo)... Must... sleep... now...
Posts: 339
Threads: 27
Joined: Nov 2009
Give this a shot. I can't test as I don't have an iPhone.
This should make the $TEMPLATE var equal to "iPhone" when the user is using an iPhone.
Code: add_hook('index-pretemplate','sic_change_theme');
function sic_change_theme() {
global $TEMPLATE;
if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') == true) {
$TEMPLATE = 'iPhone';
}
}
So when the below is called...
Code: include("theme/".$TEMPLATE."/".$template_file);
It should output like this...
Code: include("theme/iPhone/".$template_file);
Try and keep it simple. You were trying to make sure the iPhone folder exists... well, I wouldn't have this plugin if it didn't exist If you want to check for that, show it off in the admin panel.
Posts: 679
Threads: 80
Joined: Nov 2009
This is true, some one asked for this feature so I put in a bunch of time. I currently have this plugin relleased with out checking for the iPhone folder and it works greate.
I will just add some stuff to the admin and Leave it alone.
If some one else would like to assist me in adding some options then I would be willing to work with them and seeing if we can't make this plugin better.
|