How to create a custom Token for Coppermine How to create a custom Token for Coppermine
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

How to create a custom Token for Coppermine

Started by AzorMachine, September 07, 2011, 04:22:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AzorMachine

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?

Αndré

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.

AzorMachine

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

Αndré

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.

AzorMachine

Quote from: Αndré 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.

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.

Αndré

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.

AzorMachine

QuotePlease 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 :

Quote19 files in 6 albums and 2 categories viewed 466,770 times

Αndré

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

AzorMachine

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

www.reinorpg.com/resources

Αndré

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.

AzorMachine

Quote from: Αndré 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.

Done.
Now the function has this line :

'{STATISTICS}' => blank,


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

AzorMachine

Ok,
$statistics
right?

But how to remove the comments from it?

Αndré

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

AzorMachine

Added this to my theme.php :

/******************************************************************************
** 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.

Αndré

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.

AzorMachine

Quote from: Αndré 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.

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.

Αndré

Use this function:
/******************************************************************************
** 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
******************************************************************************/