Skip to content

Commit 523a220

Browse files
committed
Second layer of refactoring in display_impr_text*
1 parent 6e5e369 commit 523a220

4 files changed

Lines changed: 259 additions & 92 deletions

File tree

‎display_impr_text.php‎

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,47 @@
1515

1616
require_once 'inc/session_utility.php';
1717
require_once 'inc/mobile_interactions.php';
18+
require_once 'display_impr_text_header.php';
19+
require_once 'display_impr_text_text.php';
1820

19-
function do_mobile_display_impr_text($audio) {
21+
/**
22+
* Make the page content to display printed texts on mobile.
23+
*
24+
* @param int $textid Text ID
25+
* @param string $audio Media URI
26+
*
27+
* @return void
28+
* @deprecated
29+
* @since 2.2.0 This function should not longer be used, and should cause issues. Use
30+
* do_desktop_display_impr_text instead.
31+
*/
32+
function do_mobile_display_impr_text($textid, $audio) {
2033
do_frameset_mobile_css();
2134
do_frameset_mobile_js($audio);
2235

2336
?>
2437

2538
<div id="frame-h">
26-
<iframe id="frame-h-2" src="display_impr_text_header.php?text=<?php echo $_REQUEST['text']; ?>" scrolling="yes" name="header">
39+
<iframe id="frame-h-2" src="display_impr_text_header.php?text=<?php echo $textid; ?>" scrolling="yes" name="header">
2740
</iframe>
2841
</div>
2942
<div id="frame-l">
30-
<iframe id="frame-l-2" src="display_impr_text_text.php?text=<?php echo $_REQUEST['text']; ?>" scrolling="yes" name="text">
43+
<iframe id="frame-l-2" src="display_impr_text_text.php?text=<?php echo $textid; ?>" scrolling="yes" name="text">
3144
</iframe>
3245
</div>
3346

3447
<?php
3548
}
3649

37-
function do_desktop_display_impr_text($audio) {
50+
/**
51+
* Make the main page content to display printed texts for desktop.
52+
*
53+
* @param int $textid Text ID
54+
* @param string $audio Media URI
55+
*
56+
* @return void
57+
*/
58+
function do_desktop_display_impr_text($textid, $audio) {
3859

3960
?>
4061

@@ -53,19 +74,27 @@ function do_desktop_display_impr_text($audio) {
5374
</html>-->
5475
<div style="width: 95%; height: 100%;">
5576
<div id="frame-h">
56-
<?php require_once 'display_impr_text_header.php' ?>
77+
<?php do_diplay_impr_text_header_main($textid);?>
5778
</div>
5879
<hr />
5980
<div id="frame-l">
60-
<?php require_once 'display_impr_text_text.php'; ?>
81+
<?php do_display_impr_text_text_main($textid); ?>
6182
</div>
6283
</div>
6384
<?php
6485
}
6586

66-
function do_display_impr_text_page() {
87+
/**
88+
* Do the page to display printed text.
89+
*
90+
* @param int $textid Text ID
91+
*
92+
* @global string $tbpref Database table prefix
93+
*
94+
* @return void
95+
*/
96+
function do_display_impr_text_page($textid) {
6797
global $tbpref;
68-
6998
$audio = get_first_value(
7099
'SELECT TxAudioURI AS value FROM ' . $tbpref . 'texts
71100
WHERE TxID = ' . $_REQUEST['text']
@@ -74,16 +103,16 @@ function do_display_impr_text_page() {
74103
//framesetheader('Display');
75104

76105
if (is_mobile() && false) {
77-
do_mobile_display_impr_text($audio);
106+
do_mobile_display_impr_text($textid, $audio);
78107
} else {
79-
do_desktop_display_impr_text($audio);
108+
do_desktop_display_impr_text($textid, $audio);
80109
}
81110

82111
pageend();
83112
}
84113

85114
if (isset($_REQUEST['text'])) {
86-
do_display_impr_text_page();
115+
do_display_impr_text_page((int) getreq('text'));
87116
} else {
88117
header("Location: edit_texts.php");
89118
exit();

‎display_impr_text_header.php‎

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,21 @@
1414

1515
require_once 'inc/session_utility.php';
1616

17-
function do_diplay_impr_text_header_data() {
17+
/**
18+
* Return the useful data for the header part of a printed text.
19+
*
20+
* @param int $textid Text ID
21+
*
22+
* @return array{0: string, 1: string, 2: string} Text title,
23+
* text audio and source URI
24+
*
25+
* @global string $tbpref Database table prefix.
26+
*/
27+
function do_diplay_impr_text_header_data($textid) {
1828
global $tbpref;
1929

20-
$textid = (int) getreq('text');
21-
$sql
22-
= 'SELECT TxLgID, TxTitle, TxAudioURI, TxSourceURI
30+
$sql =
31+
'SELECT TxLgID, TxTitle, TxAudioURI, TxSourceURI
2332
FROM ' . $tbpref . 'texts
2433
WHERE TxID = ' . $textid;
2534
$res = do_mysqli_query($sql);
@@ -37,51 +46,73 @@ function do_diplay_impr_text_header_data() {
3746
mysqli_free_result($res);
3847

3948
saveSetting('currenttext', $textid);
40-
return array($title, $textid, $audio, $sourceURI);
49+
return array($title, $audio, $sourceURI);
4150
}
4251

52+
/**
53+
* Echo JavaScript area containing behaviors to show/hide
54+
* translations and annotations.
55+
*
56+
* @return void
57+
*/
4358
function do_diplay_impr_text_header_js() {
4459

4560
?>
4661

4762
<script type="text/javascript">
48-
//<![CDATA[
63+
//<![CDATA[
64+
65+
/** Hide traslations. */
4966
function do_hide_t() {
5067
$('#showt').show();
5168
$('#hidet').hide();
5269
$('.anntermruby')
5370
.css('color','#E5E4E2').css('background-color', '#E5E4E2');
5471
}
72+
73+
/** Show translations. */
5574
function do_show_t() {
5675
$('#showt').hide();
5776
$('#hidet').show();
5877
$('.anntermruby')
5978
.css('color','inherit').css('background-color', '');
6079
}
80+
81+
/** Hide annotations. */
6182
function do_hide_a() {
6283
$('#show').show();
6384
$('#hide').hide();
6485
$('.anntransruby2')
6586
.css('color','#C8DCF0').css('background-color', '#C8DCF0');
6687
}
88+
89+
/** Show annotations. */
6790
function do_show_a() {
6891
$('#show').hide();
6992
$('#hide').show();
7093
$('.anntransruby2')
7194
.css('color','').css('background-color', '');
7295
}
73-
//]]>
96+
//]]>
7497
</script>
7598

7699
<?php
77100

78101
}
79102

103+
/**
104+
* Make the header content to display a printed text.
105+
*
106+
* @param string $title Text title
107+
* @param int $textid Text ID
108+
* @param string $audio Audio URI
109+
* @param string $sourceURI Text source link
110+
*
111+
* @return void
112+
*/
80113
function do_diplay_impr_text_header_content($title, $textid, $audio, $sourceURI) {
81-
//pagestart_nobody($title);
82-
do_diplay_impr_text_header_js();
83114
?>
84-
<h2 class="center" style="margin:5px;margin-top:-10px;">
115+
<h2 class="center" style="margin:5px;margin-top:-10px;">
85116
<img id="hidet" style="margin-bottom:-5px;" class="click" src="icn/light-bulb-T.png" title="Toggle Text Display (Now ON)" alt="Toggle Text Display (Now ON)" onclick="do_hide_t();" />
86117
<img id="showt" style="display:none; margin-bottom:-5px;" class="click" src="icn/light-bulb-off-T.png" title="Toggle Text Display (Now OFF)" alt="Toggle Text Display (Now OFF)" onclick="do_show_t();" />
87118
<img id="hide" style="margin-bottom:-5px;" class="click" src="icn/light-bulb-A.png" title="Toggle Annotation Display (Now ON)" alt="Toggle Annotation Display (Now ON)" onclick="do_hide_a();" />
@@ -96,7 +127,8 @@ function do_diplay_impr_text_header_content($title, $textid, $audio, $sourceURI)
96127
}
97128
echo getPreviousAndNextTextLinks($textid, 'display_impr_text.php?text=', true, ' &nbsp; &nbsp; ');
98129
?>
99-
<img class="click" src="icn/cross.png" title="Close Window" alt="Close Window" onclick="top.close();" /></span></h2>
130+
<img class="click" src="icn/cross.png" title="Close Window" alt="Close Window" onclick="top.close();" />
131+
</h2>
100132
<?php
101133
makeMediaPlayer($audio);
102134

@@ -105,10 +137,17 @@ function do_diplay_impr_text_header_content($title, $textid, $audio, $sourceURI)
105137
//pageend();
106138
}
107139

108-
function do_diplay_impr_text_header_main() {
109-
list($title, $textid, $audio, $sourceURI) = do_diplay_impr_text_header_data();
140+
/**
141+
* Main function to generate a complete header for a specific text.
142+
*
143+
* @param int $textid Text ID.
144+
*
145+
* @return void
146+
*/
147+
function do_diplay_impr_text_header_main($textid) {
148+
do_diplay_impr_text_header_js();
149+
list($title, $audio, $sourceURI) = do_diplay_impr_text_header_data($textid);
110150
do_diplay_impr_text_header_content($title, $textid, $audio, $sourceURI);
111151
}
112152

113-
do_diplay_impr_text_header_main();
114153
?>

0 commit comments

Comments
 (0)