-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patharabic-ligature.php
150 lines (128 loc) · 5.5 KB
/
arabic-ligature.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/**
* Plugin Name: Arabic Ligature
* Plugin URI: http://wordpress.org/plugins/arabic-ligature/
* Description: Arabic Ligature will encode common Arabic phrases to respective Ligature using Unicode representation.
* Version: 0.2.0
* Author: Azizur Rahman
* Author URI: http://azizur.com
* License: GPLv2 or later
*/
/* Copyright (c) 2013 Azizur Rahman (email: [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class arabic_ligature {
const UNICODE_CODE = 0;
const UNICODE_HTML_DEC = 1;
const UNICODE_HTML_HEX = 2;
const UNICODE_HTML_URL = 3;
private $_ligature_map;
private $_ligatures = array(
array( // bismillah ar-rahman ar-raheem
// shortcode
array('bismillah', 'basmala'),
// meta: array('Unicode Code Point','HTML Entity (Decimal)','HTML Entity (Hexadecimal)','URL Escape Code')
array('U+FDFD', '﷽', '﷽', '%EF%B7%BD'),
// arabic
'بسم الله الرحمن الرحيم',
'bismi-llāhi r-raḥmāni r-raḥīm',
'In the name of God, most Gracious, most Compassionate'
),
array( // sallallahou alayhe wasallam
array('pbuh', 'saw', 'saaw', 'saas', 'saww'),
array('U+FDFA','ﷺ','ﷺ','%EF%B7%BA'),
'صلى الله عليه وسلم‎',
'ṣall Allāhu ʿalay-hi wa-sallam',
'May Allāh honor him and grant him peace'
),
array( // Jalla Jalaluh/Jallajalalouhou/Subḥānahu wa ta'āla
array('swt', 'jallajalaluh', 'jallajalalouhou'),
array('U+FDFB','ﷻ','ﷻ','%EF%B7%BB'),
'سبحانه و تعالى',
'Subḥānahu wa ta`āla',
'May He be Glorified and Exalted'
),
array( // Allah
array('allah'),
array('U+FDF2','ﷲ','ﷲ','%EF%B7%B2'),
'الله',
'Allāh',
'Allah (God)'
),
array( // As-salamu alaykum
array('salaam', 'sallam'),
array('','السلام','السلام',''),
'السلام',
'As-salamu alaykum',
'Peace be upon you'
),
array( // `Alayhi s-salām
array('sa', 'alayhis'),
array('U+FDFA','ﷺ','ﷺ','%EF%B7%BA'),
'صلى الله عليه وسلم‎',
'ʿalay-hi wa-sallam',
'Upon him prayer and peace'
),
);
function __construct() {
$this->_denormalise_ligatures();
$this->_register_filters();
}
private function _register_filters() {
add_filter( 'wp_title', array($this, 'filter_wp_title'), 100);
add_filter( 'the_content', array($this, 'filter_the_content'), 20);
// add_action( 'wp_head', array($this, 'style'));
}
public function style() {
$style = '<style>';
$style .= '.arabic-ligature {';
$style .= ' font-family: "Times New Roman", sans-serif;';
$style .= '}';
$style .= '</style>';
echo $style;
}
public function filter_wp_title($title) {
foreach($this->_ligature_map as $key=>$entry) {
$pattern[] = "/\[$key\]/i";
$replacement[] = array_shift($entry);
}
return preg_replace($pattern, $replacement, $title);
}
public function filter_the_content($content) {
foreach($this->_ligature_map as $shortcode=>$data) {
$pattern[] = "/\[$shortcode\]/im";
$replacement[] = sprintf(
'<span class="arabic-ligature" title="%s (%s) %s">%s</span>',
$data['arabic'],
$data['transliteration'],
$data['translation'],
$data['ligature']
);
}
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
private function _denormalise_ligatures() {
foreach ($this->_ligatures as $entry) {
list($short_codes, $ligature_codes, $arabic, $transliteration, $translation) = $entry;
foreach ($short_codes as $code) {
$this->_ligature_map[$code] = array(
'ligature' => $ligature_codes[self::UNICODE_HTML_DEC],
'arabic' => $arabic,
'transliteration' => $transliteration,
'translation' => $translation
);
}
}
}
}
$arabic_ligature = new arabic_ligature();