Advanced search  

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]

Pages: [1]   Go Down

Author Topic: Random gallery description  (Read 2927 times)

0 Members and 1 Guest are viewing this topic.

McKenzie

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 129
    • My car gallery
Random gallery description
« on: September 24, 2008, 02:02:05 am »

Hello,

I will have different random gallery descriptions. Where must I insert this php-code http://www.totallyphp.co.uk/scripts/random_quote.htm ? In sample theme.php I didn't find something. What must I modify to insert this script in place of the "{GAL_DESCRIPTION}".

Thanx
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Random gallery description
« Reply #1 on: September 24, 2008, 08:40:42 am »

Take a look at the section where the placeholder token {GAL_DESCRIPTION} is being populated - search themes/sample/theme.php for that string. You'll only find one line:
Code: [Select]
'{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],, so you'll have to copy the section
Code: [Select]
function pageheader($section, $meta = '')
{
    global $CONFIG, $THEME_DIR;
    global $template_header, $lang_charset, $lang_text_dir;

    $custom_header = cpg_get_custom_include($CONFIG['custom_header_path']);

        $charset = ($CONFIG['charset'] == 'language file') ? $lang_charset : $CONFIG['charset'];

    header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
        header("Content-Type: text/html; charset=$charset");
    user_save_profile();

    $template_vars = array('{LANG_DIR}' => $lang_text_dir,
        '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . strip_tags(bb_decode($section)),
        '{CHARSET}' => $charset,
        '{META}' => $meta,
        '{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,
        );

    echo template_eval($template_header, $template_vars);
}
from themes/sample/theme.php into a new line before
Code: [Select]
?>of the file themes/yourtheme/theme.php (if your custom theme.php doesn't already contain a definition for that function).

This being done, just look at the definition for the placeholder definition once more: it is being populated by a config var. To see this replaced, just re-define the token. Edit the stuff you just pasted in like this:
Code: [Select]
// Function for writing a pageheader
function pageheader($section, $meta = '')
{
    global $CONFIG, $THEME_DIR;
    global $template_header, $lang_charset, $lang_text_dir;

    $custom_header = cpg_get_custom_include($CONFIG['custom_header_path']);

        $charset = ($CONFIG['charset'] == 'language file') ? $lang_charset : $CONFIG['charset'];

    header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
        header("Content-Type: text/html; charset=$charset");
    user_save_profile();
   
    // Custom code starts here, taken from http://www.totallyphp.co.uk/scripts/random_quote.htm
    // and modified slightly
$quotes[] = "This is a quote";
$quotes[] = "This is another";
$quotes[] = "quote 3";
$quotes[] = "quote 4";
$quotes[] = "quote 5";
$quotes[] = "quote 6";
srand ((double) microtime() * 1000000);
$randomquote = rand(0,count($quotes)-1);
   

    $template_vars = array('{LANG_DIR}' => $lang_text_dir,
        '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . strip_tags(bb_decode($section)),
        '{CHARSET}' => $charset,
        '{META}' => $meta,
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $quotes[$randomquote],
        '{SYS_MENU}' => theme_main_menu('sys_menu'),
        '{SUB_MENU}' => theme_main_menu('sub_menu'),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{CUSTOM_HEADER}' => $custom_header,
        );

    echo template_eval($template_header, $template_vars);
}
You'll notice that we don't just echo (i.e. print) the random quote, but populate the placeholder token with the content of the array.

HTH
Logged
Pages: [1]   Go Up
 

Page created in 0.02 seconds with 19 queries.