protected function convertHtml($html) { $chain = new Chain(ProcessBuilder::create(array('echo', $html))); $chain->add('|', ProcessBuilder::create(array('html2wiki', '--dialect', 'MediaWiki'))); $process = $chain->getProcess(); $process->run(); $html = $process->getOutput(); //Don't use <br> $html = str_replace('<br />', PHP_EOL, $html); //Trim each line $html = implode(PHP_EOL, array_map('trim', explode(PHP_EOL, $html))); //Convert sources $html = preg_replace('/\\s*\\(?source\\s*:([^)]+)\\)?/i', '<ref>$1</ref>', $html); return $html; }
/** * Get audio stream of converted video. * * @param string $url URL of page * @param string $format Format to use for the video * * @return resource popen stream */ public function getAudioStream($url, $format) { if (!shell_exec('which ' . $this->config->avconv)) { throw new \Exception('Can\'t find avconv or ffmpeg'); } $video = $this->getJSON($url, $format); //Vimeo needs a correct user-agent ini_set('user_agent', $video->http_headers->{'User-Agent'}); $avconvProc = ProcessBuilder::create([$this->config->avconv, '-v', 'quiet', '-i', '-', '-f', 'mp3', '-vn', 'pipe:1']); if (parse_url($video->url, PHP_URL_SCHEME) == 'rtmp') { $process = $this->getRtmpProcess($video); } else { $process = $this->getCurlProcess($video); } $chain = new Chain($process); $chain->add('|', $avconvProc); return popen($chain->getProcess()->getCommandLine(), 'r'); }
protected function importDatabase($databaseName, $inputFilePath, OutputInterface $output) { $builder = new ProcessBuilder(); $builder->setPrefix($this->get('commands.mysql.path', $output)); $arguments = ['-h' . $this->get('db.host', $output), '-u' . $this->get('db.username', $output), '-p' . $this->get('db.password', $output)]; if ($this->get('db.port', $output) > 0) { $arguments[] = '--port=' . $this->get('db.port', $output); } $arguments[] = $databaseName; $databaseProcess = $builder->setArguments($arguments)->getProcess(); $chain = new Chain($databaseProcess); $chain->add('<', $inputFilePath); //$output->writeln($databaseProcess->getCommandLine()); $chainProcess = $chain->getProcess(); $chainProcess->run(); // executes after the command finishes return $chainProcess->isSuccessful(); }