PKG Rosetta: Check-in [2112ae4b63]

Codebase of pkg.deparis.io website, which helps you find concordance between Gnu/Linux or BSD packages name.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix various little glitches. Long time I didn't code in php
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:2112ae4b633f5d57fe21b28099fb3ae69a34eefe
User & Date: milouse 2016-03-08 15:07:41
Context
2016-03-08
15:40
Add links to distros packages ref manager. Needs refactoring and external configuration\! check-in: 1227006753 user: milouse tags: trunk
15:07
Fix various little glitches. Long time I didn't code in php check-in: 2112ae4b63 user: milouse tags: trunk
14:51
Initial commit, proof of something, which may become great check-in: 1cfcf52fef user: milouse tags: trunk
Changes

Changes to index.php.

5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
<h1>PKG Rosetta</h1>

<form action="search.php" method="get">
  <fieldset>
    <label for="query_field">
      Looking for
    </label>
    <input type="text" name="q" id="query_field">


    <br>

    <label for="output_field">
      Output format
    </label>
    <select name="f">
      <option value="html" selected>HTML</option>
      <option value="json">Json</option>
      <option value="txt">Plain text</option>
    </select>

    <br>








|
>






|







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<h1>PKG Rosetta</h1>

<form action="search.php" method="get">
  <fieldset>
    <label for="query_field">
      Looking for
    </label>
    <input type="text" name="q" id="query_field"
           value="<?php echo $_GET['q']; ?>">

    <br>

    <label for="output_field">
      Output format
    </label>
    <select name="f" id="output_field">
      <option value="html" selected>HTML</option>
      <option value="json">Json</option>
      <option value="txt">Plain text</option>
    </select>

    <br>

Changes to search.php.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
$distros_name = array('Archlinux', 'Debian', 'Ubuntu', 'CentOS', 'Fedora');

function print_plain_text($data){
  $content = '';
  for($i = 0; $i < sizeof($data); $i++){
    $content .= $distros_name[$i] . ': ' . $data[$i] . "\n";
  }
  $content .= "\n";
  return $content;
}

function print_json($data){
  $json_array = array();
  for($i = 0; $i < sizeof($data); $i++){
    $json_array[$distros_name[$i]] = $data[$i];

  }
  return json_encode($json_array) . "\n";
}

function print_html($data){
  $content = '<table><thead><tr>';
  foreach ($distros_name as $dn){
    $content .= '<th>' . $dn . '</th>';
  }
  $content .= '</tr></thead><tbody><tr>';
  foreach ($data as $d){
    $content .= '<td>' . $d . '</td>';
  }
  $content .= '</tr></tbody></table>';
  return $content;
}

$result = '';
if (!empty($_GET['q'])){
  $result = system(escapeshellcmd('grep ' . escapeshellarg($_GET['q']) . ' data.csv'));
}

$possible_formats = array('txt', 'json', 'html');
$output_format = 'html';
if (!empty($_GET['f']) && in_array($_GET['f'], $possible_formats)) {
  $output_format = $_GET['f'];
}

|




|








|
>






|












|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
define(DISTRO_NAMES, array('Archlinux', 'Debian', 'Ubuntu', 'CentOS', 'Fedora'));

function print_plain_text($data){
  $content = '';
  for($i = 0; $i < sizeof($data); $i++){
    $content .= DISTRO_NAMES[$i] . ': ' . $data[$i] . "\n";
  }
  $content .= "\n";
  return $content;
}

function print_json($data){
  $json_array = array();
  for($i = 0; $i < sizeof($data); $i++){
    $json_title = str_replace(' ', '_', strtolower(DISTRO_NAMES[$i]));
    $json_array[$json_title] = $data[$i];
  }
  return json_encode($json_array) . "\n";
}

function print_html($data){
  $content = '<table><thead><tr>';
  foreach (DISTRO_NAMES as $dn){
    $content .= '<th>' . $dn . '</th>';
  }
  $content .= '</tr></thead><tbody><tr>';
  foreach ($data as $d){
    $content .= '<td>' . $d . '</td>';
  }
  $content .= '</tr></tbody></table>';
  return $content;
}

$result = '';
if (!empty($_GET['q'])){
  $result = shell_exec(escapeshellcmd('grep ' . escapeshellarg($_GET['q']) . ' data.csv'));
}

$possible_formats = array('txt', 'json', 'html');
$output_format = 'html';
if (!empty($_GET['f']) && in_array($_GET['f'], $possible_formats)) {
  $output_format = $_GET['f'];
}