[MOD] Sub-themes [MOD] Sub-themes
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

[MOD] Sub-themes

Started by Titooy, October 16, 2005, 08:19:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Titooy

This mod allows you to choose another theme for a category. Like all modern board software. It's based on 1.4.1 cvs.

Add a theme field to your "categories" table.

<coppermine>/include/init.inc.php

Find
// Process theme selection if present in URI or in user profile
if (!empty($_GET['theme'])) {
    $USER['theme'] = $_GET['theme'];
}
// Load theme file
if (isset($USER['theme']) && !strstr($USER['theme'], '/') && is_dir('themes/' . $USER['theme'])) {
    $CONFIG['theme'] = strtr($USER['theme'], '$/\\:*?"\'<>|`', '____________');
} else {
    unset($USER['theme']);
}


If you don't want people to be able to choose another theme than the on you chose, remove it or comment it out.

Add before
// Looks if there's a sub-theme for that category
if (!empty($_GET['cat'])) {
   $result = cpg_db_query("SELECT parent,theme FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '{$_GET['cat']}'");
   $row = mysql_fetch_array($result);
   if (!empty($row['theme']) && !isset($theme_temp))
      $theme_temp = $row['theme'];
   mysql_free_result($result);
   while($row['parent'] != 0)
   {
      $result = cpg_db_query("SELECT parent,theme FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '{$row['parent']}'");
      $row = mysql_fetch_array($result);
      mysql_free_result($result);
      if (isset($row['theme']) && !isset($theme_temp))
         $theme_temp = $row['theme'];
   } // while
   if (isset($theme_temp))
      $CONFIG['theme'] = $theme_temp;
}

// Looks if there's a sub-theme for that album
if (!empty($_GET['album'])) {
   $result = cpg_db_query("SELECT category FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = '{$_GET['album']}'");
   $row = mysql_fetch_array($result);
   mysql_free_result($result);
   $row['parent'] =  $row['category'];
   while($row['parent'] != 0)
   {
      $result = cpg_db_query("SELECT parent,theme FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '{$row['parent']}'");
      $row = mysql_fetch_array($result);
      mysql_free_result($result);
      if (isset($row['theme']) && !isset($theme_temp))
         $theme_temp = $row['theme'];
   } // while
   if (isset($theme_temp))
      $CONFIG['theme'] = $theme_temp;
}




