tags:

views:

38

answers:

2

I have a theme in which there are numerous options, like:-

  • Setting Theme Type among many available
  • Setting Body Background Color & Image
  • Setting Header & Footer Images
  • Setting General Font Face, Size & Color
  • Setting Text Area Background Color, and Font Face & Font Color
  • Setting Form Area Background Color & Rounder Corners option
  • Setting Form Element Background Color, and Font Face & Font Color
  • Setting Link Default Color, Hover Color & Visited Color, with / without decoration
  • Providing options to upload any number of Images to be used in the user's blog
  • and many more...

Can anybody please provide any info as to how this can be done in a best possible way, using custom PHP & jQuery? I'm also open to other ways around.

EDIT:-
I have got some 12 themes all worked out, along with their own style sheets defined & icon packs. I have also got them to load upon each of the customer's personal taste. What I don't know is that how to manage the changes made to the customer's theme choice by that customer from his own account? This has to take effect both the times :-

  • when the customer is making / loading the changes from his account
  • when the customer is viewing his account along with the changes

BTW, many many thanks for such a quick response, by two users & letting me know about my incomplete question.

Any help is greatly appreciated.

+3  A: 

Try something like this:

<?php

    function template($file, $data = array())
    {
        ob_start();
        extract($data);
        include_once 'path/to/theme/folder/' . $file . '.php';
        return ob_get_clean();
    }


    // Assign values to the template file
    $values['theme_type'] = 'default';
    $values['bg_color'] = '#FFFFFF';
    $values['bg_image'] = 'path/to/bg/image.jpg';
    $values['font_face'] = 'Tahoma, Arial, Verdana';
    $values['font_size'] = '12px';
    $values['font_color'] = '#000000';
    // And so on...

    // Output template file
    echo template('theme_layout', $values);

?>

And the theme_layout.php file in 'path/to/theme/folder/theme_layout.php' should look like this:

<html>
<head>
    <title>Theme Name</title>
    <style type="text/css">
        body {
            background-color: <?php echo $bg_color; ?>;
            background-image: url(<?php echo $bg_image; ?>);
            font-family: <?php echo $font_face; ?>;
            font-size: <?php echo $font_size; ?>;
            font-color: <?php echo $font_color; ?>;
        }
    </style>
</head>
<body>

    Theme type is: <?php echo $theme_type; ?>

</body>
</html>

Update

You are right that was only the concept, here's what you have to do: Add new table in database user_themes for example and save all user related values there. For example user enters the admin page and sees a theme options like BG Color/Image, Font Name/Size/Color and enters his own values there... Form is submitted and values are saved in the database. Then during the theme display (where I assigned values to the template files) you get user entered theme options from database and assign as a theme values.

I really don't understand where jQuery should be used here, maybe in the form where user submits his options.

Hope this is helpful.

Otar
Knowledge Craving
See the updated answer please...
Otar
@Otar - Yes, I meant to control the user input process using jQuery. But many thanks again, for providing the way.
Knowledge Craving
+1  A: 

Create various stylesheets (.css). Each stylesheet represents a theme. Change the <link> element's href attribute to match the path to the selected theme.

If you're allowing user-uploaded CSS files, make sure to sanitize the input, as IE has the ability to execute parts of a CSS file as if it were JavaScript, leading to possible XSS attacks.

strager
@strager - Thanks for such a valuable point mentioned. Sure I will do sanitize the o/p.
Knowledge Craving