コード例 #1
0
ファイル: text.php プロジェクト: einervonvielen/hubzilla
function flatten_array_recursive($arr)
{
    $ret = array();
    if (!$arr) {
        return $ret;
    }
    foreach ($arr as $a) {
        if (is_array($a)) {
            $tmp = flatten_array_recursive($a);
            if ($tmp) {
                $ret = array_merge($ret, $tmp);
            }
        } elseif ($a) {
            $ret[] = $a;
        }
    }
    return $ret;
}
コード例 #2
0
ファイル: boot.php プロジェクト: einervonvielen/hubzilla
/**
 *
 * Wrap calls to proc_close(proc_open()) and call hook
 * so plugins can take part in process :)
 *
 * args:
 * $cmd program to run
 *  next args are passed as $cmd command line
 *
 * e.g.: proc_run("ls","-la","/tmp");
 *
 * $cmd and string args are surrounded with ""
 */
function proc_run()
{
    $args = func_get_args();
    $newargs = array();
    if (!count($args)) {
        return;
    }
    $args = flatten_array_recursive($args);
    $arr = array('args' => $args, 'run_cmd' => true);
    call_hooks('proc_run', $arr);
    if (!$arr['run_cmd']) {
        return;
    }
    if (count($args) && $args[0] === 'php') {
        $args[0] = x(App::$config, 'system') && x(App::$config['system'], 'php_path') && strlen(App::$config['system']['php_path']) ? App::$config['system']['php_path'] : 'php';
    }
    // redirect proc_run statements of legacy daemon processes to the newer Daemon Master object class
    // We will keep this interface until everybody has transitioned. (2016-05-20)
    if (strstr($args[1], 'include/')) {
        // convert 'include/foo.php' to 'Foo'
        $orig = substr(ucfirst(substr($args[1], 8)), 0, -4);
        logger('proc_run_redirect: ' . $orig);
        if (file_exists('Zotlabs/Daemon/' . $orig . '.php')) {
            array_shift($args);
            // daemons are all run by php, pop it off the top of the array
            $args[0] = $orig;
            // replace with the new daemon name
            logger('Redirecting old proc_run interface: ' . print_r($args, true), LOGGER_DEBUG, LOG_DEBUG);
            \Zotlabs\Daemon\Master::Summon($args);
            // summon the daemon
            return;
        }
    }
    $args = array_map('escapeshellarg', $args);
    $cmdline = implode($args, " ");
    if (is_windows()) {
        $cwd = getcwd();
        $cmd = "cmd /c start \"title\" /D \"{$cwd}\" /b {$cmdline}";
        proc_close(proc_open($cmd, array(), $foo));
    } else {
        if (get_config('system', 'use_proc_open')) {
            proc_close(proc_open($cmdline . " &", array(), $foo));
        } else {
            exec($cmdline . ' > /dev/null &');
        }
    }
}