Example #1
0
<?php

include '../inc/init.php';
$term = fRequest::get('term', 'string');
if ($GLOBALS['PRIMARY_SOURCE'] == 'GANGLIA') {
    if ($GLOBALS['GANGLIA_URL'] != '') {
        $json = file_get_contents($GLOBALS['GANGLIA_URL'] . '/tattle_autocomplete.php?term=' . $term);
        print $json;
    }
} else {
    $path = str_replace('.', '/', fRequest::get('term', 'string'));
    $return_arr = array();
    if ($GLOBALS['GRAPHITE_AUTOCOMPLETE_RECURSIVE'] == true) {
        $dir = new fDirectory($GLOBALS['WHISPER_DIR']);
        $directories = $dir->scanRecursive($path . '*');
    } else {
        $searchPattern = "*";
        if (!file_exists($GLOBALS['WHISPER_DIR'] . $path)) {
            $dirParts = explode("/", $path);
            $searchPattern = array_pop($dirParts) . $searchPattern;
            $path = implode("/", $dirParts);
        }
        $dir = new fDirectory($GLOBALS['WHISPER_DIR'] . $path);
        $directories = $dir->scan($searchPattern);
    }
    foreach ($directories as $directory) {
        $return_arr[] = array('value' => str_replace('.wsp', '', str_replace('/', '.', str_replace($GLOBALS['WHISPER_DIR'], '', $directory->getPath()))));
    }
    print json_encode($return_arr);
}
Example #2
0
 public function testScanDirs()
 {
     $this->createScannableFiles();
     $dir = new fDirectory('output/fDirectory_scan/');
     $files = $dir->scan('#/$#');
     $filenames = array();
     foreach ($files as $file) {
         $filenames[] = str_replace($dir->getPath(), '', $file->getPath());
     }
     $this->assertEquals(array('subdir' . DIRECTORY_SEPARATOR), $filenames);
 }
 public function testScanRegex()
 {
     $this->createScannableFiles();
     $dir = new fDirectory('output/fDirectory_scan/');
     $files = $dir->scan('#file#i');
     $filenames = array();
     foreach ($files as $file) {
         $filenames[] = str_replace($dir->getPath(), '', $file->getPath());
     }
     $this->assertEquals(array('file', 'file.csv', 'file.txt', 'file1.txt', 'fIle2.txt'), $filenames);
 }
Example #4
0
    $db->query($sql);
    $sql = "ALTER TABLE `patch_history` ADD PRIMARY KEY `num` (`num`)";
    $db->query($sql);
    $sql = "INSERT INTO `patch_history` SET `num` = 0";
    $db->query($sql);
}
// Get the last patch level
$sql = "SELECT MAX(num) AS num FROM patch_history";
$row = $db->query($sql)->fetchRow();
$num = (int) $row['num'];
// Next patch to install
$next = $num + 1;
echo "Current patch level: {$num}.<br>";
// Get the highest patch level available
$patch_dir = new fDirectory(DOC_ROOT . '/db');
$patch_files = $patch_dir->scan('patch*.sql');
foreach ($patch_files as $file) {
    // Get patch number from filename
    preg_match('/patch([0-9]+).sql/', $file->getName(), $matches);
    $patch_num = $matches[1];
    // If it's at the right level, run it.
    if ($patch_num >= $next) {
        echo "Running " . $file->getName() . "... ";
        $contents = $file->read();
        try {
            $db->query($contents);
            $db->query("INSERT INTO patch_history SET num = %i ON DUPLICATE KEY UPDATE num = VALUES(num);", $patch_num);
            echo "OK!<br>";
        } catch (fException $e) {
            echo "Error: " . $e->getMessage() . "<br>";
        }