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: How to create a custom Token for Coppermine  (Read 5713 times)

0 Members and 1 Guest are viewing this topic.

AzorMachine

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
How to create a custom Token for Coppermine
« on: September 07, 2011, 04:22:42 pm »

I've searched in the docs, and as I didn't found an entry about that, I'm here asking.
Is there a simple way to create custom tokens, to populate my template.html?
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: How to create a custom Token for Coppermine
« Reply #1 on: September 07, 2011, 05:10:46 pm »

All tokens you place before the {GALLERY} token need to be replaced within the function pageheader, all that are placed after that token within the pagefooter function.
Logged

AzorMachine

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
Re: How to create a custom Token for Coppermine
« Reply #2 on: September 07, 2011, 05:49:42 pm »

That means, "Use {CUSTOM_FOOTER} and {CUSTOM_HEADER}" ?
I was going to use both, But I need one more field to display php code.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: How to create a custom Token for Coppermine
« Reply #3 on: September 07, 2011, 06:52:47 pm »

No. Just add the tokens where you need it and fill it with content in the mentioned functions in theme.php. Of course you can use the custom header/footer feature to include your PHP code.
Logged

AzorMachine

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
Re: Re: How to create a custom Token for Coppermine
« Reply #4 on: September 07, 2011, 07:12:53 pm »

No. Just add the tokens where you need it and fill it with content in the mentioned functions in theme.php. Of course you can use the custom header/footer feature to include your PHP code.

And how would stay the code in theme.php, if I want a token to show the statistics of my gallery? (19 files in 6 albums and 2 categories with 0 comments viewed 466,770 times) (But whithout the comments number.)
Sorry for the inconvenience, but that is an important code to release my gallery, today.
Thanks.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: How to create a custom Token for Coppermine
« Reply #5 on: September 07, 2011, 07:26:34 pm »

Please have a look at the files template.html and theme.php of the sample theme to understand how it works. All tokens above the {GALLERY} token are replaced within the function pageheader, all tokens below the {GALLERY} token are replaced within the function pagefooter. If you understand that example it should be quite easy to add new tokens in template.html.


Please explain exactly what you try to accomplish if you need specific support.
Logged

AzorMachine

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
Re: How to create a custom Token for Coppermine
« Reply #6 on: September 07, 2011, 07:34:27 pm »

Quote
Please explain exactly what you try to accomplish if you need specific support.

I wanna that one of the tabs in my gallery, show the statistics of the gallery, without the comments numbers, like :

Quote
19 files in 6 albums and 2 categories viewed 466,770 times
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: How to create a custom Token for Coppermine
« Reply #7 on: September 07, 2011, 07:45:56 pm »

Sorry, but, which tabs? Please post a link to your gallery and a link to that 'tab'.
Logged

AzorMachine

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
Re: How to create a custom Token for Coppermine
« Reply #8 on: September 07, 2011, 07:54:38 pm »

The table that says Estatísticas in the footer area.

www.reinorpg.com/resources
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: How to create a custom Token for Coppermine
« Reply #9 on: September 07, 2011, 08:04:18 pm »

Replace that word with a token of your choice (e.g. {STATISTICS}) and extend the $template_vars array in the pagefooter function. If that function doesn't exist in your theme.php file, just copy it from the sample theme.
Logged

AzorMachine

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
Re: Re: How to create a custom Token for Coppermine
« Reply #10 on: September 07, 2011, 08:15:07 pm »

Replace that word with a token of your choice (e.g. {STATISTICS}) and extend the $template_vars array in the pagefooter function. If that function doesn't exist in your theme.php file, just copy it from the sample theme.

Done.
Now the function has this line :

Code: [Select]
'{STATISTICS}' => blank,

But what code should be in the 'blank', to show the statistics, without the comments?
Logged

AzorMachine

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
Re: How to create a custom Token for Coppermine
« Reply #11 on: September 07, 2011, 08:18:01 pm »

Ok,
Code: [Select]
$statisticsright?

But how to remove the comments from it?
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: How to create a custom Token for Coppermine
« Reply #12 on: September 07, 2011, 08:19:35 pm »

You have to grab the information from the database yourself and then build the string.
Logged

