How to disable a script if user is logged in. How to disable a script if user is logged in.
 

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 disable a script if user is logged in.

Started by ryandavis, May 23, 2008, 08:27:49 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ryandavis

To Whom it May Concern:

Does anyone know (or has it been discussed before) on how to disable a script by checking if the user is a member of a certain group in coppermine? I am running the latest version. What i have done is on the main template and displayimage.php file I have added a right click disable message. That way most people browsing the site will not be able to save the images to their computer. I realize that if they want it bad enough they can get it, but I am just trying to keep the majority of browsers from being able to download my images.

What I am wanting to do is to make it where if the user is just an unregistered (Guest) browsing the site, the right click disable script will be turned on. In contrast, if the user is a member of the registered users group (or a custom group that I would make), I would want the script to be disabled in both the main template and the displayimage.php files so that that user could right click and save the image to their computer.

Does anyone know how to do this? Any help would be appricated. I know it would probably be simple coding, I just cannot code. Please let me know if anyone would have any suggestions.

Thanks for your help in advance!

-Ryan-

Joachim Müller

Quote from: ryandavis on May 23, 2008, 08:27:49 AM
What i have done is on the main template and displayimage.php file I have added a right click disable message.
Add your no-right-click script to your theme, that should be all you need. Add it to the pageheader function definition in theme.php and use an if/then construct there to make it show only for particular groups. For details, post details.

Joachim

P.S. We're not fond of no-right-click scripts in the first place, as they are silly and will only keep complete newbies away from stealing your pics.

rdavis

Thanks for the reply. Here are some details. I am not a coder at all so any help would be awesome.

I have added the script below between my <head></head> tags in my current theme template.html file and at the end of my displayimage.php file in between two <head></head> tags that I inserted. Everything works great right now, I just want to be able to disable it when a certain group member logs in.


<script language=JavaScript>
var message="HERE IS WHERE MY MESSAGE TEXT IS";

function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")

// -->
</script>


I am not a coder at all and do not know php, so would you be able to tell me the exact if/then statement and how to put it in my theme.php file?

This is what my theme.php looks like:


<?php
define
('THEME_HAS_RATING_GRAPHICS'1);

$template_sys_menu_spacer ='<img src="themes/rdavis_silver/images/line_black.gif" width="9" height="11" border="0" alt="" />';


function 
theme_display_film_strip(&$thumb_list$nbThumb$album_name$aid$cat$pos$sort_options$mode 'thumb')
{
    global 
$CONFIG$THEME_DIR;
    global 
$template_film_strip$lang_film_strip;

    static 
$template '';
    static 
$thumb_cell '';
    static 
$empty_cell '';
    static 
$spacer '';

    if ((!
$template)) {
        
$template $template_film_strip;
        
$thumb_cell template_extract_block($template'thumb_cell');
        
$empty_cell template_extract_block($template'empty_cell');
    }

    
$cat_link is_numeric($aid) ? '' '&amp;cat=' $cat;

    
$thumbcols $CONFIG['thumbcols'];
    
$cell_width ceil(100 $CONFIG['max_film_strip_items']) . '%';

    
$i 0;
    
$thumb_strip '';
    foreach(
$thumb_list as $thumb) {

        
$new_size 65;
        
preg_match('/(?<=width=")[0-9]*/',$thumb['image'],$matches,PREG_OFFSET_CAPTURE);
        
$srcWidth=$matches[0][0];
        
preg_match('/(?<=height=")[0-9]*/',$thumb['image'],$matches,PREG_OFFSET_CAPTURE);
        
$srcHeight=$matches[0][0];
        
$ratio max($srcWidth$srcHeight) / $new_size;
        
$ratio max($ratio1.0);
        
$destWidth = (int)($srcWidth $ratio);
        
$destHeight = (int)($srcHeight $ratio);
        
$thumb['image']=preg_replace('/width="[^"]*"/','width="'.$destWidth.'"',$thumb['image']);
        
$thumb['image']=preg_replace('/height="[^"]*"/','height="'.$destHeight.'"',$thumb['image']);
        
$i++;
        if (
$mode == 'thumb') {
            
$params = array('{CELL_WIDTH}' => $cell_width,
                
'{LINK_TGT}' => "displayimage.php?album=$aid$cat_link&amp;pos={$thumb['pos']}",
                
'{THUMB}' => $thumb['image'],
                
'{CAPTION}' => $thumb['caption'],
                
'{ADMIN_MENU}' => ''
                
);
        } else {
            
$params = array('{CELL_WIDTH}' => $cell_width,
                
'{LINK_TGT}' => "index.php?cat={$thumb['cat']}",
                
'{THUMB}' => $thumb['image'],
                
'{CAPTION}' => '',
                
'{ADMIN_MENU}' => ''
                
);
        }
        
$thumb_strip .= template_eval($thumb_cell$params);
    }

    if (
defined('THEME_HAS_FILM_STRIP_GRAPHICS')) {
        
$tile1 $THEME_DIR 'images/tile1.gif';
        
$tile2 $THEME_DIR 'images/tile2.gif';
    } elseif (
defined('THEME_HAS_FILM_STRIP_GRAPHIC')) {
        
$tile1=$tile2=$THEME_DIR 'images/tile.gif';
    } else {
        
$tile1=$tile2'images/tile.gif';
    }

    
$params = array('{THUMB_STRIP}' => $thumb_strip,
        
'{COLS}' => $i,
        
'{TILE1}' => $tile1,
        
'{TILE2}' => $tile2,
        );

    
ob_start();
    
starttable($CONFIG['picture_table_width']);
    echo 
template_eval($template$params);
    
endtable();
    
$film_strip ob_get_contents();
    
ob_end_clean();

    return 
$film_strip;
}
?>



I will just use the registered users group in coppermine to be the group that has the script disabled.

Please let me how what to do about what code to insert and where. Thanks for all your help!

-Ryan-