-
Notifications
You must be signed in to change notification settings - Fork 10
/
cassis-lab.php
130 lines (114 loc) · 4.58 KB
/
cassis-lab.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
<?php
/*
cassis-lab.php Copyright 2018-2023 Tantek Çelik https://tantek.com/
Part of cassisproject.com
license: https://creativecommons.org/licenses/by-sa/4.0/
This is a PHP-only staging file for functions that would work well
as CASSIS functions but which I have not yet found use-cases
for client-side usage.
All code is experimental at best!
*/
// ----------
// independent functions - only depend on PHP
// *heuristic* function. file issues for real world use-case fails.
function is_one_emoji($s) {
$n = strlen($s);
if ($n>25) return false;
if (ord($s[0]) == 226) // older emoji with optional variant
return (3 == $n ||
(6 == $n && ord($s[3]) == 239 && ord($s[4]) == 184));
if (ord($s[0]) != 240) return false;
if (7 == $n && ord($s[4]) == 239 && ord($s[5]) == 184)
return true; // modern emoji with simple variant
if (8 == $n &&
ord($s[4]) == 240 && ord($s[5]) == 159 && ord($s[6]) == 143) return true; // modern emoji with skin tone
if (13 == $n &&
ord($s[4]) == 226 && ord($s[5]) == 128 && ord($s[6]) == 141 &&
ord($s[7]) == 226 && ord($s[8]) == 153 &&
ord($s[10]) == 239 && ord($s[11]) == 184)
return true; // modern emoji with gender variant
$i = 0;
while ($i<$n &&
(ord($s[$i]) == 240 &&
($i+4 == $n ||
($i+6 < $n &&
ord($s[$i+4]) == 226 && ord($s[$i+5]) == 128 && ord($s[$i+6]) == 141)))) {
if ($i+4 == $n) return true; // modern composite emoji
$i += 7;
}
return (ord($s[$i])==240 && $i+4==$n);
}
// ----------
// CASSIS dependent functions - depend on cassis.js behing loaded
/* auto_url_summary */
function auto_url_summary($u) {
// in: $u is a post permalink url
// out: text summary based on url, can be appended to e.g. "↳ In reply to " for a minimal readable reply-context
$hn = hostname_of_uri($u);
$ss = explode('.', $hn);
$s = $ss[count($ss) - 2];
if ($s == 'github') {
// comment, issue, pull request
if (fragment_of_uri($u) != '') {
if (segment_of_uri(3, $u) == 'issues')
return strcat('a comment on issue ',
segment_of_uri(4, $u), ' of GitHub project “',
segment_of_uri(2, $u), '”');
if (segment_of_uri(3, $u) == 'pull') {
if (substr(fragment_of_uri($u), 0, 17) == 'pullrequestreview') {
return strcat('a review on pull request ',
segment_of_uri(4, $u), ' to GitHub project “',
segment_of_uri(2, $u), '”');
} else {
return strcat('a comment on pull request ',
segment_of_uri(4, $u), ' to GitHub project “',
segment_of_uri(2, $u), '”');
}
}
return strcat('a comment on GitHub project “',
segment_of_uri(2, $u), '”');
}
if (segment_of_uri(3, $u) == 'pull')
return strcat('pull request ', segment_of_uri(4, $u),
' to GitHub project “',
segment_of_uri(2, $u), '”');
if (segment_of_uri(3, $u) == 'issues' && segment_of_uri(4, $u) != '')
return strcat('issue ', segment_of_uri(4, $u),
' of GitHub project “',
segment_of_uri(2, $u), '”');
if (segment_of_uri(2, $u) != '')
return strcat('GitHub project “',
segment_of_uri(2, $u), '”');
}
if ($s == 'twitter') {
return strcat('@', segment_of_uri(1, $u),'’s tweet');
}
if ($s == 'facebook') {
if (segment_of_uri(1, $u) == 'events')
return "a Facebook event";
if (segment_of_uri(2, $u) == 'photos')
return strcat(segment_of_uri(1, $u),'’s photo');
if (segment_of_uri(2, $u) == 'posts')
return strcat(segment_of_uri(1, $u),'’s post');
}
if ($s == 'eventbrite')
return "an Eventbrite event";
if ($s == 'upcoming' && segment_of_uri(1, $u) == 'event')
return "an Upcoming event";
if ($s == 'calagator' && segment_of_uri(1, $u) == 'events')
return "a Calagator event";
if ($s == 'indieweb') {
if ((segment_of_uri(1, $u) == 'events' || $ss[0] == 'events')
&& segment_of_uri(2, $u) != '')
return "an IndieWeb event";
if (count($ss) == 3 && ctype_digit($ss[0]))
return "an IndieWeb event";
return "an IndieWeb page";
// TBI different IndieWeb pages
}
// TBI: if $u has fragmention, synthesize quote from it
// per http://www.kevinmarks.com/mentionquote.html
return strcat(hostname_of_uri($u),
(path_of_uri($u)!='/') ? '’s post' : '');
}
?>