AzorMachine

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
Re: How to create a custom Token for Coppermine
« Reply #13 on: September 07, 2011, 08:44:29 pm »

Added this to my theme.php :

Code: [Select]
/******************************************************************************
** Section <<<pagefooter>>> - START
******************************************************************************/
// Function for writing a pagefooter
function pagefooter()
{
    //global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_SERVER_VARS;
    global $USER, $USER_DATA, $CONFIG, $time_start, $query_stats, $queries;
    global $template_footer;

    $custom_footer = cpg_get_custom_include($CONFIG['custom_footer_path']);

    if ($CONFIG['debug_mode']==1 || ($CONFIG['debug_mode']==2 && GALLERY_ADMIN_MODE)) {
        cpg_debug_output();
    }

    $template_vars = array(
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
        '{SYS_MENU}' => theme_main_menu('sys_menu'),
        '{SUB_MENU}' => theme_main_menu('sub_menu'),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{CUSTOM_HEADER}' => $custom_header,
        '{STATISTICS2}' => $statistics,
        '{JAVASCRIPT}' => theme_javascript_head(),
        '{CUSTOM_FOOTER}' => $custom_footer,
        '{VANITY}' => (defined('THEME_IS_XHTML10_TRANSITIONAL')) ? theme_vanity() : '',
        '{CREDITS}' => theme_credits(),
    );

    echo template_eval($template_footer, $template_vars);
}
/******************************************************************************
** Section <<<pagefooter>>> - END
******************************************************************************/

And added the {STATISTICS2} token to my template.html, But nothing is shown.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: How to create a custom Token for Coppermine
« Reply #14 on: September 07, 2011, 09:28:28 pm »

As I said, the variable $statistics doesn't contain anything at this place. That's why you need to fill it yourself with information from the database. I'm currently too short of time to create a working solution for you.
Logged

AzorMachine

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
Re: Re: How to create a custom Token for Coppermine
« Reply #15 on: September 08, 2011, 03:19:37 pm »

As I said, the variable $statistics doesn't contain anything at this place. That's why you need to fill it yourself with information from the database. I'm currently too short of time to create a working solution for you.

When you have time, please take a time at this. It's kinda importante for my gallery, and It's something I can't make by myself.

Best Regards.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: How to create a custom Token for Coppermine
« Reply #16 on: September 09, 2011, 12:13:02 pm »

Use this function:
Code: [Select]
/******************************************************************************
** Section <<<pagefooter>>> - START
******************************************************************************/
// Function for writing a pagefooter
function pagefooter()
{
    //global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_SERVER_VARS;
    global $USER, $USER_DATA, $CONFIG, $time_start, $query_stats, $queries;
    global $template_footer;

    $custom_footer = cpg_get_custom_include($CONFIG['custom_footer_path']);

    if ($CONFIG['debug_mode']==1 || ($CONFIG['debug_mode']==2 && GALLERY_ADMIN_MODE)) {
        cpg_debug_output();
    }

    $files = mysql_result(cpg_db_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']}"), 0);
    $albums = mysql_result(cpg_db_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_ALBUMS']}"), 0);
    $categories = mysql_result(cpg_db_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_CATEGORIES']}"), 0);
    $views = mysql_result(cpg_db_query("SELECT SUM(hits) FROM {$CONFIG['TABLE_PICTURES']}"), 0);
    $statistics = "$files files in $albums albums and $categories categories viewed $views times";
   
    $template_vars = array(
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
        '{SYS_MENU}' => theme_main_menu('sys_menu'),
        '{SUB_MENU}' => theme_main_menu('sub_menu'),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{CUSTOM_HEADER}' => $custom_header,
        '{STATISTICS2}' => $statistics,
        '{JAVASCRIPT}' => theme_javascript_head(),
        '{CUSTOM_FOOTER}' => $custom_footer,
        '{VANITY}' => (defined('THEME_IS_XHTML10_TRANSITIONAL')) ? theme_vanity() : '',
        '{CREDITS}' => theme_credits(),
    );

    echo template_eval($template_footer, $template_vars);
}
/******************************************************************************
** Section <<<pagefooter>>> - END
******************************************************************************/
Logged
Pages: [1]   Go Up
 

Page created in 0.026 seconds with 19 queries.