Skip to content

Commit 3307e5c

Browse files
committed
ajax_get_phonetic integration in REST.
1 parent 35f7ee5 commit 3307e5c

6 files changed

Lines changed: 30 additions & 5 deletions

File tree

‎docs/CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ It features the following interaction:
2222
* ``version``: the REST API version and release date.
2323
* ``test``: next word to test.
2424
* ``tomorrow_test_count``: number of tests for the next day.
25+
* ``phonetic_reading``: phonetic reading of a text.
2526
* On POST, ``action_type`` can be:
2627
* ``simterms``: similar terms to a given term
2728
* ``add_translation``: add a translation for a new word
@@ -64,6 +65,7 @@ the intendended page. Same goes for "New Text" on "Archived Texts" page.
6465
* ``inc/ajax_add_term_transl.php``, use ``action_type=add_translation`` or ``action_type=update_translation``. The arguments were also changed.
6566
* ``inc/ajax_check_regexp.php`` should be accessed through ``action_type=regexp``. Argument ``regex`` is now ``regexp``, on post only.
6667
* ``inc/ajax_chg_term_status.php`` should be accessed through ``action_type=increase_term_status``. Argument ``data`` is now ``status_up``, on post only.
68+
* ``inc/ajax_get_phonetic.php`` should be accessed through ``action_type=phonetic_reading``, same arguments.
6769

6870
## 2.8.1-fork (April 14 2023)
6971

‎docs/info.html‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,8 @@ <h4>Added</h4>
18671867
<code>test</code>: next word to test.</li>
18681868
<li>
18691869
<code>tomorrow_test_count</code>: number of tests for the next day.</li>
1870+
<li>
1871+
<code>phonetic_reading</code>: phonetic reading of a text.</li>
18701872
</ul>
18711873
</li>
18721874
<li>On POST, <code>action_type</code> can be:
@@ -1934,6 +1936,8 @@ <h4>Deprecated</h4>
19341936
<code>inc/ajax_check_regexp.php</code> should be accessed through <code>action_type=regexp</code>. Argument <code>regex</code> is now <code>regexp</code>, on post only.</li>
19351937
<li>
19361938
<code>inc/ajax_chg_term_status.php</code> should be accessed through <code>action_type=increase_term_status</code>. Argument <code>data</code> is now <code>status_up</code>, on post only.</li>
1939+
<li>
1940+
<code>inc/ajax_get_phonetic.php</code> should be accessed through <code>action_type=phonetic_reading</code>, same arguments.</li>
19371941
</ul>
19381942
</li>
19391943
</ul>

‎inc/ajax.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ function tomorrow_test_count($get_req)
112112
return get_tomorrow_test_count($get_req['test_sql']);
113113
}
114114

115+
/**
116+
* Get the phonetic reading of a word based on it's language.
117+
*
118+
* @param array $get_req Array with the fields "text" and "lang" (short language name)
119+
*/
120+
function get_phonetic_reading($get_req)
121+
{
122+
return phonetic_reading($get_req['text'], $get_req['lang']);
123+
}
124+
115125

116126
// --------------------------------- POST REQUESTS ---------------------
117127

@@ -200,6 +210,9 @@ function set_term_status($post_req)
200210
case 'tomorrow_test_count':
201211
echo tomorrow_test_count($_GET);
202212
break;
213+
case 'phonetic_reading':
214+
echo get_phonetic_reading($_GET);
215+
break;
203216
}
204217
}
205218
} else if (isset($_POST['action'])) {

‎inc/ajax_get_phonetic.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* @license Unlicense <http://unlicense.org/>
1111
* @link https://hugofara.github.io/lwt/docs/html/ajax__get__phonetic_8php.html
1212
* @since 2.3.0-fork
13+
*
14+
* @deprecated Use ajax.php with action_type=get_phonetic instead. Deprecated in 2.9.0.
1315
*/
1416
require_once 'session_utility.php';
1517

‎js/pgm.js‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/js/user_interactions.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,15 @@ function getPhoneticText(text, lang) {
176176
let phoneticText;
177177
$.ajax(
178178
{
179+
url:'inc/ajax',
179180
async: false,
180181
data: {
181-
text: text,
182+
action: "query",
183+
action_type: "phonetic_reading",
184+
text: text,
182185
lang: lang
183186
},
184187
type: "GET",
185-
url:'inc/ajax_get_phonetic.php',
186188
}
187189
)
188190
.done(
@@ -201,8 +203,10 @@ function getPhoneticText(text, lang) {
201203
*/
202204
async function getPhoneticTextAsync(text, lang) {
203205
return $.get(
204-
'inc/ajax_get_phonetic.php',
206+
'inc/ajax',
205207
data={
208+
action: "query",
209+
action_type: "phonetic_reading",
206210
text: text,
207211
lang: lang
208212
},

0 commit comments

Comments
 (0)