Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ###################################################################################################
- # KLOC Calculator
- # by: Mayank Gandhi, www.mgzhome.com
- # www.albinator.com/product/
- #
- # Special thanks to Amit Arora
- #
- # You can try my other scripts at www.mgzhome.com/project.html
- # Try my featured system Albinator: www.albinator.com/product/
- #
- # This is a Freeware, you can freely distribute/modify this,
- # Please don't remove this copyright information.
- ###################################################################################################
- $self_name = "kloc.php";
- $phpversion = phpversion();
- if($phpversion < "4.1.0")
- $_POST = &$HTTP_POST_VARS;
- $DOCUMENT_ROOT = getenv("DOCUMENT_ROOT");
- $s = isset($_POST['s']) ? $_POST['s'] : '0';
- if($s != '1')
- {
- echo(makeTemplate( '1' ));
- echo("<div align='center'>");
- echo('<form name="getValues" method="post" action="kloc.php">');
- echo('
- <table width="98%" border="0" cellspacing="4" cellpadding="5" align="center">
- <tr>
- <td width="50%" valign="top"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Root
- Path to the Parent directory</b><br>
- <font size="1">The absolute path to your code directory, e.g. /usr/bin/myname/<br>
- <br>
- <b>Note:</b> no trailing slash</font></font></td>
- <td width="59%" valign="top"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
- <input type="text" name="root_path" size="50" value="'.$DOCUMENT_ROOT.'">
- <br><input type="checkbox" name="subfolders" value="1"> include sub-folders
- </font></td>
- </tr>
- <tr>
- <td width="50%" valign="top"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Sub-Directories
- to include<br>
- </b><font size="1">List of all sub-directories you wish to calculate from.
- Don\'t remove "/" as it counts from the root path (separate by commans e.g.
- dir1,dir2) </font></font></td>
- <td width="59%" valign="top"><font face="Georgia, Times New Roman, Times, serif" size="2">
- <input type="text" name="subDirs" size="50" value="/,">
- </font></td>
- </tr>
- <tr>
- <td width="50%" valign="top"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Extentions
- to include<br>
- </b><font size="1">the extentions of the files you want to calculate, if
- you have many to include and less to exclude then just give "." in the include
- extensions and provide the list to exclude in the next variable. e.g. .php,
- .html <br>
- <br>
- <b>Tip:</b> use . for all files</font></font></td>
- <td width="59%" valign="top"><font face="Georgia, Times New Roman, Times, serif" size="2">
- <input type="text" name="masks_include_var" size="50">
- </font></td>
- </tr>
- <tr>
- <td width="50%" valign="top"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Extentions
- to exclude<br>
- </b><font size="1">the extentions of the files you want to exclude to calculate,
- if you have many to include and less to exclude then just give "." in the
- include extensions and provide the list to exclude in the next variable.
- e.g. .php, .html </font></font></td>
- <td width="59%" valign="top"><font face="Georgia, Times New Roman, Times, serif" size="2">
- <input type="text" name="masks_exclude_var" size="50">
- </font></td>
- </tr>
- <tr>
- <td width="50%"><font face="Georgia, Times New Roman, Times, serif" size="2"></font></td>
- <td width="59%" valign="top"><font face="Georgia, Times New Roman, Times, serif" size="2">
- <input type="hidden" name="s" value="1">
- <input type="submit" name="Submit" value="start calculating >">
- </font></td>
- </tr>
- </table>
- ');
- echo('</form>');
- echo("</div>");
- echo(makeTemplate( '2' ));
- exit;
- }
- set_time_limit(0);
- $bQuote = get_magic_quotes_gpc();
- $root_path = ($bQuote ? stripslashes($_POST['root_path']) : $_POST['root_path']);
- $subDirs = explode(",", ($bQuote ? stripslashes($_POST['subDirs']) : $_POST['subDirs']));
- $masks_include = explode(",", ($bQuote ? stripslashes($_POST['masks_include_var']) : $_POST['masks_include_var']));
- $masks_exclude = explode(",", ($bQuote ? stripslashes($_POST['masks_exclude_var']) : $_POST['masks_exclude_var']));
- $subfolders = isset($_POST['subfolders']) ? $_POST['subfolders'] : '0';
- $tf_count = '';
- $sMask = '';
- $lMask = '';
- $kloc = 0;
- $mtime = microtime();
- $mtime = explode(" ",$mtime);
- $mtime = $mtime[1] + $mtime[0];
- $starttime = $mtime;
- echo(makeTemplate( '1' ));
- echo("<a href='#report'>see Summary Count</a> :: <a href='?redo'>reCalculate</a>");
- while( $e = each($masks_include) )
- {
- if($e[0] != '0')
- $sMask .= "|";
- $sMask .= "($e[1])";
- }
- $sMask = "/$sMask/";
- while( $e = each($masks_exclude) )
- {
- if($e[0] != '0')
- $lMask .= "|";
- $lMask .= "($e[1])";
- }
- if($lMask != "()")
- $lMask = "/$lMask/";
- else
- $lMask = "";
- if(count($subDirs) == 0)
- $subDirs[] = "/";
- // while ( $e = each($subDirs) )
- $counter = 0;
- while ( count($subDirs) > $counter )
- {
- $f_count = 0;
- $files_to_go = '';
- $files = array();
- if(file_exists("$root_path".$subDirs[$counter]))
- $d = dir( "$root_path".$subDirs[$counter] );
- $currentDirpath = "$root_path".$subDirs[$counter];
- while( $fn = @$d->read() )
- {
- if ( filetype( $currentDirpath."/$fn" ) == "file" && preg_match( $sMask, $fn ) && $fn != $self_name)
- {
- if($lMask)
- {
- if(!preg_match( $lMask, $fn ))
- $files[ $fn ] = filetype( $currentDirpath."/$fn" );
- }
- else
- $files[ $fn ] = filetype( $currentDirpath."/$fn" );
- }
- else if(filetype( $currentDirpath."/$fn" ) == "dir" && $fn != "." && $fn != ".." && $subfolders == "1")
- {
- if(!in_array($subDirs[$counter]."$fn", $subDirs))
- {
- $add_dir = $subDirs[$counter]."/$fn";
- $subDirs[] = str_replace( '//', '/', $add_dir);
- }
- }
- }
- if ($files)
- {
- while ( $f = each($files) )
- {
- $fn = $f[0];
- if ( is_readable( $currentDirpath."/$fn" ) && preg_match( $sMask, $fn ) )
- {
- $e_temp = $counter;
- $f_count++;
- $filedata = file($currentDirpath."/$fn");
- $kloc += count($filedata);
- $files_to_go .= "<li>$f[0], <b>".count($filedata)." lines</b></li>\n";
- }
- }
- }
- else
- {
- echo "<br><font face='Arial' color='#800000' size='2'>No files found in directory: <b>$currentDirpath</b></font><br>";
- $f_count = -1;
- }
- if(!$f_count)
- {
- echo "<br><font face='Arial' color='#800000' size='2'>No files found in directory: <b>$currentDirpath</b></font><br>";
- }
- else if($f_count > 0)
- {
- $tf_count += $f_count;
- if($subDirs[$counter] != "/")
- echo("<p><br>Location: <b>$currentDirpath</b><p>$files_to_go</ul>\n");
- }
- $counter++;
- @$d->close();
- }
- $mtime = microtime();
- $mtime = explode(" ",$mtime);
- $mtime = $mtime[1] + $mtime[0];
- $endtime = $mtime;
- $totaltime = ($endtime - $starttime);
- echo("<br><br>\n<a name='report'></a>");
- echo("<b>Summary Count</b>\n");
- echo("<ul>");
- echo("<li>FILES :: $tf_count</li>");
- echo("<li>DIRECTORIES :: ".(count($subDirs) - 1)."</li>");
- echo("<li>L O C :: $kloc</li>");
- echo("<li>K L O C :: ".($kloc/1000)."</li>");
- echo("<li>TIME TAKEN :: $totaltime seconds</li>");
- echo("</ul>");
- echo(makeTemplate( '2' ));
- function makeTemplate( $place )
- {
- $header_val =<<<__HTML_END_
- <html>
- <head>
- <title>KLOC Calculator</title>
- <style type="text/css">
- <!--
- .ts { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; }
- .tn { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; }
- -->
- </style>
- </head>
- <body background="bg.gif">
- <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
- <tr>
- <td>
- <table width="95%" border="1" cellspacing="0" cellpadding="4" bordercolor="#000000" align="center" class="tn">
- <tr bgcolor="#006699" align="right">
- <td><font size="4" color="#FFFFFF">KLOC Calculator </font></td>
- </tr>
- <tr bgcolor="#EEEEEE">
- <td>
- <p> </p>
- __HTML_END_;
- $footer_val =<<<__HTML_END_
- </font>
- <br>
- </td>
- </tr>
- </table>
- <br>
- <div align="center" class="ts">powered by: <a href="http://www.mgzhome.com/project.html#kloc" target=_blank>KLOC Calculator</a> © copyright 2003, Mayank Gandhi</div></font>
- <br><br>
- <table width="95%" border="0" cellspacing="0" cellpadding="2" align="center" class="ts">
- <tr>
- <td colspan="2" align="center" class="tn" bgcolor="#EEEEEE"><b>My Other featured scripts</b></td>
- </tr>
- <tr align="center" bgcolor="#FCFCFC">
- <td width="50%"><br><a href="http://www.albinator.com/product/" target="_blank"><img src="albinator.gif" width="200" height="111" alt="Albinator" border="0"></a><br><br></td>
- <td width="50%"><br><a href="http://www.mgzhome.com/scripts/extpwr/" target="_blank"><img src="extremepower.gif" width="140" height="160" alt="eXtreme power" border="0"></a><br><br></td>
- </tr>
- <tr align="center">
- <td width="50%" bgcolor="#CCCCCC">advanced photo album/gallery system in over 8 languages</td>
- <td width="50%" bgcolor="#DDDDDD">perfect solution 4 secure-login, virtual community features</td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </body>
- </html>
- __HTML_END_;
- if($place == '1')
- return ( $header_val );
- else if($place == '2')
- return ( $footer_val );
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement