-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpw-duolingo-data.php
97 lines (93 loc) · 6.36 KB
/
pw-duolingo-data.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
<?php
/*
Plugin Name: Duolingo Data
Plugin URI: http://polyglotwannabe.com/
Description: Retrieves data from the unofficial Duolingo API for Python (https://github.com/KartikTalwar/Duolingo)
Version: 1.0
Author: Lidia Cirrone
Author URI: http://polyglotwannabe.com/
*/
function flag_icons_styles()
{
global $post;
if (is_page('duolingo') || has_shortcode( $post->post_content, 'pw_duolingo_data')) {
wp_enqueue_style('flag-icons-main', plugins_url('pw-duolingo-data') . '/flag-icons-main/css/flag-icons.min.css', array(), null);
}
}
add_action('wp_enqueue_scripts', 'flag_icons_styles');
add_shortcode('pw_duolingo_data', 'duolingo_api_call');
function duolingo_api_call($attributes)
{
$command = escapeshellarg(__DIR__ . '\pw-load-api.py');
$output = shell_exec($command);
$duo = json_decode($output);
$all_languages = $duo->all_languages;
ob_start();
?>
<div class="card">
<div class="card-body small">
<h5 class="card-title mb-3">
<img src="<?php echo $duo->avatar; ?>" class="img-fluid rounded-circle w-20 me-2" alt="avatar">
<a href="https://www.duolingo.com/lidiaCirrone" target="_href"><?php echo $duo->username; ?></a>
</h5>
<p class="card-subtitle text-pastel mt-0">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-hourglass-top" viewBox="0 0 16 16">
<path d="M2 14.5a.5.5 0 0 0 .5.5h11a.5.5 0 1 0 0-1h-1v-1a4.5 4.5 0 0 0-2.557-4.06c-.29-.139-.443-.377-.443-.59v-.7c0-.213.154-.451.443-.59A4.5 4.5 0 0 0 12.5 3V2h1a.5.5 0 0 0 0-1h-11a.5.5 0 0 0 0 1h1v1a4.5 4.5 0 0 0 2.557 4.06c.29.139.443.377.443.59v.7c0 .213-.154.451-.443.59A4.5 4.5 0 0 0 3.5 13v1h-1a.5.5 0 0 0-.5.5zm2.5-.5v-1a3.5 3.5 0 0 1 1.989-3.158c.533-.256 1.011-.79 1.011-1.491v-.702s.18.101.5.101.5-.1.5-.1v.7c0 .701.478 1.236 1.011 1.492A3.5 3.5 0 0 1 11.5 13v1h-7z" />
</svg>
created on <?php echo $duo->creation_date; ?>
</p>
<p class="card-subtitle text-pastel mt-0">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-calendar-week" viewBox="0 0 16 16">
<path d="M11 6.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-1zm-3 0a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-1zm-5 3a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-1zm3 0a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-1z" />
<path d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM1 4v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4H1z" />
</svg>
<?php echo $duo->streak; ?> day streak
</p>
<p class="card-subtitle text-pastel mt-0">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-lightning-charge" viewBox="0 0 16 16">
<path d="M11.251.068a.5.5 0 0 1 .227.58L9.677 6.5H13a.5.5 0 0 1 .364.843l-8 8.5a.5.5 0 0 1-.842-.49L6.323 9.5H3a.5.5 0 0 1-.364-.843l8-8.5a.5.5 0 0 1 .615-.09zM4.157 8.5H7a.5.5 0 0 1 .478.647L6.11 13.59l5.732-6.09H9a.5.5 0 0 1-.478-.647L9.89 2.41 4.157 8.5z" />
</svg>
<?php echo $duo->xp; ?> total xp
</p>
<p class="card-subtitle text-pastel mt-0">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chat-text" viewBox="0 0 16 16">
<path d="M2.678 11.894a1 1 0 0 1 .287.801 10.97 10.97 0 0 1-.398 2c1.395-.323 2.247-.697 2.634-.893a1 1 0 0 1 .71-.074A8.06 8.06 0 0 0 8 14c3.996 0 7-2.807 7-6 0-3.192-3.004-6-7-6S1 4.808 1 8c0 1.468.617 2.83 1.678 3.894zm-.493 3.905a21.682 21.682 0 0 1-.713.129c-.2.032-.352-.176-.273-.362a9.68 9.68 0 0 0 .244-.637l.003-.01c.248-.72.45-1.548.524-2.319C.743 11.37 0 9.76 0 8c0-3.866 3.582-7 8-7s8 3.134 8 7-3.582 7-8 7a9.06 9.06 0 0 1-2.347-.306c-.52.263-1.639.742-3.468 1.105z" />
<path d="M4 5.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zM4 8a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7A.5.5 0 0 1 4 8zm0 2.5a.5.5 0 0 1 .5-.5h4a.5.5 0 0 1 0 1h-4a.5.5 0 0 1-.5-.5z" />
</svg>
<?php echo $duo->learning_language->string; ?>
</p>
<p class="card-subtitle text-pastel mt-0">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-bar-chart" viewBox="0 0 16 16">
<path d="M4 11H2v3h2v-3zm5-4H7v7h2V7zm5-5v12h-2V2h2zm-2-1a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h2a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1h-2zM6 7a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V7zm-5 4a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1v-3z" />
</svg>
level <?php echo $duo->learning_language->level; ?> (<?php echo $duo->learning_language->level_percent; ?>%)
</p>
<div class="card-text my-3">
all the languages I've been studying on Duolingo up until now:<br>
<?php
foreach ($all_languages as $source => $target) {
if ($source == 'da') : ($source = 'dk');
endif;
if ($source == 'en') : ($source = 'gb');
endif; ?>
<span class="flag-icon flag-icon-<?php echo $source; ?> align-middle"></span>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-right-short" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z" />
</svg>
<?php foreach ($target as $lang) {
if ($lang == 'da') : ($lang = 'dk');
endif;
if ($target == 'en') : ($target = 'gb');
endif; ?>
<span class="flag-icon flag-icon-<?php echo $lang; ?> align-middle"></span>
<?php } ?>
<br>
<?php } ?>
</div>
- <a href="https://www.duolingo.com/lidiaCirrone" target="_href" class="card-link">my profile</a><br>
- <a href="https://duome.eu/lidiaCirrone" target="_href" class="card-link">more statistics on duome.eu</a>
</div>
</div>
<?php
return ob_get_clean();
}