NP_ProgressBar.php

I haven't provided this as a download yet because there are still a few things that I'd like to fix.

  • Is there a spacer image that comes with Nucleus that I could use? Right now on my server I have it linking to a spacer image I have in one of my skins, but I want to code this for maximum portability. Can I do the partial progress bars with <div> tags and CSS?
  • What is the best way for me to let people select how large to make the progress bar? I could add that as another parameter but then background and foreground colors would be required to select a size. I also want this to be different for each bar, which rules out offering an option in Nucleus..
  • What else is there I can improve upon?

I'm open to suggestions.

Code

<?php
class NP_ProgressBar extends NucleusPlugin {
 
 function getName() { return 'Progress Bar'; }
 function getAuthor() { return 'Tom Reinhart'; }
 function getURL() { return 'http://www.alltom.com/'; }
 function getVersion() { return '0.1'; }
 function getDescription() { return 'Displays a progress bar. Usage: &lt;%plugin(ProgressBar,[val],[max])%&gt; or &lt;%plugin(ProgressBar,[val],[max],[background color],[foreground color])%&gt;'; }
 
 function doSkinVar() {
  // $skinType, $min, $max, $bg, $fg
  $spacer = '[path_to_spacer_image]';
  switch( func_num_args() ){
 
   case 3:
    $min = func_get_arg(1);
    $max = func_get_arg(2);
 
    $min = floatval($min);
    $max = floatval($max);
    if( ($min > $max) || ($min < 0) || ($max < 0) ){
     die( 'Invalid variables sent to ProgressBar plugin.' );
    }else{
     if( $min == 0 ){
      echo '<table border=0 cellpadding=3 cellspacing=0 width="100%" style="border:1px solid black">';
      echo '<tr><td bgcolor="#FFCCCC"><img src="' . $spacer . '" width="1" height="1" alt="" /></td></tr>';
      echo '</table>';
     }elseif( $min == $max ){
      echo '<table border=0 cellpadding=3 cellspacing=0 width="100%" style="border:1px solid black">';
      echo '<tr><td bgcolor="#FF0000" width="36%"><img src="' . $spacer . '" width="1" height="1" alt="" /></td></tr>';
      echo '</table>';
     }else{
      $percent = floatval($min / $max * 100);
      echo '<table border=0 cellpadding=3 cellspacing=0 width="100%" style="border:1px solid black">';
      echo '<tr><td bgcolor="#FF0000" width="'. $percent . '%"><img src="' . $spacer . '" width="1" height="1" alt="" /></td>';
      echo '<td bgcolor="#FFCCCC"><img src="' . $spacer . '" width="1" height="1" alt="" /></td></tr>';
      echo '</table>';
     }
    }
    break;
 
   case 5:
    $min = func_get_arg(1);
    $max = func_get_arg(2);
    $bg = func_get_arg(3);
    $fg = func_get_arg(4);
 
    $min = floatval($min);
    $max = floatval($max);
    if( ($min > $max) || ($min < 0) || ($max < 0) ){
     die( 'Invalid variables sent to ProgressBar plugin.' );
    }else{
     if( $min == 0 ){
      echo '<table border=0 cellpadding=3 cellspacing=0 width="100%" style="border:1px solid black">';
      echo '<tr><td bgcolor="' . $bg . '"><img src="' . $spacer . '" width="1" height="1" alt="" /></td></tr>';
      echo '</table>';
     }elseif( $min == $max ){
      echo '<table border=0 cellpadding=3 cellspacing=0 width="100%" style="border:1px solid black">';
      echo '<tr><td bgcolor="' . $fg . '" width="36%"><img src="' . $spacer . '" width="1" height="1" alt="" /></td></tr>';
      echo '</table>';
     }else{
      $percent = floatval($min / $max * 100);
      echo '<table border=0 cellpadding=3 cellspacing=0 width="100%" style="border:1px solid black">';
      echo '<tr><td bgcolor="' . $fg . '" width="'. $percent . '%"><img src="' . $spacer . '" width="1" height="1" alt="" /></td>';
      echo '<td bgcolor="' . $bg . '"><img src="' . $spacer . '" width="1" height="1" alt="" /></td></tr>';
      echo '</table>';
     }
    }
    break;
 
  }
 }
 
}
?>
progressbar.txt · Last modified: 2006/07/05 13:03 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki