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: Using a keyword to manipulate theme  (Read 3181 times)

0 Members and 1 Guest are viewing this topic.

Caprisorn20

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Using a keyword to manipulate theme
« on: November 12, 2012, 02:15:21 pm »

Is there a way to set a variable when keywords are read so that if a particular keyword is used some text is shown/not shown on the display page? Reason I ask is that I'd like to use a particular keyword and if it is present to not show Google Adsense on that page because the image may not adhere to the T&Cs.

On displayimage.php the keyword can be found within:
Code: [Select]
    if ($CURRENT_PIC_DATA['keywords'] != '') {
        $keyword_links = array();
        foreach (explode($CONFIG['keyword_separator'], html_entity_decode($CURRENT_PIC_DATA['keywords'])) as $keyword) {
            $keyword_links[] = '<a href="thumbnails.php?album=search&amp;keywords=on&amp;search=' . urlencode($keyword) . '">' . $keyword . '</a>';
            if($keyword=='blah') {$ADSENSE='off';}
        }
        $info[$lang_common['keywords']] = '<span class="alblink">' . implode(' / ', $keyword_links) . '</span>';
    }

I know  if($keyword=='blah') {$ADSENSE='off';} is not correct but what is the best way to make a global variable that can drive this ll the way through to theme.php?

Thanks in advance.
Logged

Jeff Bailey

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 1322
  • Fishing relaxes me.
    • Bailey Family Co.
Re: Using a keyword to manipulate theme
« Reply #1 on: November 12, 2012, 10:56:43 pm »

It's recommended that you edit theme files instead of core files so:

In your custom theme.php
you can add
Code: [Select]
/******************************************************************************
** Section <<<theme_display_image>>> - START
******************************************************************************/
function theme_display_image($nav_menu, $picture, $votes, $pic_info, $comments, $film_strip)
{
    global $CONFIG, $LINEBREAK, $CURRENT_PIC_DATA;

    $superCage = Inspekt::makeSuperCage();

    $width = $CONFIG['picture_table_width'];

    echo '<a name="top_display_media"></a>'; // set the navbar-anchor
    starttable();
    echo $nav_menu;
    endtable();

    starttable();
    echo $picture;
    endtable();

// start adsense
$keywordlist = explode($CONFIG['keyword_separator'],$CURRENT_PIC_DATA['keywords']);
if (!in_array('triggerword', $keywordlist)) {
echo 'code to display adsense';
}
//end adsense

    if ($CONFIG['display_film_strip'] == 1) {
        echo $film_strip;
    }


    echo $votes;

    $picinfo = $superCage->cookie->keyExists('picinfo') ? $superCage->cookie->getAlpha('picinfo') : ($CONFIG['display_pic_info'] ? 'block' : 'none');
    echo $LINEBREAK . '<div id="picinfo" style="display: '.$picinfo.';">' . $LINEBREAK;
    starttable();
    echo $pic_info;
    endtable();
    echo '</div>' . $LINEBREAK;

    echo '<a name="comments_top"></a>';
    echo '<div id="comments">' . $LINEBREAK;
        echo $comments;
        echo '</div>' . $LINEBREAK;

}
/******************************************************************************
** Section <<<theme_display_image>>> - END
******************************************************************************/
This will display your ad under the image description on displayimage.php

Code: [Select]
// start adsense
$keywordlist = explode($CONFIG['keyword_separator'],$CURRENT_PIC_DATA['keywords']);
if (!in_array('triggerword', $keywordlist)) {
echo 'code to display adsense'
}
//end adsense
Is the code I added. edit triggerword to match the keyword and change code to display adsense to your adsense code.

Of Course you can move the whole adsense block to wherever you want. If your adsense code is in a different part of your page, you'll have to find the proper function (or ask) and add the code and make $CURRENT_PIC_DATA a global variable.
« Last Edit: November 14, 2012, 07:18:03 am by Jeff Bailey »
Logged
Thinking is the hardest work there is, which is probably the reason why so few engage in it. - Henry Ford
Pages: [1]   Go Up
 

Page created in 0.019 seconds with 19 queries.