/**
  * Execute the command
  *
  * @param Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output
  * @return void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Searching...</info>');
     $handle = $this->transcriber->loadCmuFile();
     $strings = explodeByComma($input->getArgument('word'));
     $this->makeOptions();
     $this->setOptionsField('destination', $input->getOption('destination'));
     $this->setOptionsField('fields', explodeByComma($input->getOption('fields')));
     $this->setOptionsField('file_name', $input->getOption('file'));
     $this->setOptionsField('hyphenate', $input->getOption('hyphenate'));
     $this->setOptionsField('multiple', $input->getOption('multiple'));
     $this->setOptionsField('symbol', $input->getOption('symbol'));
     $this->setOptionsField('method_names', $this->builder->buildFieldMethods($this->options['fields']));
     if (!$handle) {
         $GLOBALS['status'] = 1;
         die('<error>File did not open properly</error>');
     }
     $answers = [];
     $answered = [];
     while (($line = fgets($handle)) !== false) {
         if (isComment($line)) {
             continue;
         }
         $exploded_line = explode(' ', $line);
         $word = trim($exploded_line[0]);
         $word = $this->parseDuplicateEntries($word);
         if (in_array($word, $strings)) {
             $output_word = $this->hyphenateOutputWord($this->hyphenator, $word);
             $output_word = $this->setHyphenationSymbol($output_word);
             $key = $this->makeAnswersKey($word, $answers);
             $answers[$key] = $this->makeLookupOutputArray($output, $output_word, $exploded_line);
             array_push($answered, $word);
         }
     }
     if ($GLOBALS['status'] !== 0) {
         return null;
     }
     $unanswered = array_diff($strings, $answered);
     $destination_method = $this->builder->buildDestinationMethod($this->options['destination']);
     if (!method_exists($this, $destination_method)) {
         $output->writeln("<error>Incorret destination input</error>");
         $output->writeln("<info>Destination options: </info><comment>table,string,file,database</comment>");
         $GLOBALS['status'] = 1;
         return null;
     }
     $this->{$destination_method}($output, $answers);
     $this->displayErrorForUnanswered($output, $unanswered);
     fclose($handle);
 }
Exemple #2
0
            // echo "</pre>";
            if ($partie['notes']) {
                foreach ($partie['notes'] as $file) {
                    $fd = fopen('xml/note/' . $file . '.note', 'r');
                    while (!feof($fd)) {
                        $line1 = fgets($fd);
                        if ($cpt == 0) {
                            if (match_tag('titre', $line1)) {
                                fputs($fdc, "<titre>" . extract_text('titre', $line1) . " [Compilation]</titre>\n");
                            } else {
                                if (!match_tag('note', $line1) and !match_tag('meta_note', $line1) and !match_tag('statut', $line1) and !match_tag('date_creation', $line1) and !match_tag('date_modification', $line1) and !match_tag('auteur', $line1) and !match_tag('contributeurs', $line1) and !match_tag('contributeur', $line1) and !match_tag('relecteur', $line1) and !match_tag('nom', $line1) and !match_tag('prenom', $line1) and !isComment($line1)) {
                                    fputs($fdc, $line1);
                                }
                            }
                        } else {
                            if (!match_tag('note', $line1) and !match_tag('meta_note', $line1) and !match_tag('statut', $line1) and !match_tag('date_creation', $line1) and !match_tag('date_modification', $line1) and !match_tag('auteur', $line1) and !match_tag('contributeurs', $line1) and !match_tag('contributeur', $line1) and !match_tag('relecteur', $line1) and !match_tag('nom', $line1) and !match_tag('prenom', $line1) and !match_tag('titre', $line1) and !isComment($line1)) {
                                fputs($fdc, $line1);
                            }
                        }
                    }
                    $cpt++;
                }
            }
            fputs($fdc, '</partie>');
        }
        fputs($fdc, '</note>');
        $xml_filename = "xml/note/{$titre}.note";
        header('Location: http://localhost/wikiutc/pdf.php?id=' . $xml_filename . '&gen=1');
    }
}
?>
Exemple #3
0
 function archive2app__process($values)
 {
     require_once 'Archive/Tar.php';
     if (preg_match('/\\.gz$/', $_FILES['archive']['name'])) {
         $compression = 'gz';
     } else {
         $compression = null;
     }
     $archive = new Archive_Tar($_FILES['archive']['tmp_name'], $compression);
     $files = $archive->listContent();
     foreach ($files as $file) {
         if (!preg_match('/(\\.ini)|(\\.php)$/', $file['filename'])) {
             continue;
         }
         $content = $archive->extractInString($file['filename']);
         $content = str_replace(array('%%DATAFACE_URL%%', '%%DATAFACE_PATH%%', '%%MYSQL_USER%%', '%%MYSQL_PASSWORD%%', '%%MYSQL_HOST%%', '%%MYSQL_DATABASE_NAME%%'), array(addslashes(dirname($_SERVER['PHP_SELF'])), addslashes(dirname(__FILE__)), addslashes($values['mysql_user']), addslashes($values['mysql_password']), addslashes(DB_HOST), addslashes($values['database_name'])), $content);
         $archive->addString($file['filename'], $content);
     }
     $root = $files[0]['filename'];
     $install = $archive->extractInString($root . 'install/install.sql');
     $res = mysql_select_db($values['database_name'], db());
     if (!$res) {
         $dbname = str_replace('`', '', $values['database_name']);
         $res = mysql_query("create database `" . addslashes($dbname) . "`", db());
         if (!$res) {
             return PEAR::raiseError("Failed to create database '{$dbname}'");
         }
         $res = mysql_select_db($dbname);
         if (!$res) {
             return PEAR::raiseError("Problem selecting database {$dbname}.");
         }
     }
     if ($install) {
         $installFile = tempnam(null, 'install.sql');
         file_put_contents($installFile, $install);
         $file = file($installFile);
         $queries = array();
         $ctr = 0;
         foreach ($file as $line) {
             if (isComment($line)) {
                 continue;
             }
             $queries[$ctr] .= $line;
             $trimmed = trim($line);
             if ($trimmed[strlen($trimmed) - 1] == ';') {
                 $ctr++;
             }
         }
         //$file = implode("",$out);
         foreach ($queries as $query) {
             $res = @mysql_query($query, $db);
             if (!$res) {
                 $my_errs[] = mysql_error($db);
             }
         }
     }
     switch ($values['install_type']) {
         case 'ftp_install':
             //echo 'here';
             require_once 'install/FTPExtractor.class.php';
             $extractor = new FTPExtractor($archive);
             $res = $extractor->connect($values['ftp_host'], $values['ftp_username'], $values['ftp_password']);
             if (PEAR::isError($res)) {
                 die($res->getMessage());
             }
             $res = $extractor->extract($values['ftp_path'], '/');
             //if ( PEAR::isError($res) ){
             //	die($res->getMessage());
             //}
             $context = array();
             if (PEAR::isError($res)) {
                 $context['result'] = 'Error: ' . $res->getMessage();
             } else {
                 $context = $res;
             }
             include 'install' . DIRECTORY_SEPARATOR . 'archive2app-results.inc.php';
             exit;
         default:
             // download_tarball
             $tarpath = $_FILES['archive']['tmp_name'];
             if ($compression == 'gz') {
                 $mimetype = 'application/x-gzip';
             } else {
                 $mimetype = 'application/x-tar';
             }
             header('Content-type: ' . $mimetype);
             header('Content-Disposition: attachment; filename="' . basename($_FILES['archive']['name']) . '.tar.gz"');
             echo file_get_contents($tarpath);
             exit;
     }
 }
 /**
  * Write all to database
  *
  * @param Symfony\Component\Console\Output\OutputInterface $output, resource $handle
  * @return void
  */
 protected function writeToDatabase(OutputInterface $output, $handle)
 {
     $connect = $this->getDatabaseConnection($output);
     $output_handle = $connect->handle();
     $statement = null;
     while (($line = fgets($handle)) !== false) {
         if (isComment($line)) {
             continue;
         }
         $exploded_line = explode(' ', $line);
         $word = trim($exploded_line[0]);
         $word = $this->parseDuplicateEntries($word);
         $answer = $this->makeAllOutputArray($output, $word, $exploded_line);
         if (is_null($statement)) {
             $statement_fields = [];
             foreach (array_keys($answer) as $statement_field) {
                 array_push($statement_fields, $statement_field);
             }
             $statement = $connect->statement($output_handle, $statement_fields);
         }
         $connect->executeStatement($statement, $answer);
     }
     $output->writeln("<info>Successfully wrote to database</info>");
     $handle = null;
 }