<coppermine>/catmgr.php
Find
function display_cat_list() {

Add before
function form_sub_theme() {
    global $CONFIG, $lang_catmgr_php, $current_category;

    $theme_dir = 'themes/';

    $dir = opendir($theme_dir);
    while ($file = readdir($dir)) {
        if (is_dir($theme_dir . $file) && $file != "." && $file != "..") {
            $theme_array[] = $file;
        }
    }
    closedir($dir);

    natcasesort($theme_array);

    echo <<<EOT
        <tr>
            <td class="tableb" width="60%">
                        {$lang_catmgr_php['cat_theme']}
        </td>
        <td class="tableb" valign="top">
                        <select name="theme" class="listbox">
EOT;
    echo "                    <option value=\"\"></option>\n";
    foreach ($theme_array as $theme) {
        echo "                                <option value=\"$theme\" " . ($theme == $current_category['theme'] ? 'selected="selected"' : '') . ">" . strtr(ucfirst($theme), '_', ' ') . "</option>\n";
    }
    echo <<<EOT
                        </select>
                </td>
        </tr>

EOT;
}




Find
$current_category = array('cid' => '0', 'name' => '', 'parent' => '0', 'description' => '');

Change to
$current_category = array('cid' => '0', 'name' => '', 'parent' => '0', 'description' => '', 'theme' => '');


Find
        $result = cpg_db_query("SELECT cid, name, parent, description, thumb FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cid' LIMIT 1");

Change to
        $result = cpg_db_query("SELECT cid, name, parent, description, thumb, theme FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cid' LIMIT 1");


Find twice
        if (!isset($_POST['cid']) || !isset($_POST['parent']) || !isset($_POST['name']) || !isset($_POST['description']))

Change to
        if (!isset($_POST['cid']) || !isset($_POST['parent']) || !isset($_POST['name']) || !isset($_POST['description']) || !isset($_POST['theme']))


Find twice
                $description = addslashes($_POST['description']);

Add after
                $theme = addslashes($_POST['theme']);



Find
                cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent='$parent', name='$name', description='$description', thumb='$thumb' WHERE cid = '$cid' LIMIT 1");
                }else{
                        cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET name='$name', description='$description', thumb='$thumb' WHERE cid = '$cid' LIMIT 1");


Change to
                cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent='$parent', name='$name', description='$description', thumb='$thumb', theme='$theme' WHERE cid = '$cid' LIMIT 1");
                }else{
                        cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET name='$name', description='$description', thumb='$thumb', theme='$theme' WHERE cid = '$cid' LIMIT 1");



Find
        cpg_db_query("INSERT INTO {$CONFIG['TABLE_CATEGORIES']} (pos, parent, name, description) VALUES ('10000', '$parent', '$name', '$description')");

Change to
        cpg_db_query("INSERT INTO {$CONFIG['TABLE_CATEGORIES']} (pos, parent, name, description, theme) VALUES ('10000', '$parent', '$name', '$description', '$theme')");


Find
form_alb_thumb();

Add before
form_sub_theme();



<coppermine>/lang/<your_language>.php (and all the languages used by administrators)
Find
  'cat_desc' => 'Category description',

Add after
  'cat_theme' => 'Category theme',
(italic to be translated)

That's it!

Tranz

Thanks for the contribution.

I wasn't sure in which mods/hacks subcategory to put this so it's in Themes, but it might belong elsewhere.

maime

great  ;D ;D ;D,
This is what I was looking for.
Thanks

Pascal YAP

Hello Tittoy,

Nice work  ;D and,
It's would be nice to see this MOD in an other place too ! In french board for exemple  ;D
http://forum.coppermine-gallery.net/index.php?board=38.0

Bien cool ton MOD man !  ;)

PYAP

Pascal YAP

#4

Woofy

Hi there !

Is this MOD working on cpg 1.3.x ? Or needing some modification ?

Titooy

Oops I had forgotten the modif in the lang file... fixed now.

Quote from: Woofy on October 25, 2005, 03:38:52 PM
Hi there !

Is this MOD working on cpg 1.3.x ? Or needing some modification ?

I didn't try yet but at least you shoud change all cpg_db_query() into db_query() to make it work on 1.3.x

Joachim Müller

as suggested in the subject: cpg1.4.x only.

Blueiris

Not sure where to post this question, but this mod comes awfully close to what I'm looking to do. Is there a way to modify this so that the owner of a user gallery can choose a theme for an album, so that theme is used for that album regardless of what theme the visitor or other users may be viewing the gallery itself in?

I'd like to have special album themes for things like birthday party photos, etc., that the album owner could choose for that album.

I'd really like to write this myself, but I'm too green with php, and I'm lost with the coding.
You can lead a horse to water, but you can't make him drink - he's got to discover that it's wet for himself.

psylocke

I was trying to install this MOD http://forum.coppermine-gallery.net/index.php?topic=22781.0

My version is 1.4.10

But on <coppermine>/catmgr.php
I couldn't find twice this lines:

Find twice        if (!isset($_POST['cid']) || !isset($_POST['parent']) || !isset($_POST['name']) || !isset($_POST['description']))Change to        if (!isset($_POST['cid']) || !isset($_POST['parent']) || !isset($_POST['name']) || !isset($_POST['description']) || !isset($_POST['theme']))


when I go to EDIT category I get an error message too:

Critical error
There was an error while processing a database query 

I don't know what am I doing wrong can someone help me with it?

