Jump to content
MakeWebGames

Multipile .CSS Files


Cronic

Recommended Posts

Hi there, I'm working on a new function so users can decide between a few game layouts.

 

<?php
if ($user_class->bluelayout == 1 ) { ?>
<link rel="stylesheet" href="styles/blue.css" type="text/css">
<? } ?>
<?php
if ($user_class->redlayout == 1){ ?>
<link rel="stylesheet" href="styles/red.css" type="text/css">
<? } ?>

 

Im still working on the function that when they change their layout id, it automatically updates in the database too.

Just wondering, would this make any sense?

Edited by Cronic
Edit1
Link to comment
Share on other sites

Why not something like this, and I've no knowledge with gRPG, but...

(Insert database field - `layout`, TINYINT)

 

<?php
$layout = array(1 => "blue.css", 2 => "red.css"); // Store css names in an array
$layout = $layout[$user_class->layout]; // Search the array for the css file name
?>
<link rel="stylesheet" href="styles/<?php echo $layout; ?>" type="text/css" />

 

I hope that makes sense.

Oh, and I assumed the $user_class was fetch object, and the bluelayout/redlayout where the column names....

Link to comment
Share on other sites

hmmm...

first... add layout to user...

ALTER TABLE `grpgusers` ADD `layout` VARCHAR( 30 ) NOT NULL DEFAULT 'default.css'

 

on classes.php add

$this->layout = $worked['layout'];

 

To display the css

<link rel="stylesheet" href="styles/<?php echo $user_class->layout; ?>" type="text/css" />

Now on user preferences, get a combobox to display all your color schemes, allowing the user to choose...

Something along these lines...

<form method="post">
   <select name="layout" id="layout">
   <option value="blue.css">Blue Layout</option>
   <option value="red.css">Red Layout</option>
   <option value="green.css">Green Layout</option>
   <option value="pink.css">Pink Layout</option>  
   </select>
   <input type="submit" value="Change"  />
</form>

Obviously you will need to add a few extra lines, but i think you can manage to handle the $_POST

Easier than this... impossible! :)

Edited by Lithium
actually... bored!!!!
Link to comment
Share on other sites

Thanks. works now.. :)

I've created it like this:

header.php

<link rel="stylesheet" href="styles/<?php echo $user_class->layout; ?>" type="text/css" />

 

header.php

if(isset($_POST['submit'])){
$theme = $_POST['layout'];
$result = mysql_query("UPDATE `grpgusers` SET `layout` = '".$_POST['layout']."' WHERE `id` = '".$user_class->id."'"); 
echo Message("You have successfully changed your theme.");

 

<div class="menu">
<h3>  Change Site Theme</h3>
<div class="bg">
<br>
<center>
<form method="post">
<select name="layout" id="layout">
<option value="main.css">Default Theme</option>
<option value="blue.css">Blue Theme</option>
<option value="red.css">Red Theme</option>
<option value="green.css">Green Theme</option>
</select>
<input type='submit' name='submit' value='Change Theme'>
</form>
</div>
</div>
Link to comment
Share on other sites

Thanks. works now.. :)

I've created it like this:

See you used my approach to do it! :)

One call for attention...

if(isset($_POST['submit'])){
$theme = $_POST['layout'];
$result = mysql_query("UPDATE `grpgusers` SET `layout` = '".$_POST['layout']."' WHERE `id` = '".$user_class->id."'");

 

Post can be manipulated, and you make no sanitize.... that can lead to issues! ;)

Link to comment
Share on other sites

Might want to add some insurance on that....

 

$colours = array("main","blue","red","green");
if( isset($_POST) ) {
  if( !in_array($_POST['layout'], $colours) ) {
     $_POST['layout'] = 'main';
  }
  $_POST['layout'] = $_POST['layout'].'css';
  // [..] show msg, update field.
} else {
// [...]
foreach($colours as $c) {
  echo '<option value="', $c ,'.css">', $c ,' theme</option>';
}

 

This is so they can't save the webpage to their computer and change the source code, and execute it. For instance, change this line;

<option value="blue.css">Blue Theme</option>

To this;

<option value="redUltraCoolMagic.css">Red Ultra Cool Magic</option>

And then run it on their machine, thus making them not having a theme.... Just some insurance ;)

Edit

Also, as we all know, the stylesheets will end with .css, so why store '.css'? Say you have 1,000 users, that is (Math, please serve me correctly)

.css - 4 bytes

4 bytes * 1000 = 3.90625 kilobytes

But say you have 10,000 members, that is (Again, math, please serve me correctly)

4 byes * 10,000 = 39.0625 kilobytes

That will be, x amount of memory, wasted. Just something to think about. (I know in the examples given, it's low, but consider if you're on a tight budget, as these 'mistakes', throughout your whole game, was wasting xMB, which not only uses more bandwidth, no matter if you've optimized your queries or not, but server storage space....

Yes. I may be being anal, but think about the top companies, for instance Google.

4 bytes * 1,000,000,000 = 3.7252903 gigabytes

Get where I'm going....?

Edited by sniko
being anal.
Link to comment
Share on other sites

@sniko, you're being kind :P

The problem without sanitizing, something along the lines sniko suggested, may lead to more serious problems than the one sniko showed! :)

Oooo thank you! :) I wanted the OP, and other readers, be aware of such things ;)

(I also posted about memory wastage)

Link to comment
Share on other sites

Might want to add some insurance on that....

 

$colours = array("main","blue","red","green");
if( isset($_POST) ) {
  if( !in_array($_POST['layout'], $colours) ) {
     $_POST['layout'] = 'main';
  }
  $_POST['layout'] = $_POST['layout'].'css';
  // [..] show msg, update field.
} else {
// [...]
foreach($colours as $c) {
  echo '<option value="', $c ,'.css">', $c ,' theme</option>';
}

 

This is so they can't save the webpage to their computer and change the source code, and execute it. For instance, change this line;

<option value="blue.css">Blue Theme</option>

To this;

<option value="redUltraCoolMagic.css">Red Ultra Cool Magic</option>

And then run it on their machine, thus making them not having a theme.... Just some insurance ;)

Edit

Also, as we all know, the stylesheets will end with .css, so why store '.css'? Say you have 1,000 users, that is (Math, please serve me correctly)

.css - 4 bytes

4 bytes * 1000 = 3.90625 kilobytes

But say you have 10,000 members, that is (Again, math, please serve me correctly)

4 byes * 10,000 = 39.0625 kilobytes

That will be, x amount of memory, wasted. Just something to think about. (I know in the examples given, it's low, but consider if you're on a tight budget, as these 'mistakes', throughout your whole game, was wasting xMB, which not only uses more bandwidth, no matter if you've optimized your queries or not, but server storage space....

Yes. I may be being anal, but think about the top companies, for instance Google.

4 bytes * 1,000,000,000 = 3.7252903 gigabytes

Get where I'm going....?

But for arguments sake if you were google 4GB is nothing.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...