Switching links to css via PHP - php

My idea is to switch multiple links to CSS files, if special URL was detected. But I have a trouble: my code includes only css in the first if..else statement. And it doesn't depend on the URL.
Here is my code.
http://pastebin.com/Jm3QFDmH
ported from pastebin
<?php
// get first folder in URL
$f_folder = substr(substr($_SERVER["REQUEST_URI"],1), 0, strpos(substr($_SERVER["REQUEST_URI"],1), "/"));
//get full directory structure from URL for current page
$full_path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
//css for account
if ($f_folder='account') {
?>
<link rel="stylesheet" href="/mainstyle/common.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="/mainstyle/account.css" type="text/css" charset="utf-8" />
<?php
} elseif ($f_folder='signin'||$f_folder='signup'||$full_path='/account/resetPassword'||$full_path='/account/logout') {
?>
<link rel="stylesheet" href="/mainstyle/login-signup.css" type="text/css" charset="utf-8" />
<?php
} else {
?>
<link rel="stylesheet" href="/mainstyle/common.css" type="text/css" charset="utf-8" />
<?php
}
?>
Where is mistake?

if and elseif, should have == comparison operator , not = assignment

Line 7 should be
if ($f_folder=='account') {

Related

open cart 2.2 Change style.css based on language or direction

I am trying change style.css based on language or direction in open cart 2.2
I have this input:
<link type="text/css" href="view/stylesheet/stylesheet.css" rel="stylesheet" media="screen" />
i want change stylesheet.css to stylesheet-rtl.css
This is my try:
<?php $session = new Session();?>
<?php $lang = $session->data['language']; ?>
<?php if ($lang == 'ar') { ?>
<link type="text/css" href="view/stylesheet/stylesheet-rtl.css" rel="stylesheet" media="screen" />
<?php } else { ?>
<link type="text/css" href="view/stylesheet/stylesheet.css" rel="stylesheet" media="screen" />
<?php } ?>
This worked for opencart 2.0.X but not in opencart 2.2.
What changed?
if you are using OC 2.2 you can try this code
<?php $direction = $this->language->get('direction'); ?>
<?php if ($direction == 'rtl') { ?>
<link type="text/css" href="view/stylesheet/stylesheet-rtl.css" rel="stylesheet" media="screen" />
<?php } else { ?>
<link type="text/css" href="view/stylesheet/stylesheet.css" rel="stylesheet" media="screen" />
<?php } ?>

Is there a way to make header.php switch .css when transposh language is switched?

i am using transposh to translate my website from English to Arabic but when i switch language to Arabic it switches the style.css and it reverse the layout of my website leading to a mess, so i made a new style.css which works with the Arabic version very well but now i don't know how to link them together i mean i want to know how to make it switch the css file when it switches the language.
i tried this code but it didn't work
<?php if(MY_CUR_LANG == 'en'){?>
<link rel="stylesheet" href="http://localhost/wordpress/wp-content/themes/style.css" type="text/css" media="screen" />
<?php }elseif(MY_CUR_LANG == 'ar'){?>
<link rel="stylesheet" href="http://localhost/wordpress/wp-content/themes/arabic.css" type="text/css" media="screen" />
<?php } ?>
You cannot jump in and out php code. Try
<?php
if(MY_CUR_LANG == 'en'){
echo'<link rel="stylesheet" href="http://localhost/wordpress/wp-content/themes/style.css" type="text/css" media="screen" />';
}elseif(MY_CUR_LANG == 'ar'){
echo'<link rel="stylesheet" href="http://localhost/wordpress/wp-content/themes/arabic.css" type="text/css" media="screen" />';
}
?>

Replacing php links to static links

I have script which uses absolute addressing in most areas, now I need to change them to relative addressing. But then the issue I am facing here is that, if for instance I have a website named www.example.com Now I want to change the links in php from
<link href="<?php print $theme; ?>style.css" type="text/css" rel="stylesheet" />
<link href="<?php print $theme; ?>css/colorpicker.css" type="text/css" rel="stylesheet" />
to
<link href="http://www.example.com/<?php print $theme; ?>style.css" type="text/css" rel="stylesheet" />
<link href="http://www.example.com/<?php print $theme; ?>css/colorpicker.css" type="text/css" rel="stylesheet" />
But I end up getting this result
<link href="http://www.example.com/http://www.example.com/themes/in/style.css" type="text/css" rel="stylesheet" />
<link href="http://www.example.com/http://www.example.com/themes/in/css/colorpicker.css" type="text/css" rel="stylesheet" />
I know something is wrong somewhere, but I still can't get it to work.. Any help with correct formatting will be highly appreciated. Sorry if my title for question is inappropriate.
Judging by the url setup:
<?php
$path = explode('/', $theme);
$theme = end($path);
?>
<link href="http://www.example.com/themes/<?= $theme ?>/style.css" type="text/css" rel="stylesheet" />
This will split the url in pieces and picks the last item which is I think is the theme name you want.
Your $theme contains this url 'http://www.example.com/themes/in/'. So if you just want the url to be like this
http://www.example.com/style.css instead of
http://www.example.com/http://www.example.com/themes/in/style.css
then remove the $theme from the href section.
hope this helps
Their would be two possible solutions, either you remove the
http://www.example.com/
from starting of <?php print $theme; ?> OR only include
theme name rather than with base bath.

How to load dynamic CSS files based on condition

I have a index.php file which loads (require) 2 different files based on a condition.
Visiting this link will cause;
mysite.com/index.php will load stats.php (require("stats.php");)
Visiting this link will cause;
mysite.com/index.php?auth="jgbsbsbasm" will load encry.php (require("stats_encry.php");)
Done with this code:
<?php
if(isset($_GET['auth'])) require("stats.php");
else require("stats_encry.php");
?>
This works fine. Now my question is; I have a CSS file in the header as static;
<link rel="stylesheet" href="cv.css">
What I want is now to load cv.css file for stats.php and cv1.css for stats_encry.php respectively.
How do I do this?
In your header replace
<link rel="stylesheet" href="cv.css">
with
<?php if(isset($_GET['auth'])){ ?>
<link rel="stylesheet" href="cv.css">
<?php } else { ?>
<link rel="stylesheet" href="cv1.css">
<?php } ?>
You can use this like below syntax
<?php
if(isset($_GET['auth'])){
echo '<link rel="stylesheet" href="cv.css">';
} else {
echo '<link rel="stylesheet" href="cv1.css">';
}
?>

PHP stylesheet print switcher problem revisited?

Okay I have this style sheet switcher which will only works if I leave out the media="print" from the style sheet link.
I was wondering how can I fix this problem without leaving out the media="print" attribute.
Here is the PHP code.
<!-- Print Script -->
<?php if (isset($_GET['css']) && $_GET['css'] == 'print') { ?>
<meta name="robots" content="noindex" />
<link rel="stylesheet" type="text/css" href="http://localhost/styles/print.css" media="print" />
<script type="text/javascript">
//<![CDATA[
if(window.print())
onload = window.print();
else
onload = window.print;
//]]>
</script>
<?php } else { ?>
<link rel="stylesheet" type="text/css" href="http://localhost/styles/style.css" media="screen" />
<?php } ?>
<!-- End Print Script -->
And here is the link you click to change the style sheet.
Print This Page
You don't need PHP code for determining whether to output the CSS file for print. By default the browser won't render the "print" stylesheet and should ignore the "screen" stylesheet when printing.
There may be some rendering issues: maybe the browser hasn't had enough time to render the page and feed it correctly to the printer.
A simplified solution would be:
<head>
<link rel="stylesheet" type="text/css" href="http://localhost/styles/print.css" media="print" />
<link rel="stylesheet" type="text/css" href="http://localhost/styles/style.css" media="screen" />
<script type="text/javascript">
function print_it() {
if(window.print())
onload = window.print();
else
onload = window.print;
}
</script>
</head>
<body>
Print This Page
</body>

Categories