예제 #1
0
 function glob_r($pattern, $flags = 0)
 {
     $files = glob($pattern, $flags);
     foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
         $files = array_merge($files, glob_r($dir . '/' . basename($pattern), $flags));
     }
     return $files;
 }
예제 #2
0
function glob_r($pattern, $flags = 0)
{
    $override = apply_filters('pre_glob_r', false, $pattern, $flags);
    if ($override !== false) {
        return $override;
    }
    $files = glob($pattern, $flags);
    foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
        $files = array_merge($files, glob_r($dir . '/' . basename($pattern), $flags));
    }
    return $files;
}
예제 #3
0
function search_theme_files()
{
    if (!wp_verify_nonce($_POST['nonce'], 'nebula_ajax_nonce')) {
        die('Permission Denied.');
    }
    ini_set('max_execution_time', 120);
    ini_set('memory_limit', '512M');
    $searchTerm = stripslashes($_POST['data'][0]['searchData']);
    if (strlen($searchTerm) < 3) {
        echo '<p><strong>Error:</strong> Minimum 3 characters needed to search!</p>';
        die;
    }
    if ($_POST['data'][0]['directory'] == 'theme') {
        $dirpath = get_template_directory();
    } elseif ($_POST['data'][0]['directory'] == 'parent') {
        $dirpath = get_template_directory();
    } elseif ($_POST['data'][0]['directory'] == 'child') {
        $dirpath = get_stylesheet_directory();
    } elseif ($_POST['data'][0]['directory'] == 'plugins') {
        $dirpath = WP_PLUGIN_DIR;
    } elseif ($_POST['data'][0]['directory'] == 'uploads') {
        $uploadDirectory = wp_upload_dir();
        $dirpath = $uploadDirectory['basedir'];
    } else {
        echo '<p><strong>Error:</strong> Please specify a directory to search!</p>';
        die;
    }
    echo '<p class="resulttext">Search results for <strong>"' . $searchTerm . '"</strong> in the <strong>' . $_POST['data'][0]['directory'] . '</strong> directory:</p><br />';
    $file_counter = 0;
    $instance_counter = 0;
    foreach (glob_r($dirpath . '/*') as $file) {
        $counted = 0;
        if (is_file($file)) {
            if (strpos(basename($file), $searchTerm) !== false) {
                echo '<p class="resulttext">' . str_replace($dirpath, '', dirname($file)) . '/<strong>' . basename($file) . '</strong></p>';
                $file_counter++;
                $counted = 1;
            }
            $skipFilenames = array('error_log');
            if (!contains(basename($file), skip_extensions()) && !contains(basename($file), $skipFilenames)) {
                foreach (file($file) as $lineNumber => $line) {
                    if (stripos(stripslashes($line), $searchTerm) !== false) {
                        $actualLineNumber = $lineNumber + 1;
                        echo '<div class="linewrap">
								<p class="resulttext">' . str_replace($dirpath, '', dirname($file)) . '/<strong>' . basename($file) . '</strong> on <a class="linenumber" href="#">line ' . $actualLineNumber . '</a>.</p>
								<div class="precon"><pre class="actualline">' . trim(htmlentities($line)) . '</pre></div>
							</div>';
                        $instance_counter++;
                        if ($counted == 0) {
                            $file_counter++;
                            $counted = 1;
                        }
                    }
                }
            }
        }
    }
    echo '<br /><p class="resulttext">Found ';
    if ($instance_counter) {
        echo '<strong>' . $instance_counter . '</strong> instances in ';
    }
    echo '<strong>' . $file_counter . '</strong> file';
    echo $file_counter == 1 ? '.</p>' : 's.</p>';
    exit;
}