PHP Classes

File: all.php

Recommend this page to a friend!
  Classes of Dave Smith   PHP Deprecated Function Checker   all.php   Download  
File: all.php
Role: Example script
Content type: text/plain
Description: Check multiple files
Class: PHP Deprecated Function Checker
Find deprecated functions and suggest replacements
Author: By
Last change:
Date: 9 years ago
Size: 2,424 bytes
 

Contents

Class file image Download
<?php
require_once 'depcheck.class.php';
$dpc = new depcheck(); // get some info first
$phpVersion = PHP_VERSION;
$csvFile = $dpc->depFile;
$docRoot = $dpc->docRoot;
$pageTitle = 'PHP Deprecated Function Checker for Entire Site';
$pageSubTitle = 'Example provide by Gerry Danen';

//set folder off document root to start or leave blank to start at document root
$docFolder = '';

//check files with these extensions
$extType = array(
   
'php',
   
'inc'
);

//ignore installed PHP version
$dpc->ignoreVersion = true;

echo <<< EOT
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="/favicon.ico">
    <title>
{$pageTitle}</title>
    <link rel="stylesheet" href="depcheck.css" />
</head>
<body>
<h1>
$pageTitle</h1>
<h6>
$pageSubTitle</h6>
<div>Running PHP version
{$phpVersion}</div>
<div>Using deprecated csv file '
{$csvFile}'</div>
<div>Start checking all files at '
{$docRoot}{$docFolder}'</div>

EOT;

$docRootLength = strlen($docRoot);
$filesToProcess = array();
$fileCount = 0;
$fileTotal = 0;
processDirectory( $docRoot.$docFolder );
asort( $filesToProcess ); // sort the array
//check files
foreach( $filesToProcess AS $fileName )
{
   
$fileTotal ++ ;
   
//set file to check
   
$dpc->setFile($fileName);
   
$dpc->checkFile();
    if (
$dpc->depFlag === true )
    {
       
$result = $dpc->resultMessage;
       
$fileCount ++ ;
        echo <<< EOT
<div style="margin-top: 15px;">Checking file '<strong>{$fileName}</strong>'</div>
<div style="margin-top: 5px;margin-bottom: 5px;">Results:<br>
{$result}</div>
EOT;
    }
}
echo
"<div><br><p>Issues in $fileCount of $fileTotal files</p></div>";


// recursive
function processDirectory( $name )
{
    global
$docRootLength, $filesToProcess, $extType;

    if (
$dh = opendir($name) )
    {
        while ( (
$file = readdir($dh)) !== FALSE )
        {
           
$F = $name . '/' . $file;
           
$fileType = @filetype($F);
            if (
$fileType == 'file' )
            {
               
$ext = strtolower( pathinfo($F, PATHINFO_EXTENSION) );
                if (
in_array($ext,$extType) )
                {
                   
$filesToProcess[] = substr($F,$docRootLength);
                }
            }
            if (
$fileType == 'dir' )
            {
                if ( ! (
$file == '.' OR $file == '..') )
                {
                   
processDirectory( $F );
                }
            }
        }
       
closedir($dh);
    }
}