コード例 #1
0
function cpg_versioncheckPopulateArray($file_data_array)
{
    global $displayOption_array, $textFileExtensions_array, $imageFileExtensions_array, $CONFIG, $maxLength_array, $lang_versioncheck_php, $lang_common;
    $extensionMatrix_array = array('unknown' => 'images/extensions/unknown.png', 'folder' => 'images/extensions/folder.png', 'php' => 'images/extensions/php.png', 'js' => 'images/extensions/js.png', 'css' => 'images/extensions/css.png', 'htm' => 'images/extensions/htm.png', 'html' => 'images/extensions/htm.png', 'sql' => 'images/extensions/sql.png', 'ttf' => 'images/extensions/ttf.png', 'ico' => 'images/extensions/unknown.png');
    $loopCounter = 0;
    //print_r($file_data_array);
    //die;
    foreach ($file_data_array as $file_data_key => $file_data_values) {
        // start the foreach loop
        // initialize the vars
        if (!isset($file_data_array[$file_data_key]['comment'])) {
            $file_data_array[$file_data_key]['comment'] = '';
        }
        if (!isset($file_data_array[$file_data_key]['txt_revision'])) {
            $file_data_array[$file_data_key]['txt_revision'] = '';
        }
        if (!isset($file_data_array[$file_data_key]['version'])) {
            $file_data_array[$file_data_key]['version'] = '';
        }
        if (!isset($file_data_array[$file_data_key]['local_version'])) {
            $file_data_array[$file_data_key]['local_version'] = '';
        }
        if (!isset($file_data_array[$file_data_key]['revision'])) {
            $file_data_array[$file_data_key]['revision'] = '';
        }
        if (!isset($file_data_array[$file_data_key]['local_revision'])) {
            $file_data_array[$file_data_key]['local_revision'] = '';
        }
        if (!isset($file_data_array[$file_data_key]['txt_folderfile'])) {
            $file_data_array[$file_data_key]['txt_folderfile'] = '';
        }
        // Replace the placeholders with actual content --- start
        $file_data_array[$file_data_key]['fullpath'] = str_replace('**fullpath**', rtrim($CONFIG['fullpath'], '/'), $file_data_array[$file_data_key]['fullpath']);
        $file_data_array[$file_data_key]['fullpath'] = str_replace('**userpics**', rtrim($CONFIG['userpics'], '/'), $file_data_array[$file_data_key]['fullpath']);
        // Replace the placeholders with actual content --- end
        // populate the path and file from the fullpath --- start
        $tempArray = cpg_get_path_and_file($file_data_array[$file_data_key]['fullpath']);
        $file_data_array[$file_data_key]['folder'] = $tempArray['path'];
        $file_data_array[$file_data_key]['file'] = $tempArray['file'];
        // populate the path and file from the fullpath --- end
        // determine the number of parent folders --- start
        $file_data_array[$file_data_key]['folderDepth'] = count(explode('/', rtrim($tempArray['path'], '/')));
        if (strlen($file_data_array[$file_data_key]['folder']) > $maxLength_array['folderfile']) {
            $maxLength_array['folderfile'] = strlen($file_data_array[$file_data_key]['folder']);
        }
        // determine the number of parent folders --- end
        // Determine the icon -- start
        if ($file_data_array[$file_data_key]['file'] == '') {
            // we have a folder here --- start
            $file_data_array[$file_data_key]['icon'] = '<img src="' . $extensionMatrix_array['folder'] . '" border="0" width="16" height="16" alt="" style="margin-left:' . 16 * ($file_data_array[$file_data_key]['folderDepth'] - 1) . 'px" />';
            // we have a folder here --- end
        } else {
            // we have a file here --- start
            // determine the extension -- start
            $file_data_array[$file_data_key]['extension'] = ltrim(substr($file_data_array[$file_data_key]['file'], strrpos($file_data_array[$file_data_key]['file'], '.')), '.');
            // determine the extension -- end
            // determine the icon representing the file -- start
            if (array_key_exists($file_data_array[$file_data_key]['extension'], $extensionMatrix_array) == TRUE) {
                $file_data_array[$file_data_key]['icon'] = '<img src="' . $extensionMatrix_array[$file_data_array[$file_data_key]['extension']] . '" border="0" width="16" height="16" alt="' . $file_data_array[$file_data_key]['extension'] . '" style="margin-left:' . 16 * $file_data_array[$file_data_key]['folderDepth'] . 'px" />';
            } elseif (in_array($file_data_array[$file_data_key]['extension'], $imageFileExtensions_array)) {
                $file_data_array[$file_data_key]['icon'] = '<img src="images/extensions/' . $file_data_array[$file_data_key]['extension'] . '.png" border="0" width="16" height="16" alt="' . $file_data_array[$file_data_key]['extension'] . '" style="margin-left:' . 16 * $file_data_array[$file_data_key]['folderDepth'] . 'px" />';
            } else {
                $file_data_array[$file_data_key]['icon'] = '<img src="' . $extensionMatrix_array['unknown'] . '" border="0" width="16" height="16" alt="' . $file_data_array[$file_data_key]['extension'] . '" style="margin-left:' . 16 * $file_data_array[$file_data_key]['folderDepth'] . 'px" />';
            }
            // determine the icon representing the file -- end
            // we have a file here --- end
        }
        // Determine the icon -- end
        // Is the folder/file actually there --- start
        $file_data_array[$file_data_key]['exists'] = file_exists($file_data_array[$file_data_key]['fullpath']);
        // Is the folder/file actually there --- end
        if ($file_data_array[$file_data_key]['exists'] != 1) {
            // The folder/file is missing --- start
            if ($file_data_array[$file_data_key]['status'] == 'mandatory') {
                $file_data_array[$file_data_key]['txt_missing'] = $lang_versioncheck_php['mandatory'];
                $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['mandatory_missing'];
                $file_data_array[$file_data_key]['txt_version'] = $lang_versioncheck_php['not_applicable'];
                $file_data_array[$file_data_key]['txt_revision'] = $lang_versioncheck_php['not_applicable'];
            } elseif ($file_data_array[$file_data_key]['status'] == 'remove') {
                $file_data_array[$file_data_key]['txt_missing'] = $lang_versioncheck_php['removed'] . ' (' . $lang_common['ok'] . ')';
                $file_data_array[$file_data_key]['txt_version'] = $lang_versioncheck_php['not_applicable'] . ' (' . $lang_common['ok'] . ')';
                $file_data_array[$file_data_key]['txt_revision'] = $lang_versioncheck_php['not_applicable'] . ' (' . $lang_common['ok'] . ')';
            } else {
                $file_data_array[$file_data_key]['txt_missing'] = $lang_versioncheck_php['optional'];
                $file_data_array[$file_data_key]['txt_version'] = $lang_versioncheck_php['not_applicable'];
                $file_data_array[$file_data_key]['txt_revision'] = $lang_versioncheck_php['not_applicable'];
            }
            if (strlen($file_data_array[$file_data_key]['txt_missing']) > $maxLength_array['exist']) {
                $maxLength_array['exist'] = strlen($file_data_array[$file_data_key]['txt_missing']);
            }
            // The folder/file is missing --- end
        } else {
            // The folder/file exists --- start
            if ($file_data_array[$file_data_key]['file'] == '') {
                // we have a folder here --- start
                $file_data_array[$file_data_key]['txt_folderfile'] = $lang_versioncheck_php['folder'];
                // no version or revision number for folder names
                $file_data_array[$file_data_key]['txt_version'] = $lang_versioncheck_php['not_applicable'] . ' (' . $lang_common['ok'] . ')';
                $file_data_array[$file_data_key]['txt_revision'] = $lang_versioncheck_php['not_applicable'] . ' (' . $lang_common['ok'] . ')';
                if (isset($displayOption_array['no_modification_check']) && $displayOption_array['no_modification_check'] != 1) {
                    $file_data_array[$file_data_key]['txt_modified'] = $lang_versioncheck_php['not_applicable'] . ' (' . $lang_common['ok'] . ')';
                }
                $file_data_array[$file_data_key]['local_version'] = '';
                $file_data_array[$file_data_key]['local_revision'] = '';
                if (is_readable($file_data_values['fullpath']) == TRUE) {
                    // check if the folder is readable/writable --- start
                    // Sadly, is_readable doesn't really work on all server setups
                    $file_data_array[$file_data_key]['local_readwrite'] = $lang_versioncheck_php['read'];
                    $file_data_array[$file_data_key]['local_readwrite'] = cpg_is_writable($file_data_array[$file_data_key]['fullpath']);
                    if (is_writable($file_data_values['fullpath']) == TRUE) {
                        $file_data_array[$file_data_key]['local_readwrite'] = $lang_versioncheck_php['write'];
                    }
                }
                // check if the folder is readable/writable --- end
                // we have a folder here --- end
            } else {
                // we have a file here --- start
                $file_data_array[$file_data_key]['txt_folderfile'] = $lang_versioncheck_php['file'];
                if (in_array($file_data_array[$file_data_key]['extension'], $textFileExtensions_array) == TRUE) {
                    // the file is not binary, i.e. it's a text file --- start
                    $handle = @fopen($file_data_array[$file_data_key]['fullpath'], 'r');
                    if ($handle == FALSE) {
                        // We haven't been able to even fopen the file, so the information retrieved by is_readable/is_writable returned nonsense. Let's reset the information accordingly.
                        $file_data_array[$file_data_key]['local_readwrite'] = '--';
                        $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['inaccessible'] . '. ' . $lang_versioncheck_php['review_permissions'] . '. ';
                        //$file_data_array[$file_data_key]['comment'] .= '|'.$file_data_values['fullpath'];
                    } else {
                        // File is readable -- start
                        $blob = '';
                        $blob = @fread($handle, filesize($file_data_array[$file_data_key]['fullpath']));
                        @fclose($handle);
                        $revision_string = '$' . 'Revision' . ':';
                        $cpg_version_determination = 'Coppermine' . ' ' . 'version:';
                        $blob = str_replace('<?php', '', $blob);
                        // Determine the cpg version -- start
                        $file_data_array[$file_data_key]['local_version'] = substr($blob, strpos($blob, $cpg_version_determination));
                        // chop off the first bit up to the string $cpg_version_determination
                        $double_slash_position = strpos($file_data_array[$file_data_key]['local_version'], '//');
                        if ($double_slash_position) {
                            $file_data_array[$file_data_key]['local_version'] = substr($file_data_array[$file_data_key]['local_version'], 0, $double_slash_position);
                        }
                        $file_data_array[$file_data_key]['local_version'] = trim(str_replace($cpg_version_determination, '', $file_data_array[$file_data_key]['local_version']));
                        $file_data_array[$file_data_key]['local_version'] = trim(str_replace('#', '', $file_data_array[$file_data_key]['local_version']));
                        $file_data_array[$file_data_key]['local_version'] = trim(substr($file_data_array[$file_data_key]['local_version'], 0, strpos($file_data_array[$file_data_key]['local_version'], '$')));
                        if (strlen($file_data_array[$file_data_key]['local_version']) > 6) {
                            // Version numbers larger than 6 are not likely at all
                            $file_data_array[$file_data_key]['local_version'] = $lang_versioncheck_php['not_applicable'];
                        }
                        if ($file_data_array[$file_data_key]['version'] != '' && $file_data_array[$file_data_key]['exists'] == 1 && $file_data_array[$file_data_key]['local_version'] != '') {
                            $file_data_array[$file_data_key]['txt_version'] = ' (';
                            $versionCompare = version_compare($file_data_array[$file_data_key]['local_version'], $file_data_array[$file_data_key]['version']);
                            if ($versionCompare == 0) {
                                $file_data_array[$file_data_key]['txt_version'] .= $lang_common['ok'];
                            } elseif ($versionCompare == -1) {
                                $file_data_array[$file_data_key]['txt_version'] .= sprintf($lang_versioncheck_php['outdated'], $file_data_array[$file_data_key]['version']);
                                $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['review_version'] . '. ';
                            } else {
                                $file_data_array[$file_data_key]['txt_version'] .= sprintf($lang_versioncheck_php['newer'], $file_data_array[$file_data_key]['version']);
                                $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['review_dev_version'] . '. ';
                            }
                            $file_data_array[$file_data_key]['txt_version'] .= ')';
                        } else {
                            $file_data_array[$file_data_key]['txt_version'] = '';
                        }
                        if ($file_data_array[$file_data_key]['local_version'] != '' && $file_data_array[$file_data_key]['txt_version'] == '') {
                            $file_data_array[$file_data_key]['txt_version'] = ' (?)';
                        }
                        if ($file_data_array[$file_data_key]['version'] == '' && $file_data_array[$file_data_key]['txt_version'] == '') {
                            $file_data_array[$file_data_key]['txt_version'] = $lang_versioncheck_php['not_applicable'] . ' (' . $lang_common['ok'] . ')';
                        }
                        if (strlen($file_data_array[$file_data_key]['local_version'] . $file_data_array[$file_data_key]['txt_version']) > $maxLength_array['version']) {
                            $maxLength_array['version'] = strlen($file_data_array[$file_data_key]['local_version'] . $file_data_array[$file_data_key]['txt_version']);
                        }
                        // Determine the cpg version -- end
                        // Determine file revision -- start
                        if ($file_data_array[$file_data_key]['revision'] != '') {
                            // only look the revision up if a revision is given in the XML data
                            $file_data_array[$file_data_key]['local_revision'] = str_replace($revision_string, '', substr($blob, strpos($blob, $revision_string), 25));
                            $file_data_array[$file_data_key]['local_revision'] = trim(substr($file_data_array[$file_data_key]['local_revision'], 0, strpos($file_data_array[$file_data_key]['local_revision'], '$')));
                            if (strlen($file_data_array[$file_data_key]['local_revision']) > 5) {
                                // Check validity of revision: more than 5 chars is not expected
                                $file_data_array[$file_data_key]['local_revision'] = $lang_versioncheck_php['not_applicable'];
                            }
                            if ($file_data_array[$file_data_key]['local_revision'] != '' && $file_data_array[$file_data_key]['exists'] == 1) {
                                //$file_data_array[$file_data_key]['local_revision'] = $file_data_array[$file_data_key]['revision'];
                                if ($file_data_array[$file_data_key]['local_revision'] == $file_data_array[$file_data_key]['revision']) {
                                    $file_data_array[$file_data_key]['txt_revision'] .= ' (' . $lang_common['ok'] . ')';
                                } elseif ($file_data_array[$file_data_key]['local_revision'] < $file_data_array[$file_data_key]['revision']) {
                                    $file_data_array[$file_data_key]['txt_revision'] .= ' (' . sprintf($lang_versioncheck_php['outdated'], $file_data_array[$file_data_key]['revision']) . ')(!)';
                                    if ($versionCompare == 0) {
                                        $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['review_version'] . '. ';
                                    }
                                } else {
                                    $file_data_array[$file_data_key]['txt_revision'] .= ' (' . sprintf($lang_versioncheck_php['newer'], $file_data_array[$file_data_key]['revision']) . ')(?)';
                                    if ($versionCompare == 0) {
                                        $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['review_dev_version'] . '. ';
                                    }
                                }
                                //$file_data_array[$file_data_key]['txt_revision'] .= ')';
                            } else {
                                $file_data_array[$file_data_key]['txt_revision'] = '';
                            }
                        } else {
                            // there's no file revision given, so let's output "na"
                            $file_data_array[$file_data_key]['txt_revision'] = $lang_versioncheck_php['not_applicable'] . ' (' . $lang_common['ok'] . ')';
                        }
                        // Determine file revision -- end
                        // File is readable -- end
                    }
                    // the file is not binary, i.e. it's a text file --- end
                } else {
                    // the file is binary, i.e. it's an image --- start
                    // binary files don't come with version numbers -- start
                    $file_data_array[$file_data_key]['txt_version'] = $lang_versioncheck_php['not_applicable'] . ' (' . $lang_common['ok'] . ')';
                    $file_data_array[$file_data_key]['txt_revision'] = $lang_versioncheck_php['not_applicable'] . ' (' . $lang_common['ok'] . ')';
                    // binary files don't come with version numbers -- end
                    // the file is binary, i.e. it's an image --- end
                }
                // check the md5 hashes --- start
                if (isset($displayOption_array['no_modification_check']) && $displayOption_array['no_modification_check'] != 1) {
                    // Is the option "no_modification_check" not populated --- start
                    if (function_exists('md5_file')) {
                        // the MD5-function may not exist
                        // Do we have an md5-hash that we could compare against? -- start
                        if ($file_data_array[$file_data_key]['hash'] != '') {
                            // only perform the md5-check if the versions and revisions match anyway - we'd be comparing apples with bananas if we checked the hashes otherwise -- start
                            if ($file_data_array[$file_data_key]['version'] == $file_data_array[$file_data_key]['local_version'] && $file_data_array[$file_data_key]['revision'] == $file_data_array[$file_data_key]['local_revision']) {
                                $file_data_array[$file_data_key]['local_hash'] = md5_file($file_data_values['fullpath']);
                                if ($file_data_array[$file_data_key]['local_hash'] == $file_data_array[$file_data_key]['hash']) {
                                    $file_data_array[$file_data_key]['unmodified'] = 1;
                                    $file_data_array[$file_data_key]['txt_modified'] = $lang_versioncheck_php['not_modified'] . ' (' . $lang_common['ok'] . ')';
                                } else {
                                    $file_data_array[$file_data_key]['unmodified'] = 0;
                                    $file_data_array[$file_data_key]['txt_modified'] = $lang_versioncheck_php['modified'] . ' (!)';
                                    $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['review_modified'] . '. ';
                                }
                            } else {
                                $file_data_array[$file_data_key]['txt_modified'] = $lang_versioncheck_php['not_applicable'];
                            }
                            // only perform the md5-check if the versions and revisions match anyway - we'd be comparing apples with bananas if we checked the hashes otherwise -- end
                        }
                        // Do we have an md5-hash that we could compare against? -- end
                    }
                    // Is the option "no_modification_check" not populated --- end
                }
                // check the md5 hashes --- end
                if ($file_data_array[$file_data_key]['status'] == 'remove') {
                    // should the file have been removed ? --- start
                    $file_data_array[$file_data_key]['txt_missing'] = $lang_versioncheck_php['existing'];
                    $file_data_array[$file_data_key]['txt_version'] = $lang_versioncheck_php['not_applicable'];
                    $file_data_array[$file_data_key]['txt_revision'] = $lang_versioncheck_php['not_applicable'];
                    if ($displayOption_array['no_modification_check'] != 1) {
                        $file_data_array[$file_data_key]['txt_modified'] = $lang_versioncheck_php['not_applicable'];
                    } else {
                        $file_data_array[$file_data_key]['txt_modified'] = '';
                    }
                    $file_data_array[$file_data_key]['comment'] = $lang_versioncheck_php['review_removed_existing'];
                    // should the file have been removed ? --- end
                }
                // we have a file here --- end
            }
            // The folder/file exists --- end
        }
        // Populate some columns for files that have been successfully removed
        if ($file_data_array[$file_data_key]['status'] == 'remove') {
            // Fill the folder/file status column
            if ($file_data_array[$file_data_key]['txt_folderfile'] == '') {
                $file_data_array[$file_data_key]['txt_folderfile'] = $lang_versioncheck_php['not_applicable'];
            }
            if (isset($file_data_array[$file_data_key]['txt_modified']) && $file_data_array[$file_data_key]['txt_modified'] == '' && $displayOption_array['no_modification_check'] != 1) {
                $file_data_array[$file_data_key]['txt_modified'] = $lang_versioncheck_php['not_applicable'] . ' (' . $lang_common['ok'] . ')';
            }
        }
        $loopCounter++;
        //  Adapt the maxLength array -- start
        if (strlen($file_data_array[$file_data_key]['fullpath']) > $maxLength_array['fullpath']) {
            $maxLength_array['fullpath'] = strlen($file_data_array[$file_data_key]['fullpath']);
        }
        if (strlen($file_data_array[$file_data_key]['txt_folderfile']) > $maxLength_array['folderfile']) {
            $maxLength_array['folderfile'] = strlen($file_data_array[$file_data_key]['txt_folderfile']);
        }
        if (strlen($file_data_array[$file_data_key]['txt_revision']) > $maxLength_array['revision']) {
            $maxLength_array['revision'] = strlen($file_data_array[$file_data_key]['txt_revision']);
        }
        if (strlen($file_data_array[$file_data_key]['local_revision'] . $file_data_array[$file_data_key]['txt_revision']) > $maxLength_array['revision']) {
            $maxLength_array['revision'] = strlen($file_data_array[$file_data_key]['local_revision'] . $file_data_array[$file_data_key]['txt_revision']);
        }
        if (strlen($lang_versioncheck_php['warning']) > $maxLength_array['comment']) {
            $maxLength_array['comment'] = strlen($lang_versioncheck_php['warning']);
        }
        if (isset($file_data_array[$file_data_key]['txt_modified']) && strlen($file_data_array[$file_data_key]['txt_modified']) > $maxLength_array['modified']) {
            $maxLength_array['modified'] = strlen($file_data_array[$file_data_key]['txt_modified']);
        }
        //  Adapt the maxLength array -- end
    }
    // end the foreach loop
    return $file_data_array;
}
コード例 #2
0
function cpg_versioncheckPopulateArray2($file_data_array)
{
    global $displayOption_array, $textFileExtensions_array, $imageFileExtensions_array, $CONFIG, $maxLength_array, $lang_versioncheck_php;
    $extensionMatrix_array = array('unknown' => 'images/extensions/unknown.gif', 'folder' => 'images/extensions/folder.gif', 'php' => 'images/extensions/php.gif', 'js' => 'images/extensions/js.gif', 'css' => 'images/extensions/css.gif', 'htm' => 'images/extensions/htm.gif', 'html' => 'images/extensions/htm.gif', 'sql' => 'images/extensions/sql.gif', 'ttf' => 'images/extensions/ttf.gif', 'ico' => 'images/extensions/unknown.gif');
    $maxLength_array = array();
    $maxLength_array['counter'] = strlen($lang_versioncheck_php['counter']);
    $maxLength_array['folderfile'] = strlen($lang_versioncheck_php['type']);
    $maxLength_array['exist'] = strlen($lang_versioncheck_php['missing']);
    $maxLength_array['readwrite'] = strlen($lang_versioncheck_php['permissions']);
    $maxLength_array['version'] = strlen($lang_versioncheck_php['version']);
    $maxLength_array['revision'] = strlen($lang_versioncheck_php['revision']);
    $maxLength_array['modified'] = strlen($lang_versioncheck_php['modified']);
    $loopCounter = 0;
    foreach ($file_data_array as $file_data_key => $file_data_values) {
        $file_data_array[$file_data_key]['comment'] = '';
        // Replace the placeholders with actual content --- start
        $file_data_array[$file_data_key]['fullpath'] = str_replace('**fullpath**', rtrim($CONFIG['fullpath'], '/'), $file_data_array[$file_data_key]['fullpath']);
        $file_data_array[$file_data_key]['fullpath'] = str_replace('**userpics**', rtrim($CONFIG['userpics'], '/'), $file_data_array[$file_data_key]['fullpath']);
        // Replace the placeholders with actual content --- end
        if (strlen($file_data_array[$file_data_key]['fullpath']) > $maxLength_array['fullpath']) {
            $maxLength_array['fullpath'] = strlen($file_data_array[$file_data_key]['fullpath']);
        }
        // populate the path and file from the fullpath
        $tempArray = cpg_get_path_and_file($file_data_array[$file_data_key]['fullpath']);
        $file_data_array[$file_data_key]['folder'] = $tempArray['path'];
        //determine the number of parent folders
        $file_data_array[$file_data_key]['folderDepth'] = count(explode('/', rtrim($tempArray['path'], '/')));
        if (strlen($file_data_array[$file_data_key]['folder']) > $maxLength_array['folder']) {
            $maxLength_array['folder'] = strlen($file_data_array[$file_data_key]['folder']);
        }
        $file_data_array[$file_data_key]['file'] = $tempArray['file'];
        $file_data_array[$file_data_key]['exists'] = file_exists($file_data_array[$file_data_key]['fullpath']);
        if ($file_data_array[$file_data_key]['exists'] != 1) {
            if ($file_data_array[$file_data_key]['status'] == 'mandatory') {
                $file_data_array[$file_data_key]['txt_missing'] = $lang_versioncheck_php['mandatory'];
                $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['mandatory'];
            } else {
                $file_data_array[$file_data_key]['txt_missing'] = $lang_versioncheck_php['optional'];
            }
            if (strlen($file_data_array[$file_data_key]['txt_missing']) > $maxLength_array['exist']) {
                $maxLength_array['exist'] = strlen($file_data_array[$file_data_key]['txt_missing']);
            }
        }
        if ($file_data_array[$file_data_key]['file'] == '') {
            // we have a folder here
            $file_data_array[$file_data_key]['local_readwrite'] = cpg_is_writable($file_data_array[$file_data_key]['path']);
            $file_data_array[$file_data_key]['txt_folderfile'] = $lang_versioncheck_php['folder'];
            $file_data_array[$file_data_key]['icon'] = '<img src="' . $extensionMatrix_array['folder'] . '" border="0" width="16" height="16" alt="" style="margin-left:' . 16 * ($file_data_array[$file_data_key]['folderDepth'] - 1) . 'px" />';
            // no version or revision number for folder names
            $file_data_array[$file_data_key]['txt_version'] = 'n/a (' . $lang_versioncheck_php['ok'] . ')';
            $file_data_array[$file_data_key]['txt_revision'] = 'n/a (' . $lang_versioncheck_php['ok'] . ')';
            $file_data_array[$file_data_key]['local_version'] = '';
            $file_data_array[$file_data_key]['local_revision'] = '';
        } else {
            // we have a file here --- start
            // determine the extension
            $file_data_array[$file_data_key]['extension'] = ltrim(substr($file_data_array[$file_data_key]['file'], strrpos($file_data_array[$file_data_key]['file'], '.')), '.');
            if (array_key_exists($file_data_array[$file_data_key]['extension'], $extensionMatrix_array) == TRUE) {
                $file_data_array[$file_data_key]['icon'] = '<img src="' . $extensionMatrix_array[$file_data_array[$file_data_key]['extension']] . '" border="0" width="16" height="16" alt="' . $file_data_array[$file_data_key]['extension'] . '" style="margin-left:' . 16 * $file_data_array[$file_data_key]['folderDepth'] . 'px" />';
            } else {
                //  the file is not in the extension array
                if (in_array($file_data_array[$file_data_key]['extension'], $imageFileExtensions_array)) {
                    // we have an image
                    // no version or revision number for images
                    $file_data_array[$file_data_key]['txt_version'] = 'n/a (' . $lang_versioncheck_php['ok'] . ')';
                    $file_data_array[$file_data_key]['txt_revision'] = 'n/a (' . $lang_versioncheck_php['ok'] . ')';
                    $file_data_array[$file_data_key]['local_version'] = '';
                    $file_data_array[$file_data_key]['local_revision'] = '';
                    $file_data_array[$file_data_key]['icon'] = '<img src="images/extensions/' . $file_data_array[$file_data_key]['extension'] . '.gif" border="0" width="16" height="16" alt="' . $file_data_array[$file_data_key]['extension'] . '" style="margin-left:' . 16 * $file_data_array[$file_data_key]['folderDepth'] . 'px" />';
                } else {
                    // no image file
                    $file_data_array[$file_data_key]['icon'] = '<img src="' . $extensionMatrix_array['unknown'] . '" border="0" width="16" height="16" alt="' . $file_data_array[$file_data_key]['extension'] . '" style="margin-left:' . 16 * $file_data_array[$file_data_key]['folderDepth'] . 'px" />';
                }
            }
            if (is_readable($file_data_values['fullpath']) == TRUE) {
                // check if the file is readable/writable --- start
                // Sadly, is_readable doesn't really work on all server setups, so we might have to review later when performing the fopen
                $file_data_array[$file_data_key]['local_readwrite'] = 'read';
                if (is_writable($file_data_values['fullpath']) == TRUE) {
                    $file_data_array[$file_data_key]['local_readwrite'] = 'write';
                }
            }
            // check if the file is readable/writable --- end
            if ($file_data_array[$file_data_key]['exists'] && $file_data_array[$file_data_key]['local_readwrite'] != '') {
                if (in_array($file_data_array[$file_data_key]['extension'], $textFileExtensions_array) == TRUE) {
                    // the file is not binary --- start
                    $handle = @fopen($file_data_values['fullpath'], 'r');
                    if ($handle == FALSE) {
                        // We haven't been able to even fopen the file, so the information retrieved by is_readable/is_writable returned nonsense. Let's reset the information accordingly.
                        $file_data_array[$file_data_key]['local_readwrite'] = '--';
                        $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['inaccessible'] . '. ' . $lang_versioncheck_php['review_permissions'] . '. ';
                    }
                    $blob = '';
                    $blob = @fread($handle, filesize($file_data_values['fullpath']));
                    @fclose($handle);
                    $revision_string = '$' . 'Revision' . ':';
                    $cpg_version_determination = 'Coppermine' . ' ' . 'version:';
                    $blob = str_replace('<?php', '', $blob);
                    // Determine the cpg version
                    $file_data_array[$file_data_key]['local_version'] = substr($blob, strpos($blob, $cpg_version_determination));
                    // chop off the first bit up to the string $cpg_version_determination
                    $double_slash_position = strpos($file_data_array[$file_data_key]['local_version'], '//');
                    if ($double_slash_position) {
                        $file_data_array[$file_data_key]['local_version'] = substr($file_data_array[$file_data_key]['local_version'], 0, $double_slash_position);
                    }
                    $file_data_array[$file_data_key]['local_version'] = trim(str_replace($cpg_version_determination, '', $file_data_array[$file_data_key]['local_version']));
                    $file_data_array[$file_data_key]['local_version'] = trim(str_replace('#', '', $file_data_array[$file_data_key]['local_version']));
                    $file_data_array[$file_data_key]['local_version'] = trim(substr($file_data_array[$file_data_key]['local_version'], 0, strpos($file_data_array[$file_data_key]['local_version'], '$')));
                    if (strlen($file_data_array[$file_data_key]['local_version']) > 6) {
                        // Version numbers larger than 6 are not likely at all
                        $file_data_array[$file_data_key]['local_version'] = 'n/a';
                    }
                    if ($file_data_array[$file_data_key]['version'] != '' && $file_data_array[$file_data_key]['exists'] == 1 && $file_data_array[$file_data_key]['local_version'] != '') {
                        $file_data_array[$file_data_key]['txt_version'] = ' (';
                        $versionCompare = version_compare($file_data_array[$file_data_key]['local_version'], $file_data_array[$file_data_key]['version']);
                        if ($versionCompare == 0) {
                            $file_data_array[$file_data_key]['txt_version'] .= $lang_versioncheck_php['ok'];
                        } elseif ($versionCompare == -1) {
                            $file_data_array[$file_data_key]['txt_version'] .= sprintf($lang_versioncheck_php['outdated'], $file_data_array[$file_data_key]['version']);
                            $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['review_version'] . '. ';
                        } else {
                            $file_data_array[$file_data_key]['txt_version'] .= sprintf($lang_versioncheck_php['newer'], $file_data_array[$file_data_key]['version']);
                            $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['review_dev_version'] . '. ';
                        }
                        $file_data_array[$file_data_key]['txt_version'] .= ')';
                    } else {
                        $file_data_array[$file_data_key]['txt_version'] = '';
                        //$file_data_array[$file_data_key]['local_version'] = '';
                    }
                    if (strlen($file_data_array[$file_data_key]['local_version'] . $file_data_array[$file_data_key]['txt_version']) > $maxLength_array['version']) {
                        $maxLength_array['version'] = strlen($file_data_array[$file_data_key]['local_version'] . $file_data_array[$file_data_key]['txt_version']);
                    }
                    // Determine file revision (only for files containing text)
                    if ($file_data_array[$file_data_key]['revision'] != '') {
                        // only look the revision up if a revision is given in the XML data
                        $file_data_array[$file_data_key]['local_revision'] = str_replace($revision_string, '', substr($blob, strpos($blob, $revision_string), 25));
                        $file_data_array[$file_data_key]['local_revision'] = trim(substr($file_data_array[$file_data_key]['local_revision'], 0, strpos($file_data_array[$file_data_key]['local_revision'], '$')));
                        if (strlen($file_data_array[$file_data_key]['local_revision']) > 5) {
                            // Check validity of revision: more than 5 chars is not expected
                            $file_data_array[$file_data_key]['local_revision'] = 'n/a';
                        }
                        if ($file_data_array[$file_data_key]['local_revision'] != '' && $file_data_array[$file_data_key]['exists'] == 1) {
                            //$file_data_array[$file_data_key]['local_revision'] = $file_data_array[$file_data_key]['revision'];
                            if ($file_data_array[$file_data_key]['local_revision'] == $file_data_array[$file_data_key]['revision']) {
                                $file_data_array[$file_data_key]['txt_revision'] .= ' (' . $lang_versioncheck_php['ok'];
                            } elseif ($file_data_array[$file_data_key]['local_revision'] < $file_data_array[$file_data_key]['revision']) {
                                $file_data_array[$file_data_key]['txt_revision'] .= ' (' . sprintf($lang_versioncheck_php['outdated'], $file_data_array[$file_data_key]['revision']);
                                if ($versionCompare == 0) {
                                    $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['review_version'] . '. ';
                                }
                            } else {
                                $file_data_array[$file_data_key]['txt_revision'] .= ' (' . sprintf($lang_versioncheck_php['newer'], $file_data_array[$file_data_key]['revision']);
                                if ($versionCompare == 0) {
                                    $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['review_dev_version'] . '. ';
                                }
                            }
                            $file_data_array[$file_data_key]['txt_revision'] .= ')';
                        } else {
                            $file_data_array[$file_data_key]['txt_revision'] = '';
                        }
                        if (strlen($file_data_array[$file_data_key]['local_revision'] . $file_data_array[$file_data_key]['txt_revision']) > $maxLength_array['revision']) {
                            $maxLength_array['revision'] = strlen($file_data_array[$file_data_key]['local_revision'] . $file_data_array[$file_data_key]['txt_revision']);
                        }
                    }
                }
                // the file is not binary --- end
                if (function_exists('md5') && $file_data_array[$file_data_key]['hash'] != '') {
                    // check the md5 hashes --- start
                    if ($file_data_array[$file_data_key]['version'] == $file_data_array[$file_data_key]['local_version'] && $file_data_array[$file_data_key]['revision'] == $file_data_array[$file_data_key]['local_revision']) {
                        // only perform the md5-check if the versions and revisions match anyway - we'd be comparing apples with bananas if we checked the hashes otherwise
                        $file_data_array[$file_data_key]['local_hash'] = md5($file_data_values['fullpath']);
                        if ($file_data_array[$file_data_key]['local_hash'] == $file_data_array[$file_data_key]['hash']) {
                            $file_data_array[$file_data_key]['unmodified'] = 1;
                        } else {
                            $file_data_array[$file_data_key]['unmodified'] = 0;
                            $file_data_array[$file_data_key]['txt_modified'] = $lang_versioncheck_php['modified'];
                            $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['review_modified'] . '. ';
                        }
                        if (strlen($file_data_array[$file_data_key]['txt_modified']) > $maxLength_array['modified']) {
                            $maxLength_array['modified'] = strlen($file_data_array[$file_data_key]['txt_modified']);
                        }
                    } else {
                        $file_data_array[$file_data_key]['txt_modified'] = 'n/a';
                    }
                }
                // check the md5 hashes --- end
            }
            $file_data_array[$file_data_key]['txt_folderfile'] = $lang_versioncheck_php['file'];
        }
        // we have a file here --- end
        if (strlen($file_data_array[$file_data_key]['txt_folderfile']) > $maxLength_array['folderfile']) {
            $maxLength_array['folderfile'] = strlen($file_data_array[$file_data_key]['txt_folderfile']);
        }
        if ($file_data_array[$file_data_key]['local_readwrite'] == 'read') {
            if ($file_data_array[$file_data_key]['permission'] == 'read') {
                $file_data_array[$file_data_key]['txt_readwrite'] .= ' (' . $lang_versioncheck_php['ok'] . ')';
            } elseif ($file_data_array[$file_data_key]['permission'] == 'write') {
                $file_data_array[$file_data_key]['txt_readwrite'] .= ' (' . $lang_versioncheck_php['needs_change'] . ')';
                $file_data_array[$file_data_key]['comment'] .= $lang_versioncheck_php['review_permissions'] . '. ';
            }
        } elseif ($file_data_array[$file_data_key]['local_readwrite'] == 'write') {
            $file_data_array[$file_data_key]['txt_readwrite'] = ' (' . $lang_versioncheck_php['ok'] . ')';
        } else {
            $file_data_array[$file_data_key]['txt_readwrite'] = '--';
        }
        if (strlen($file_data_array[$file_data_key]['local_readwrite'] . $file_data_array[$file_data_key]['txt_readwrite']) > $maxLength_array['readwrite']) {
            $maxLength_array['readwrite'] = strlen($file_data_array[$file_data_key]['local_readwrite'] . $file_data_array[$file_data_key]['txt_readwrite']);
        }
        if ($file_data_array[$file_data_key]['exists'] != 1) {
            $file_data_array[$file_data_key]['comment'] = sprintf($lang_versioncheck_php['review_missing'], ucfirst($file_data_array[$file_data_key]['txt_folderfile'])) . '. ';
        }
        // end the foreach loop
        $loopCounter++;
    }
    return $file_data_array;
}
コード例 #3
0
ファイル: bridgemgr.php プロジェクト: phill104/branches
     if ($BRIDGE['relative_path_of_forum_from_webroot'] != '' && $default_bridge_data[$BRIDGE['short_name']]['relative_path_of_forum_from_webroot_used'] != '') {
         // we have a db entry and the user appears to have it configured
         $redir_folder = $BRIDGE['relative_path_of_forum_from_webroot'];
     } elseif ($BRIDGE['relative_path_to_config_file'] != '' && $default_bridge_data[$BRIDGE['short_name']]['relative_path_to_config_file_used'] != '') {
         // we have a relative path. We'll use it if we don't have a folder already
         $redir_folder = $BRIDGE['relative_path_to_config_file'];
     } else {
         // something strange happened: there is no path set at all. We won't be able to write the file. Change the option to "display_only"
         $default_bridge_data[$BRIDGE['short_name']]['create_redir_file_action'] = @str_replace(',write', '', $default_bridge_data[$BRIDGE['short_name']]['create_redir_file_action']);
         $default_bridge_data[$BRIDGE['short_name']]['create_redir_file_action'] = @str_replace('write,', '', $default_bridge_data[$BRIDGE['short_name']]['create_redir_file_action']);
         $default_bridge_data[$BRIDGE['short_name']]['create_redir_file_action'] = @str_replace('write', '', $default_bridge_data[$BRIDGE['short_name']]['create_redir_file_action']);
         $redir_action = explode(',', $default_bridge_data[$BRIDGE['short_name']]['create_redir_file_action']);
     }
     // check if the redir file already exists
     print $redir_folder;
     $redir_folder_writable = cpg_is_writable($redir_folder);
     if ($redir_folder_writable == '-1') {
         // the redir folder is not writable
         print 'Not writable';
     }
 }
 // the file should be created --- end
 // display the option
 // temporarily removed this section, as it's still under construction
 print '<!--';
 print '<tr>' . $new_line;
 print '    <td class="tableb" colspan="2">' . $new_line;
 print '        <input type="checkbox" name="create_redir_file" id="create_redir_file" class="checkbox" value="1" checked="checked" />' . $new_line;
 print '        <label for="create_redir_file" class="clickable_option">' . $new_line;
 print '        <span class="explanation">' . $new_line;
 print '            ' . $lang_bridgemgr_php['create_redir_file'] . $new_line;
