Example #1
0
function countLines($dir, &$fileCounter)
{
    $_allowedFileTypes = "(html|htm|phtml|php|js|css|ini)";
    $lineCounter = 0;
    $dirHandle = opendir($dir);
    $path = realpath($dir);
    $nextLineIsComment = false;
    if ($dirHandle) {
        while (false !== ($file = readdir($dirHandle))) {
            if (is_dir($path . "/" . $file) && ($file !== '.' && $file !== '..')) {
                $lineCounter += countLines($path . "/" . $file, $fileCounter);
            } elseif ($file !== '.' && $file !== '..') {
                //Check if we have a valid file
                $ext = _findExtension($file);
                if (preg_match("/" . $_allowedFileTypes . "\$/i", $ext)) {
                    $realFile = realpath($path) . "/" . $file;
                    $fileHandle = fopen($realFile, 'r');
                    $fileArray = file($realFile);
                    //Check content of file:
                    for ($i = 0; $i < count($fileArray); $i++) {
                        if ($nextLineIsComment) {
                            $fileCounter['gen']['commentedLines']++;
                            //Look for the end of the comment block
                            if (strpos($fileArray[$i], '*/')) {
                                $nextLineIsComment = false;
                            }
                        } else {
                            //Look for a function
                            if (strpos($fileArray[$i], 'function')) {
                                $fileCounter['gen']['functions']++;
                            }
                            //Look for a commented line
                            if (strpos($fileArray[$i], '//')) {
                                $fileCounter['gen']['commentedLines']++;
                            }
                            //Look for a class
                            if (substr(trim($fileArray[$i]), 0, 5) == 'class') {
                                $fileCounter['gen']['classes']++;
                            }
                            //Look for a comment block
                            if (strpos($fileArray[$i], '/*')) {
                                $nextLineIsComment = true;
                                $fileCounter['gen']['commentedLines']++;
                                $fileCounter['gen']['commentBlocks']++;
                            }
                            //Look for a blank line
                            if (trim($fileArray[$i]) == '') {
                                $fileCounter['gen']['blankLines']++;
                            }
                        }
                    }
                    $lineCounter += count($fileArray);
                }
                //Add to the files counter
                $fileCounter['gen']['totalFiles']++;
                $fileCounter[strtolower($ext)]++;
            }
        }
    } else {
        echo 'Could not enter folder';
    }
    return $lineCounter;
}
Example #2
0
 } else {
     if (!is_dir($outDir)) {
         die("Parametre 3 : le chemin n'est pas un dossier.");
     }
 }
 if ($partNumber <= 0) {
     die("Parametre 4 : le nombre doit etre un entier naturel non nul.");
 }
 if ($partCount <= 0) {
     die("Parametre 5 : le nombre doit etre un entier naturel non nul.");
 }
 if ($partNumber > $partCount) {
     die("Parametres 4 et 5 : on s'attend a ce que parametre 4 <= parametre 5.");
 }
 /* Exécution. */
 $lineCount = countLines($groupList);
 if ($lineCount <= 0) {
     die("Impossible d'analyser la liste de groupes : nombre de lignes <= 0.");
 }
 $lineFrom = (int) ($lineCount * ($partNumber - 1) / $partCount) + 1;
 $lineTo = $partNumber == $partCount ? $lineCount : (int) ($lineCount * $partNumber / $partCount);
 $file = @fopen($groupList, "r");
 if ($file === false) {
     die("Impossible de lire la liste de groupes.");
 }
 $lineRead = 0;
 while ($lineRead < $lineFrom - 1) {
     fgets($file);
     ++$lineRead;
 }
 echo "Groupes {$lineFrom} - {$lineTo} ( " . ($lineTo - $lineFrom + 1) . " / {$lineCount} ).\n";
Example #3
0
<?php

function countLines($path, $extensions = array('php', 'html', 'css', 'js'))
{
    $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
    $files = array();
    foreach ($it as $file) {
        if ($file->isDir()) {
            continue;
        }
        $parts = explode('.', $file->getFilename());
        $extension = end($parts);
        if (in_array($extension, $extensions)) {
            $files[$file->getPathname()] = count(file($file->getPathname()));
        }
    }
    return $files;
}
$path = $_GET['p'];
$c = countLines($path);
?>

<pre>
	<?php 
foreach ($c as $f => $l) {
    echo "{$f} = {$l}\r\n";
}
echo "\r\n" . array_sum($c);
?>
</pre>
Example #4
0
                //Get all folders in subdirectory
                $items = array_merge($items, $add);
                //Add it to the master array
            }
        }
    }
    return $items;
    //Return the master array
}
$total = 0;
//Total line count
$files = getFiles();
//Get all of the directories throughout the entire directory
//Loop through
foreach ($files as $f) {
    $total += countLines($f);
    //and add the line count
}
//We'll print this out all later.
HTML::begin();
Head::make("About Us");
Body::begin();
?>
		<style>

		#code_count { border-top:1px solid green; font-family:TitilliumrRegular,Trebuchet MS, sans-serif;font-size:45px;color:green; padding:25px !important; text-align:center;}

		</style>
			<div style="min-height:520px;" class="layout-1200 uk-container-center">
				<div class="uk-grid">
					<div class="uk-width-medium-1-5">