-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmusify.php
104 lines (96 loc) · 3.76 KB
/
musify.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
<?php
// Musify, written by Corey Mwamba, Sep 2010. Licence: BY-NC-SA 3.0 - http://creativecommons.org/licenses/by-nc-sa/3.0/
// last change:13 Jul 2012 by Corey Mwamba: better tie symbols.
//
// For use in WordPress: remove the double slashes from the two lines below:
//$test = $atts['text'];
//echo musify($test);
// And then install the shortcode Exec PHP plugin from
// http://wordpress.org/extend/plugins/shortcode-exec-php/
// in your WordPress installation, you will see a menu option called "Shortcode Exec";
// select it, paste the contents of this file into the code window and SAVE.
function musify($text) {
$sharp = '<abbr title="sharp">♯</abbr>';
$dblsharp = '<abbr class="dblsharp" title="double sharp">✢</abbr>';
$flat = '<abbr title="flat">♭</abbr>';
$dim = '<sup class="musdim"><abbr title="diminished">°</abbr></sup>';
$hdim = '<sup class="mushdim"><abbr title="half-diminished">ø</abbr></sup>';
$ext1 = '<sup>(';
$ext2 = ')</sup>';
$var1 = '<sup>';
$var2 = '</sup>';
$chain = '×';
$plus = '+';
$tss = '<span class="musnum">';
$tsm = '</span>⁄<span class="musden">';
$ivm = '</span><span class="timden">';
$tri = 'Δ';
$tse = '</span>';
$u1 = '<sub>';
$u2 = '</sub>';
$simile = '<abbr title="simile">÷</abbr>';
$tied = '<span class="musitie">⏝</span>';
$tieu = '<span class="musotie">⏜</span>';
$br = '<br />';
$ellip = '…';
$nat = '<abbr title="natural">♮</abbr>';
$losq = '❬';
$rosq = '❭';
$text = html_entity_decode($text);
$text = htmlspecialchars_decode($text);
$text = str_replace('<|',$losq,$text);
$text = str_replace('|>',$rosq,$text);
$text = str_replace ('...', $ellip, $text);
$text = str_replace ( "£", $flat, $text);
$text = str_replace ( "$", $flat, $text);
$text = str_replace ( "€", $flat, $text);
$text = str_replace ( "¥", $flat, $text);
$text = str_replace ( "¤", $flat, $text);
$text = str_replace ( "%", $simile, $text);
$text = str_replace ( "#", $sharp, $text);
$text = str_replace($sharp.$sharp, $dblsharp, $text);
$text = str_replace ( "?", $nat, $text);
$text = str_replace ( "&".$sharp."247;", $simile, $text);
$text = str_replace ( "&".$sharp."8230;", $ellip, $text);
$text = str_replace ( "&".$sharp."9837;", $flat, $text);
$text = str_replace ( "&".$sharp."916;", "Δ", $text);
$text = str_replace ( "&".$sharp."215;", $chain, $text);
$text = str_replace ("&".$sharp."10092;", $losq, $text);
$text = str_replace ("&".$sharp."10093;", $rosq, $text);
$text = str_replace ( "~", $hdim, $text);
$text = str_replace ( "&".$sharp."176;", "&176;", $text);
$text = str_replace ( "_", $dim, $text);
$text = str_replace ( "*", $chain, $text);
$text = str_replace ( "+", $plus, $text);
$text = str_replace("((", $ext1, $text);
$text = str_replace("))", $ext2, $text);
$text = str_replace("[[", $var1, $text);
$text = str_replace("]]", $var2, $text);
$text = str_replace("[-", $u1, $text);
$text = str_replace("-]", $u2, $text);
$text = str_replace("{{", $tss, $text);
$text = str_replace("//", $tsm, $text);
$text = str_replace("@", $ivm, $text);
$text = str_replace("}}", $tse, $text);
$text = str_replace("==", $tieu, $text);
$text = str_replace("--", $tied, $text);
$text = str_replace("^", $tri, $text);
$text = str_replace ("!!", $br, $text);
$text = str_replace ('<abbr title="flat"><abbr title="flat">♭</abbr></abbr>', $flat, $text);
$text = str_replace ('<abbr title="simile"><abbr title="simile">÷</abbr></abbr>', $simile, text);
return $text;
}
function musify_tag($str) {
//so: change "[mus]musify markup[/mus]" to musical notation.
$pat = "/\[mus\](.*?)\[\/mus\]/";
$n = preg_match_all($pat,$str,$m);
preg_match_all($pat,$str,$m);
for ($i = 0;$i < $n;$i++) {
$mus[] = musify($m[1][$i]);
}
foreach ($m as $subj) {
$str = str_replace($subj,$mus,$str);
}
return $str;
}
?>musotie