Codes divers: Check-in [fe663be61d]

Divers bouts de code de ma composition

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

Overview
Comment:Remove old unshorten.php code
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:fe663be61d3dd1e774e0c591cd0046eba5caf368
User & Date: milouse 2020-03-11 08:21:28
Context
2020-03-13
22:01
Remove buddies.py as it is now hosted in its own repository check-in: f8e33b603a user: milouse tags: trunk
2020-03-11
08:21
Remove old unshorten.php code check-in: fe663be61d user: milouse tags: trunk
2020-02-25
19:33
Another improvement cycle on buddies.py check-in: cf6dbb4ff0 user: milouse tags: trunk
Changes

Changes to expe/unshorten.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

<?php
/**
 *            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 *                    Version 2, December 2004
 *
 * Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
 *
 * Everyone is permitted to copy and distribute verbatim or modified
 * copies of this license document, and changing it is allowed as long
 * as the name is changed.
 *
 *            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 *   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 *
 *  0. You just DO WHAT THE FUCK YOU WANT TO.
 */
$tinydomains = array(
  array('a.sgdf.fr', 'French scouts and guides association'),
  array('bddy.me', ''),
  array('bit.ly', ''),
  array('buff.ly', ''),
  array('dlvr.it', ''),
  array('ebx.sh', ''),
  array('fb.me', 'Facebook'),
  array('frama.link', 'Framasoft'),
  array('frphn.co', 'Fairphone'),
  array('go.onelink.me', 'AppsFlyer deep linking service'),
  array('goo.gl', 'Google'),
  array('h2fr.fr', 'Hauts de France, a France administrative region'),
  array('huit.re', 'Framasoft'),
  array('is.gd', ''),
  array('kck.st', 'Kickstarter'),
  array('lemde.fr', 'Le Monde, a french newspaper'),
  array('lnkd.in', 'Linkedin / Microsoft'),
  array('mzl.la', 'Mozilla'),
  array('ow.ly', ''),
  array('po.st', ''),
  array('t.co', 'Twitter'),
  array('tinyurl.com', ''),
  array('u.afp.com', 'AFP, the french press agency. Redir. to fr. newspapers'),
  array('ur1.ca', 'Old identi.ca shortening services'),
  array('vdn.lv', 'La Voix du Nord, a french newspaper')
);

if (isset($_GET['json'])) {
  header('Content-Type: application/json');
  if ($_GET['json'] == 'info') {
    $json_d = array_map(function ($i) {
      return '{"domain":"' . $i[0] . '","info":"' . $i[1] . '"}';
    }, $tinydomains);
    echo '[' . join(', ', $json_d) . ']';
  } else {
    $json_d = array_map(function ($i) { return $i[0]; }, $tinydomains);
    echo '["' . join('", "', $json_d) . '"]';
  }
  exit;

} else if (isset($_GET['url'])) {
  $tinyurl = $_GET['url'];
  $pipedtd = join('|', array_map(
    function ($i) { return $i[0]; }, $tinydomains));
  $tinyregexp = "/^https?:\/\/(?:$pipedtd)\/[a-zA-Z0-9_]+$/";
  if (preg_match($tinyregexp, $tinyurl) !== 1) {
    echo $tinyurl;
    exit;
  }
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $tinyurl);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
  curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
  curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLOPT_NOBODY, true);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
  $output = curl_exec($ch);
  curl_close($ch);
  if (preg_match_all('/^location: (https?:\/\/.*)/im', $output, $matches) !== false) {
    $tinyurl = array_pop($matches[1]);
  }
  echo $tinyurl;
  exit;
}
?>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Unshorten tiny URLs</title>

<h1>Unshorten tiny URLs</h1>

<form action="unshorten.php" method="get">
  <fieldset>
    <label for="tiny_url_field">
      Short URL:
    </label>
    <br>
    <input name="url" type="text"
           id="tiny_url_field" style="width:300px;"
           placeholder="https://t.co/QmQGE3SgEJ">
    <input type="submit" value="Expand">
  </fieldset>
</form>

<p style="font-size: smaller;color: gray;">
  <?php
  $dl = array_map(function ($i) {
    if ($i[1] == '') return $i[0];
    return $i[0] . ' (' . $i[1] . ')';
  }, $tinydomains);
  ?>
  (Supported services: <?php echo join(', ', $dl) ?>)
</p>

<h2>API</h2>

<dl>
  <dt><code>/unshorten.php?json</code></dt>
  <dd>gives you the list of supported domains as an array.</dd>
  <dt><code>/unshorten.php?json=info</code></dt>
  <dd>gives you the list of supported domains, as an array of objects,
    with the domain in the <code>domain</code> property and
    complementary information in the <code>info</code> property.</dd>
</dl>

<footer>
  <p style="font-size: smaller;">
    Author&nbsp;: <a href="https://etienne.depar.is">Étienne Deparis</a> –
    License <a href="http://www.wtfpl.net/txt/copying/">WTFPL</a> –
    <a href="https://gist.github.com/milouse/11104731f2184c4cf84376e9b5fecd85">source</a>
  </p>
</footer>

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>




















































































1














































2




















































































<!DOCTYPE html>














































<meta http-equiv="refresh" content="0; url=https://unshorten.deparis.io">