Not the best upload script I've ever seen, but this'll make it fit the punbb theme:

<?php

define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';

if ($pun_user['g_id'] > PUN_MOD) message($lang_common['No view']);

$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.'Upload a smiley';

require PUN_ROOT.'header.php';

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//   You may change maxsize, and allowable upload file types.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//Mmaximum file size. You may increase or decrease.
$MAX_SIZE = 200000;
                            
//Allowable file Mime Types. Add more mime types if you want
$FILE_MIMES = array('image/jpeg','image/jpg','image/gif'
                   ,'image/png');

//Allowable file ext. names. you may add more extension names.            
$FILE_EXTS  = array('.jpg','.png','.gif'); 

//Allow file delete? no, if only allow upload only
$DELETABLE  = false;                               


//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//   Do not touch the below if you are not confident.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/************************************************************
 *     Setup variables
 ************************************************************/
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this =  "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

$upload_dir = "img/smilies/";
$upload_url = $url_dir."/img/smilies/";
$message ="";

/************************************************************
 *     Create Upload Directory
 ************************************************************/
if (!is_dir("img/smilies")) {
  if (!mkdir($upload_dir))
      die ("upload_files directory doesn't exist and creation failed");
  if (!chmod($upload_dir,0755))
      die ("change permission to 755 failed.");
}

/************************************************************
 *     Process User's Request
 ************************************************************/
if (isset($_FILES['userfile'])) {
  $resource = fopen("log.txt","a");
  fwrite($resource,date("Ymd h:i:s")."UPLOAD - $_SERVER[REMOTE_ADDR]"
            .$_FILES['userfile']['name']." "
            .$_FILES['userfile']['type']."\n");
  fclose($resource);

    $file_type = $_FILES['userfile']['type']; 
  $file_name = $_FILES['userfile']['name'];
  $file_ext = strtolower(substr($file_name,strrpos($file_name,".")));

  //File Size Check
  if ( $_FILES['userfile']['size'] > $MAX_SIZE) 
     $message = "The file size is over 200k.";
  //File Type/Extension Check
  else if (!in_array($file_type, $FILE_MIMES) 
          && !in_array($file_ext, $FILE_EXTS) )
     $message = "Sorry, $file_name($file_type) is not allowed to be uploaded.";
  else
     $message = do_upload($upload_dir, $upload_url);

}

function do_upload($upload_dir, $upload_url) {
    $message = 'File uploaded successfully';
    $temp_name = $_FILES['userfile']['tmp_name'];
    $file_name = $_FILES['userfile']['name']; 
  $file_name = str_replace("\\","",$file_name);
  $file_name = str_replace("'","",$file_name);
    $file_path = $upload_dir.$file_name;

    //File Name Check
  if ( $file_name =="") { 
      $message = "Invalid File Name Specified";
      return $message;
  }

  $result  =  move_uploaded_file($temp_name, $file_path);
  if (!chmod($file_path,0755))
       $message = "change permission to 755 failed.";
  else
    $message = ($result)?"$file_name uploaded successfully." :
               "Somthing is wrong with uploading a file.";
  return $message;
}

?>
<div class="blockform">
    <h2><span>Upload</span></h2>
    <div class="box">
        <form action=<?= $url_this ?> name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
            <div class="inform">
                <fieldset>
                    <legend>Upload a smiley</legend>
                    <div class="infldset">
                        <input type="hidden" name="saction" value="search" />
                        <label class="conl">Upload file<br /><input type="file" id="userfile" name="userfile"><br /></label>
                        <p class="clearb">Size limit is 200k.  Files must be .gif, .jpg, or .png.  E-mail or post to let me know you upped something and I'll activate it. 
   Name the file the exact same thing you'd like the code to be. Example:  if you want the smiley code to be :fart:, name the file fart.gif.</p>
                        <p><font color="red"><?=$message?></font></p>
                    </div>
                </fieldset>
                <p><input type="submit" name="upload" value="Upload"/></p>
                <p><a href="http://www.pokerpeeps.net/">Return to the Forum</a></p>
            </div>
        </form>
    </div>
</div>
<?php

require PUN_ROOT.'footer.php';

52

(10 replies, posted in Programming)

GD is bundled with PHP, all you need to do is turn it on. How you do this (and how you would install IM) depends largely on your operating system. What OS are you using ?

