Advanced search  

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

Pages: [1]   Go Down

Author Topic: [MOD] Sub-themes  (Read 27667 times)

0 Members and 1 Guest are viewing this topic.

Titooy

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Posts: 736
    • under construction...
[MOD] Sub-themes
« on: October 16, 2005, 08:19:38 pm »

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!
« Last Edit: October 25, 2005, 07:01:22 pm by TranzNDance »
Logged

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: [MOD] Sub-themes
« Reply #1 on: October 16, 2005, 08:50:22 pm »

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.
Logged

maime

  • Coppermine newbie
  • Offline Offline
  • Posts: 7
Re: [MOD] Sub-themes
« Reply #2 on: October 24, 2005, 12:27:30 am »

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

Pascal YAP

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: fr
  • Offline Offline
  • Gender: Male
  • Posts: 13833
  • Hello World :-)
    • CPG 1.5.x ExperiMental website
Re: [MOD] Sub-themes
« Reply #3 on: October 25, 2005, 09:02:39 am »

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
Logged

Pascal YAP

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: fr
  • Offline Offline
  • Gender: Male
  • Posts: 13833
  • Hello World :-)
    • CPG 1.5.x ExperiMental website
Re: [MOD] Sub-themes
« Reply #4 on: October 25, 2005, 10:46:27 am »

« Last Edit: October 25, 2005, 02:17:17 pm by PYAP »
Logged

Woofy

  • Coppermine newbie
  • Offline Offline
  • Posts: 3
Re: [MOD] Sub-themes
« Reply #5 on: October 25, 2005, 03:38:52 pm »

Hi there !

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

Titooy

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Posts: 736
    • under construction...
Re: [MOD] Sub-themes
« Reply #6 on: October 25, 2005, 06:06:18 pm »

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

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
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: [MOD] Sub-themes
« Reply #7 on: October 26, 2005, 12:19:43 am »

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

Blueiris

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Female
  • Posts: 170
  • Horse poor!
    • Saddlebred World Gallery
Re: [MOD] Sub-themes
« Reply #8 on: December 06, 2005, 05:19:19 pm »

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.
Logged
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

  • Coppermine newbie
  • Offline Offline
  • Posts: 16
Help with Sub-Themes
« Reply #9 on: March 21, 2007, 10:00:36 pm »

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?
Logged

jesusarmy

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 34
Re: Help with Sub-Themes
« Reply #10 on: December 19, 2007, 02:00:31 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
Code: [Select]
if (!isset($_POST['parent']) || !isset($_POST['name']) || !isset($_POST['description']))
I suggest you just change it to
Code: [Select]
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)


Logged

jesusarmy

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 34
Re: [MOD] Sub-themes in Meta-albums
« Reply #11 on: January 12, 2008, 11:15:32 am »

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)
Code: [Select]
// Looks if there's a sub-theme for that category
if (!empty($_GET['cat'])) {

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

And find:
Code: [Select]
// 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:
Code: [Select]
// 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.
Logged

saith

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 37
Re: [MOD] Sub-themes
« Reply #12 on: January 23, 2008, 07:25:54 pm »

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 ?
Logged

Nibbler

  • Guest
Re: [MOD] Sub-themes
« Reply #13 on: January 24, 2008, 10:42:45 am »

Use includes.
Logged

Oingo

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: [MOD] Sub-themes
« Reply #14 on: March 27, 2008, 06:57:55 am »

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
Logged

Nibbler

  • Guest
Re: [MOD] Sub-themes
« Reply #15 on: March 27, 2008, 01:41:19 pm »

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.
Logged

ff

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 108
Re: [MOD] Sub-themes
« Reply #16 on: December 18, 2008, 07:02:20 pm »

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?
Logged
Pages: [1]   Go Up
 

Page created in 0.052 seconds with 20 queries.