jesusarmy

Quote from: psylocke on March 21, 2007, 10:00:36 PM
I couldn't find twice this lines:

Find twice        if (!isset($_POST['cid']) || !isset($_POST['parent']) || !isset($_POST['name']) || !isset($_POST['description']))Change to        if (!isset($_POST['cid']) || !isset($_POST['parent']) || !isset($_POST['name']) || !isset($_POST['description']) || !isset($_POST['theme']))


when I go to EDIT category I get an error message too:

Critical error
There was an error while processing a database query 

1. The second time this appears, it is not quite the same. The actual line in my version of cpg is if (!isset($_POST['parent']) || !isset($_POST['name']) || !isset($_POST['description']))

I suggest you just change it to if (!isset($_POST['parent']) || !isset($_POST['name']) || !isset($_POST['description']) || !isset($_POST['theme']))

2. You missed the first step which is to add a field called theme to your category database, using your sql interface. It needs to be VARCHAR (255)



jesusarmy

To extend this mod to work with meta-albums based on an album rather than a category, such as Last Additions in an Album, make the following further changes.

In the modded init.inc.php, find:
(to avoid a database query that is not needed in this situation)
// Looks if there's a sub-theme for that category
if (!empty($_GET['cat'])) {


change to:
// Looks if there's a sub-theme for that category
if (!empty($_GET['cat']) && $_GET['cat'] >= 0) {


And find:
// Looks if there's a sub-theme for that album
if (!empty($_GET['album'])) {
   $result = cpg_db_query("SELECT category FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = '{$_GET['album']}'");


and change to:
// Looks if there's a sub-theme for that album
if (!empty($_GET['album'])) {
   if (!is_numeric($_GET['album'])) { // Is it a meta-album?
      $actual_album = -$_GET['cat']; // actual album id is sent as negative catgory id
   } else {
      $actual_album = $_GET['album'];
   }

   $result = cpg_db_query("SELECT category FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = '{$actual_album}'");


Explanation: In the case of a meta-album based on an album (such as http://www.jesus.org.uk/gallery/thumbnails.php?album=lastup&cat=-42), the 'album' variable carries the meta-album identifier, and the 'cat' variable carries the actual album as a negative value.

saith

Great Mod. i'de like to know if I could use a sub-theme with only a few specification. I Mean I have a theme for my whole gallery, and I just want a few things to change when  we're on a particular gallery. What I mean is that I don't want a totally different theme but just a few changes. So I can do that by copying the general theme and modifying the thing I want to change for the caegory, but then if I have changes to do on the general gallery, I'll have to do it for the general theme, and the sub-theme of the category. Is there a way I can tell the sub-theme to load all the settings from my main theme and ad then the changes I want ?

Nibbler


Oingo

Hello,

I've applied the Mod... (Thanks by the way... this is really nice :))
At the beginning it was not working...  ???   

I had a look in the post and found out why:
expected behaviour: when using the theme selector or forcing a theme in the address bar, the theme you specify is stored in a cookie, while the default theme stays as set in coppermine's config.

The cookies... My 'default' theme was stored in a cookie...


My question:
I would like to change the behavior for the Guest user, I would like CopperMine to not use the theme stored in a cookie for guests . Do you know how I can set this up ?

However I would like to still be able to force a theme in the adresse bar.


Another way to reach my goal:
To not store the theme in the cookie when forcing a theme in the address bar.
Do you  know in wich file I should look for ?

Many thanks for your help,

Regards,

Oingo

Nibbler

Look in include/init.inc.php for references to lang. Where you see $USER['lang'] =  that's the language pref being stored in the cookie.

ff

I changed all files as said and created the record in cpg_categories.

But the added theme for the gallery isn't put into this record.

Adding the themename directly to the record does give the correct theme at chosen category.
And the themename is also shown in the editscreen.

Did something change in CPG 1.4.19 for security reasons that caused this mod to be unable to write to the database?