Maybe something like this. It's a little limited atm, but it does avoid any punbb modding.

To use htaccess passwords essentially all you need to do is  replace your check_cookie() function in include/functions.php with this:

//
// Cookie stuff!
//
function check_cookie(&$pun_user)
{
    global $db, $pun_config;

    $username = (isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '');
    
    if (!$username) die('Authentication failure');

    $now = time();

    // Check if there's a user with the user ID and password hash from the cookie
    $result = $db->query('SELECT u.*, g.*, o.logged, o.idle FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '.$db->prefix.'online AS o ON o.user_id=u.id WHERE u.username=\''.$username.'\'') or error('Unable to fetch user information', __FILE__, __LINE__, $db->error());
    $pun_user = $db->fetch_assoc($result);

    // Set a default language if the user selected language no longer exists
    if (!@file_exists(PUN_ROOT.'lang/'.$pun_user['language']))
        $pun_user['language'] = $pun_config['o_default_lang'];

    // Set a default style if the user selected style no longer exists
    if (!@file_exists(PUN_ROOT.'style/'.$pun_user['style'].'.css'))
        $pun_user['style'] = $pun_config['o_default_style'];

    if (!$pun_user['disp_topics'])
        $pun_user['disp_topics'] = $pun_config['o_disp_topics_default'];
    if (!$pun_user['disp_posts'])
        $pun_user['disp_posts'] = $pun_config['o_disp_posts_default'];

    // Define this if you want this visit to affect the online list and the users last visit data
    if (!defined('PUN_QUIET_VISIT'))
    {
        // Update the online list
        if (!$pun_user['logged'])
            $db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$db->escape($pun_user['username']).'\', '.$now.')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error());
        else
        {
            // Special case: We've timed out, but no other user has browsed the forums since we timed out
            if ($pun_user['logged'] < ($now-$pun_config['o_timeout_visit']))
            {
                $db->query('UPDATE '.$db->prefix.'users SET last_visit='.$pun_user['logged'].' WHERE id='.$pun_user['id']) or error('Unable to update user visit data', __FILE__, __LINE__, $db->error());
                $pun_user['last_visit'] = $pun_user['logged'];
            }

            $idle_sql = ($pun_user['idle'] == '1') ? ', idle=0' : '';
            $db->query('UPDATE '.$db->prefix.'online SET logged='.$now.$idle_sql.' WHERE user_id='.$pun_user['id']) or error('Unable to update online list', __FILE__, __LINE__, $db->error());
        }
    }
    $pun_user['is_guest'] = false;
}

And then setup password protection on your punbb folder to use the same passwd file as your members area. If you get 'Authentication failure' then you haven't setup the protection properly.

55

(8 replies, posted in Programming)

<script type="text/javascript" language="javascript">
function togVis(id) {
    var list = id+"List";
    list = document.getElementById(list);
    var button = id+"Button";
    button = document.getElementById(button);
    if(list.style.display == "block") {
        list.style.display = "none";
        button.src = "images/nolines_plus.gif";
    } else {
        list.style.display = "block";
        button.src = "images/nolines_minus.gif";
    }
}
</script>
<style type="text/css">
img {border: 0; vertical-align: middle}
li {list-style: none outside}
ul {display: none; padding-left: 20; padding-top: 0; margin: 0}
body {font-family : Verdana, Arial, Helvetica, sans-serif; font-size: 12px}
</style>
<?

$tree = dir_parse('admin');
maketree($tree);

function dir_parse($path)
{
    if ($dir = opendir($path))
    {
        $thisdir = array();
        while (false !== ($file = readdir($dir)))
        {
            if  ($file != '.' && $file != '..')
            {
                if (is_dir("$path/$file"))
                {
                    $thisdir[$file] = dir_parse("$path/$file");
                } else {
                    $thisdir[] = $file;
                }
            }
        }
        asort($thisdir, SORT_STRING);
        return $thisdir;
    }
}

function maketree($tree)
{
    static $i = 0;
    
    foreach ($tree as $path=>$file){
        if (is_array($file)){
            echo "<li><a href=\"#\" onclick=\"togVis('$i'); return false;\"><img src=\"images/nolines_plus.gif\" alt=\"+\" id=\"{$i}Button\" /></a>$path";
            echo "<ul id=\"{$i}List\">";
            $i++;
            maketree($file);
            echo "</ul></li>";
        } else {
            echo "<li><img src=\"images/page.gif\" alt=\"$file\" />$file</li>";
        }
    }
}
?>

