Skip to content
This repository was archived by the owner on Mar 3, 2020. It is now read-only.

Commit 081062c

Browse files
javutogsingh93
authored andcommitted
Custom branding for icon and text (#448)
* Custom branding for icon and text * Replace async calls branding xhp by attributes * Use genRenderBranding in genRenderMobilePage and combine awaitables
1 parent ac64f55 commit 081062c

File tree

16 files changed

+260
-38
lines changed

16 files changed

+260
-38
lines changed

database/schema.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ INSERT INTO `configuration` (field, value, description) VALUES("password_type",
211211
INSERT INTO `configuration` (field, value, description) VALUES("default_bonus", "30", "(Integer) Default value for bonus in levels");
212212
INSERT INTO `configuration` (field, value, description) VALUES("default_bonusdec", "10", "(Integer) Default bonus decrement in levels");
213213
INSERT INTO `configuration` (field, value, description) VALUES("language", "en", "(String) Language of the system");
214+
INSERT INTO `configuration` (field, value, description) VALUES("custom_logo", "0", "(Boolean) Custom branding logo");
215+
INSERT INTO `configuration` (field, value, description) VALUES("custom_text", "Powered By Facebook", "(String) Custom branding text");
216+
INSERT INTO `configuration` (field, value, description) VALUES("custom_logo_image", "static/img/favicon.png", "(String) Custom logo image file");
214217
UNLOCK TABLES;
215218

216219
--

src/controllers/AdminController.php

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ class="fb-cta cta--yellow"
311311
'bases_cycle' => Configuration::gen('bases_cycle'),
312312
'start_ts' => Configuration::gen('start_ts'),
313313
'end_ts' => Configuration::gen('end_ts'),
314+
'custom_logo' => Configuration::gen('custom_logo'),
315+
'custom_text' => Configuration::gen('custom_text'),
316+
'custom_logo_image' => Configuration::gen('custom_logo_image'),
314317
};
315318

316319
$results = await \HH\Asio\m($awaitables);
@@ -335,6 +338,9 @@ class="fb-cta cta--yellow"
335338
$bases_cycle = $results['bases_cycle'];
336339
$start_ts = $results['start_ts'];
337340
$end_ts = $results['end_ts'];
341+
$custom_logo = $results['custom_logo'];
342+
$custom_text = $results['custom_text'];
343+
$custom_logo_image = $results['custom_logo_image'];
338344

339345
$registration_on = $registration->getValue() === '1';
340346
$registration_off = $registration->getValue() === '0';
@@ -354,6 +360,8 @@ class="fb-cta cta--yellow"
354360
$gameboard_off = $gameboard->getValue() === '0';
355361
$timer_on = $timer->getValue() === '1';
356362
$timer_off = $timer->getValue() === '0';
363+
$custom_logo_on = $custom_logo->getValue() === '1';
364+
$custom_logo_off = $custom_logo->getValue() === '0';
357365

358366
$game_start_array = array();
359367
if ($start_ts->getValue() !== '0' && $start_ts->getValue() !== 'NaN') {
@@ -437,7 +445,6 @@ class="fb-cta cta--yellow"
437445
$language_select = $results['language_select'];
438446
$password_types_select = $results['password_types_select'];
439447

440-
$login_strongpasswords = await Configuration::gen('login_strongpasswords');
441448
if ($login_strongpasswords->getValue() === '0') { // Strong passwords are not enforced
442449
$strong_passwords = <div></div>;
443450
} else {
@@ -448,6 +455,33 @@ class="fb-cta cta--yellow"
448455
</div>;
449456
}
450457

458+
if ($custom_logo->getValue() === '0') { // Custom branding is not enabled
459+
$custom_logo_xhp = <div></div>;
460+
} else {
461+
$custom_logo_xhp =
462+
<div class="form-el el--block-label el--full-text">
463+
<label for="">{tr('Logo')}</label>
464+
<img
465+
id="custom-logo-image"
466+
class="icon--badge"
467+
src={$custom_logo_image->getValue()}
468+
/>
469+
<br/>
470+
<h6>
471+
<a class="icon-text" href="#" id="custom-logo-link">
472+
{tr('Change')}
473+
</a>
474+
</h6>
475+
<input
476+
autocomplete="off"
477+
name="custom-logo-input"
478+
id="custom-logo-input"
479+
type="file"
480+
accept="image/*"
481+
/>
482+
</div>;
483+
}
484+
451485
return
452486
<div>
453487
<header class="admin-page-header">
@@ -914,11 +948,59 @@ class="fb-cta cta--yellow"
914948
</section>
915949
<section class="admin-box">
916950
<header class="admin-box-header">
917-
<h3>{tr('Language')}</h3>
951+
<h3>{tr('Internationalization')}</h3>
952+
</header>
953+
<div class="fb-column-container">
954+
<div class="col col-pad col-2-4">
955+
<div class="form-el el--block-label">
956+
<label for="">{tr('Language')}</label>
957+
{$language_select}
958+
</div>
959+
</div>
960+
</div>
961+
</section>
962+
<section class="admin-box">
963+
<header class="admin-box-header">
964+
<h3>{tr('Branding')}</h3>
918965
</header>
919-
<div class="col col-pad col-1-2">
920-
<div class="form-el el--block-label el--full-text">
921-
{$language_select}
966+
<div class="fb-column-container">
967+
<div class="col col-pad col-1-3">
968+
<div class="form-el el--block-label">
969+
<label>{tr('Custom Logo')}</label>
970+
<div class="admin-section-toggle radio-inline">
971+
<input
972+
type="radio"
973+
name="fb--conf--custom_logo"
974+
id="fb--conf--custom_logo--on"
975+
checked={$custom_logo_on}
976+
/>
977+
<label for="fb--conf--custom_logo--on">
978+
{tr('On')}
979+
</label>
980+
<input
981+
type="radio"
982+
name="fb--conf--custom_logo"
983+
id="fb--conf--custom_logo--off"
984+
checked={$custom_logo_off}
985+
/>
986+
<label for="fb--conf--custom_logo--off">
987+
{tr('Off')}
988+
</label>
989+
</div>
990+
</div>
991+
</div>
992+
<div class="col col-pad col-1-3">
993+
{$custom_logo_xhp}
994+
</div>
995+
<div class="col col-pad col-1-3">
996+
<div class="form-el el--block-label el--full-text">
997+
<label for="">{tr('Custom Text')}</label>
998+
<input
999+
type="text"
1000+
name="fb--conf--custom_text"
1001+
value={$custom_text->getValue()}
1002+
/>
1003+
</div>
9221004
</div>
9231005
</div>
9241006
</section>
@@ -3718,6 +3800,7 @@ public function renderMainContent(): :xhp {
37183800
{tr('Begin Game')}
37193801
</a>;
37203802
}
3803+
$branding_xhp = await $this->genRenderBranding();
37213804
return
37223805
<div id="fb-admin-nav" class="admin-nav-bar fb-row-container">
37233806
<header class="admin-nav-header row-fixed">
@@ -3790,7 +3873,7 @@ public function renderMainContent(): :xhp {
37903873
<a href="/index.php?p=game">{tr('Gameboard')}</a>
37913874
<a href="" class="js-prompt-logout">{tr('Logout')}</a>
37923875
<a></a>
3793-
<fbbranding />
3876+
{$branding_xhp}
37943877
</div>
37953878
</div>;
37963879
}

src/controllers/Controller.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ abstract protected function getPages(): array<string>;
77

88
abstract protected function genRenderBody(string $page): Awaitable<:xhp>;
99

10+
public async function genRenderBranding(): Awaitable<:xhp> {
11+
$awaitables = Map {
12+
'custom_logo' => Configuration::gen('custom_logo'),
13+
'custom_text' => Configuration::gen('custom_text'),
14+
'custom_logo_image' => Configuration::gen('custom_logo_image'),
15+
};
16+
$results = await \HH\Asio\m($awaitables);
17+
$branding = $results['custom_logo'];
18+
$custom_text = $results['custom_text'];
19+
if ($branding->getValue() === '0') {
20+
$branding_xhp =
21+
<fbbranding
22+
brandingText={tr(strval($custom_text->getValue()))}
23+
/>;
24+
} else {
25+
$custom_logo_image = $results['custom_logo_image'];
26+
$branding_xhp =
27+
<custombranding
28+
brandingText={strval($custom_text->getValue())}
29+
brandingLogo={strval($custom_logo_image->getValue())}
30+
/>;
31+
}
32+
return $branding_xhp;
33+
}
34+
1035
public async function genRender(): Awaitable<:xhp> {
1136
$page = $this->processRequest();
1237
$body = await $this->genRenderBody($page);

src/controllers/GameboardController.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ protected function getPages(): array<string> {
2323
return array('main', 'viewmode');
2424
}
2525

26-
public function renderMainContent(): :xhp {
26+
public async function genRenderMainContent(): Awaitable<:xhp> {
2727
if (SessionUtils::sessionAdmin()) {
2828
$admin_link = <li><a href="index.php?p=admin">{tr('Admin')}</a></li>;
2929
} else {
3030
$admin_link = null;
3131
}
32+
$branding_gen = await $this->genRenderBranding();
3233
return
3334
<div id="fb-gameboard" class="fb-gameboard">
3435
<div class="gameboard-header">
@@ -58,7 +59,7 @@ public function renderMainContent(): :xhp {
5859
<div class="branding">
5960
<a href="index.php?p=game">
6061
<div class="branding-rules">
61-
<fbbranding />
62+
{$branding_gen}
6263
</div>
6364
</a>
6465
</div>
@@ -137,19 +138,20 @@ class="module--outer-right"
137138
</div>;
138139
}
139140

140-
public function renderPage(string $page): :xhp {
141+
public async function genRenderPage(string $page): Awaitable<:xhp> {
141142
switch ($page) {
142143
case 'main':
143-
return $this->renderMainContent();
144+
return await $this->genRenderMainContent();
144145
break;
145146
default:
146-
return $this->renderMainContent();
147+
return await $this->genRenderMainContent();
147148
break;
148149
}
149150
}
150151

151152
<<__Override>>
152153
public async function genRenderBody(string $page): Awaitable<:xhp> {
154+
$rendered_page = await $this->genRenderPage($page);
153155
return
154156
<body data-section="gameboard">
155157
<input
@@ -159,7 +161,7 @@ public function renderPage(string $page): :xhp {
159161
/>
160162
<div class="fb-sprite" id="fb-svg-sprite"></div>
161163
<div id="fb-main-content" class="fb-page">
162-
{$this->renderPage($page)}
164+
{$rendered_page}
163165
</div>
164166
<script type="text/javascript" src="static/dist/js/app.js"></script>
165167
</body>;

src/controllers/IndexController.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,8 @@ public function renderErrorPage(): :xhp {
732732
</main>;
733733
}
734734

735-
public function renderMobilePage(): :xhp {
735+
public async function genRenderMobilePage(): Awaitable<:xhp> {
736+
$branding_xhp = await $this->genRenderBranding();
736737
return
737738
<div class="fb-row-container full-height page--mobile">
738739
<main
@@ -751,12 +752,12 @@ class="fb-main row-fluid center-vertically fb-img-glitch">
751752
</div>
752753
</main>
753754
<div class="row-fixed">
754-
<fbbranding />
755+
{$branding_xhp}
755756
</div>
756757
</div>;
757758
}
758759

759-
public function renderMainNav(): :xhp {
760+
public async function genRenderMainNav(): Awaitable<:xhp> {
760761
if (SessionUtils::sessionActive()) {
761762
$right_nav =
762763
<ul class="nav-right">
@@ -804,17 +805,20 @@ public function renderMainNav(): :xhp {
804805
</a>
805806
</li>
806807
</ul>;
808+
$branding_gen = await $this->genRenderBranding();
809+
$branding =
810+
<div class="branding">
811+
<a href="/">
812+
<div class="branding-rules">
813+
{$branding_gen}
814+
</div>
815+
</a>
816+
</div>;
807817

808818
return
809819
<nav class="fb-main-nav fb-navigation">
810820
{$left_nav}
811-
<div class="branding">
812-
<a href="/">
813-
<div class="branding-rules">
814-
<fbbranding />
815-
</div>
816-
</a>
817-
</div>
821+
{$branding}
818822
{$right_nav}
819823
</nav>;
820824
}
@@ -826,7 +830,7 @@ public function renderMainNav(): :xhp {
826830
case 'error':
827831
return $this->renderErrorPage();
828832
case 'mobile':
829-
return $this->renderMobilePage();
833+
return await $this->genRenderMobilePage();
830834
case 'login':
831835
return await $this->genRenderLoginContent();
832836
case 'registration':
@@ -847,11 +851,12 @@ public function renderMainNav(): :xhp {
847851
<<__Override>>
848852
public async function genRenderBody(string $page): Awaitable<:xhp> {
849853
$rendered_page = await $this->genRenderPage($page);
854+
$rendered_nav = await $this->genRenderMainNav();
850855
return
851856
<body data-section="pages">
852857
<div class="fb-sprite" id="fb-svg-sprite"></div>
853858
<div class="fb-viewport">
854-
<div id="fb-main-nav">{$this->renderMainNav()}</div>
859+
<div id="fb-main-nav">{$rendered_nav}</div>
855860
<div id="fb-main-content" class="fb-page">{$rendered_page}</div>
856861
</div>
857862
<script type="text/javascript" src="static/dist/js/app.js"></script>

src/controllers/ViewModeController.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ protected function getPages(): array<string> {
2323
return array('main');
2424
}
2525

26-
public function renderMainContent(): :xhp {
26+
public async function genRenderMainContent(): Awaitable<:xhp> {
27+
$branding_gen = await $this->genRenderBranding();
2728
return
2829
<div id="fb-gameboard" class="fb-gameboard gameboard--viewmode">
2930
<div class="gameboard-header">
3031
<nav class="fb-navigation fb-gameboard-nav">
3132
<div class="branding">
3233
<a href="/">
3334
<div class="branding-rules">
34-
<fbbranding />
35+
{$branding_gen}
3536
</div>
3637
</a>
3738
</div>
@@ -58,24 +59,25 @@ class="module--outer-right active"
5859
</div>;
5960
}
6061

61-
public function renderPage(string $page): :xhp {
62+
public async function genRenderPage(string $page): Awaitable<:xhp> {
6263
switch ($page) {
6364
case 'main':
64-
return $this->renderMainContent();
65+
return await $this->genRenderMainContent();
6566
break;
6667
default:
67-
return $this->renderMainContent();
68+
return await $this->genRenderMainContent();
6869
break;
6970
}
7071
}
7172

7273
<<__Override>>
7374
public async function genRenderBody(string $page): Awaitable<:xhp> {
75+
$rendered_page = await $this->genRenderPage($page);
7476
return
7577
<body data-section="viewer-mode">
7678
<div class="fb-sprite" id="fb-svg-sprite"></div>
7779
<div id="fb-main-content" class="fb-page">
78-
{$this->renderPage($page)}
80+
{$rendered_page}
7981
</div>
8082
<script type="text/javascript" src="static/dist/js/app.js"></script>
8183
</body>;

0 commit comments

Comments
 (0)