コード例 #4
0
ファイル: versioncheck.php プロジェクト: alencarmo/OCF
function cpg_get_fileversion($folder = '', $file = '')
{
    $handle = @fopen($folder . $file, 'r');
    $blob = @fread($handle, filesize($folder . $file));
    @fclose($handle);
    $cvs_string1 = '$' . 'I' . 'd' . ':';
    $cvs_string2 = '$' . 'Revision' . ':';
    $cpg_version_determination = 'Coppermine' . ' ' . 'version:';
    $blob = str_replace('<?php', '', $blob);
    // Determine the cpg version
    $return['cpg_version'] = substr($blob, strpos($blob, $cpg_version_determination));
    // chop off the first bit up to the string $cpg_version_determination
    $double_slash_position = strpos($return['cpg_version'], '//');
    if ($double_slash_position) {
        $return['cpg_version'] = substr($return['cpg_version'], 0, $double_slash_position);
    }
    $return['cpg_version'] = trim(str_replace($cpg_version_determination, '', $return['cpg_version']));
    $return['cpg_version'] = trim(str_replace('#', '', $return['cpg_version']));
    $return['cpg_version'] = trim(substr($return['cpg_version'], 0, strpos($return['cpg_version'], '$')));
    /*
    print $file;
    print ':<span style="color:red">';
    print $return['cpg_version'];
    print "</span>";
    print $double_slash_position;
    print "<br />\n";
    */
    if (strlen($return['cpg_version']) > 6) {
        $return['cpg_version'] = 'n/a';
    }
    // Fallback to the "old" cpg version determination method if no result (for compatibility with older versions)
    if ($return['cpg_version'] == '') {
        $return['cpg_version'] = substr($blob, strpos($blob, 'Coppermine Photo Gallery'));
        $return['cpg_version'] = substr($return['cpg_version'], 0, strpos($return['cpg_version'], '//'));
        $return['cpg_version'] = trim(str_replace('Coppermine Photo Gallery', '', $return['cpg_version']));
        if (strlen($return['cpg_version']) > 6) {
            $return['cpg_version'] = 'n/a';
        }
    }
    // Determine file (cvs) revision
    $return['cvs_version'] = str_replace($cvs_string2, '', substr($blob, strpos($blob, $cvs_string2), 25));
    $return['cvs_version'] = trim(substr($return['cvs_version'], 0, strpos($return['cvs_version'], '$')));
    // Fallback to the "old" revision determination method if no result (for compatibility with older versions)
    if ($return['cvs_version'] == '' || !is_numeric($return['cvs_version'])) {
        $return['cvs_version'] = substr($blob, strpos($blob, $cvs_string1));
        $return['cvs_version'] = substr($return['cvs_version'], 0, strpos($return['cvs_version'], 'Exp'));
        $return['cvs_version'] = str_replace($cvs_string1, '', $return['cvs_version']);
        // get rid of the filename inside the string
        $return['cvs_version'] = trim(str_replace($file . ',v ', '', $return['cvs_version']));
        $return['cvs_version'] = str_replace('v ', '', $return['cvs_version']);
        //if ($file=='picmgmt.inc.php' || $file=='index.php') {print $folder.$file.':'.$return['cvs_version'].'<br />';}
        $return['cvs_version'] = trim(str_replace(strstr($return['cvs_version'], ' '), '', $return['cvs_version']));
    }
    if (strlen($return['cvs_version']) > 5) {
        $return['cvs_version'] = 'n/a';
    }
    if (file_exists($folder . $file)) {
        $return['exists'] = 1;
    } else {
        $return['exists'] = 0;
    }
    if ($file == '') {
        //we have a folder here. Check if it's writable
        $return['writable'] = cpg_is_writable($folder);
    }
    // check for the existance of a folder
    $return['is_dir'] = 0;
    if ($file == '') {
        if ($handle = @opendir($folder . $file)) {
            $return['is_dir'] = 1;
            @closedir($handle);
        }
    }
    return $return;
}