That should make a tree from a directory listing smile

Be more specific about versions please, the 1.1.5 punbb bridge that came with the 1.3.2 cpg package wont work with a 1.2 install of punbb.

I think the integration does all you can reasonably expect it to do without making any changes to the forum you bridge it to. As I said, 1.4 is xhtml and css compliant and has a new bridging system. The theme system we inherited from the original creator of coppermine, and we are doing the best we can with it (for the 1.x series). 1.4 is now under feature freeze and a beta will be available within a few weeks I should think.

Rod wrote:

for me, all the galleries are bad in the sense where you want to see a pic, you have to change a page ... DOM changes this !!! and it's really good for galleries, for users, and .. THE SERVERS !

We know !! smile


CPG 1.4 is valid XHTML 1.0 Transitional.

Best bet is to wait for the upcomming 1.4 release of Coppermine, it supports punbb 1.2 bridging out-of-the-box. The bridging system is all changed for 1.4 so I can't simply backport the bridge file for 1.3.2. You can grab it from sf cvs ('devel' branch) now if you are comfortable using unsupported betas.

Enable debug mode and post the full sql error message you get and I'll have a look at it over the weekend.

61

(2 replies, posted in PunBB 1.2 discussion)

All you need is

define('PUN_ROOT', 'punbb/');
require PUN_ROOT . 'include/common.php';

and that gives you your $pun_user, $pun_config and the database object $db among other things. Change the path as appropriate.

You mean accounts that are over a certain number of days old, not users I suppose smile

63

(7 replies, posted in PunBB 1.2 bug reports)

Fix confirmed.

64

(3 replies, posted in PunBB 1.2 troubleshooting)

Try installing phpmyadmin, that should help you setup a new database.

You can add this in pretty easily, into viewtopic.php, change

$username = '<a href="profile.php?id='.$cur_post['poster_id'].'">'.pun_htmlspecialchars($cur_post['username']).'</a>';

to

    $group_colours = array(
        1 => 'red',
        2 => 'blue',
        4 => 'green'
    );
    
        $username = '<a href="profile.php?id='.$cur_post['poster_id'].'"><span style="color:'.$group_colours[$pun_user['group_id']].'">'.pun_htmlspecialchars($cur_post['username']).'</span></a>';

and set the colours you like in the array.

66

(7 replies, posted in PunBB 1.2 bug reports)

Hi,

"Use AND, OR and NOT to refine your search."

Only works if you use a lower case and, not if you use a capitalised AND. This is a little misleading, given the search instructions above.

It uses a <li> tag now, you can remove that simply by searching extern.php for <li> and </li> and changing them to something you like better

Line 78 reads:

if ($cookie['id'] > 0)

Change the 0 to a 1 roll

edit: Updated file to include this fix + logout fix + guest group fix

How about......now ?

Try me

(Use save as)

##
##        Mod title:  CPG avatar gallery
##
##   Works on PunBB:  1.2 + CPG 1.3 - 1.4 both running on MySQL
##     Release date:  2005-01-12
##           Author:  Nibbler (nibbler999@users.sourceforge.net)
##
##      Description:  Allows an avatar to be selected by browsing an existing Coppermine gallery, bridged or not.
##
##   Affected files:  profile.php
##
##       Affects DB:  No
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB or by the Coppermine Dev Team. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##

Get me

Screenshot

You can change the line to

else if (isset($_SERVER['QUERY_STRING']) &&  $_SERVER['QUERY_STRING'] == 'action=show_new')

72

(254 replies, posted in PunBB 1.2 discussion)

I'd prefer it to actually mention the difference between those 2 options in install. It isn't obvious that that is what the question is about. I use mysql 5, so I selected mysql 5 and then had to mess around because I don't have mysqli.

You could try adding the indexes using ALTER instead of CREATE, you may have permissions for that.

ie

ALTER TABLE online ADD INDEX online_user_id_idx(user_id);

I got around to making a cpg->punbb converter, available as a punbb1.2 plugin at the coppermine boards, here.

Oh, and passwords are stored in the cookie as md5 hashes not as plain text - that post on hotscripts is simply wrong.