Topic: Adding to the warning mod.

Is it possible in the code below to add more than one filename to search for. In this case it only looks for install_mod.php and I would like it to look for 2 others, so 3 in total.

    // START SUBST - <pun_mod>
        ## Function
    function regExpFile($regExp, $dir, $regType='P', $case='') {
    # Two parameters accepted by $regType are E for ereg* functions
    # and P for preg* functions
    $func = ( $regType == 'P' ) ? 'preg_match' : 'ereg' . $case;
    $regExp = ( $regType == 'P' ) ? $regExp . $case : $regExp;
    # Note, technically anything other than P will use ereg* functions;
    # however, you can specify whether to use ereg or eregi by
    # declaring $case as "i" to use eregi rather than ereg
    
    $open = opendir($dir);
    while( ($file = readdir($open)) !== false ) {
    if ( $func($regExp, $file) ) {
    return true;
    }
    } // End while
    return false;
    } // End function
    
    
    $reff_function = function_exists('preg_match') ? 'P' : 'E';
    if(regExpFile("#install_mod.*#i", './') && ($pun_user['g_id'] == PUN_ADMIN))
        {
        $replace = '<div id="announce" class="block">
        <h2><span class="mod_warn">Attention - There is currently an <font class="mod_warn_text">install_mod.php</font> file located in your root folder!</span></h2>
        <div class="box">
            <div class="inbox">
                <div>There is a modification ready to be installed.<br /><a href="'.PUN_ROOT.'install_mod.php" target="_blank">Install the modification!</a></div>
            </div>
        </div>
    </div>';
        
        $tpl_main = str_replace('<pun_mod>', $replace, $tpl_main);
        }
    else
        {
        $tpl_main = str_replace('<pun_mod>', '', $tpl_main);
        }
    // END SUBST - <pun_mod>

Re: Adding to the warning mod.

Change

    if(regExpFile("#install_mod.*#i", './') && ($pun_user['g_id'] == PUN_ADMIN))

to

    if(regExpFile("#install_mod.*#i", './') || regExpFile("#file_2.*#i", './' || regExpFile("#file3.*#i", './')) && ($pun_user['g_id'] == PUN_ADMIN))

Also, it' sad to see that I wrote code so badly ages ago =P

Re: Adding to the warning mod.

I get the following error:

Warning: opendir(1) [function.opendir]: failed to open dir: Invalid argument in c:\punbb\header.php on line 268

Warning: readdir(): supplied argument is not a valid Directory resource in c:\punbb\header.php on line 269

Re: Adding to the warning mod.

Any idea why this doesn't work...anyone?

5

Re: Adding to the warning mod.

Did it work okay before the alteration?

Re: Adding to the warning mod.

yes, but now it doesnt'. I just wanted to add 2 more extra files to the code.

Re: Adding to the warning mod.

Can you fix it for me Matt?

8

Re: Adding to the warning mod.

    if((regExpFile("#install_mod.*#i", './') || regExpFile("#file_2.*#i", './') || regExpFile("#file3.*#i", './')) && $pun_user['g_id'] == PUN_ADMIN)

Try that.

Re: Adding to the warning mod.

Neh, doesn't work.

10

Re: Adding to the warning mod.

bingiman wrote:

Neh, doesn't work.

In what way? Same error as before?

Re: Adding to the warning mod.

Well...I have 3 files to test. install_mod.php, install.php and install_attach_mod.php - If i remove those files it still tells me that they are in the folder, and they aren't.

12

Re: Adding to the warning mod.

Must admit, I've no idea. (Don't tell Elbecko, but I can hardly make head nor tail of that code). big_smile

Re: Adding to the warning mod.

ok, no problem Matt.