Skip to content

Commit

Permalink
Do not generate HTML when url provided as GET param
Browse files Browse the repository at this point in the history
Simply pass over the URL as field value. Generating HTML
"from hand" is not nice in general.
  • Loading branch information
manicki committed Mar 7, 2017
1 parent 99522fe commit 375fcf0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.base.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h2>{{i18n.index.description}}</h2>
</div>

<form id="file-form" class="yes-script" onsubmit="return false;">
<input id="file-form-input" type="text" inputmode="url" name="file" placeholder="{{i18n.index.input-placeholder}}" {{inputattr}} autofocus><button type="submit" class="green-btn">{{i18n.index.go-button}}</button>
<input id="file-form-input" type="text" inputmode="url" name="file" placeholder="{{i18n.index.input-placeholder}}" value="{{url}}" autofocus><button type="submit" class="green-btn">{{i18n.index.go-button}}</button>
<div class="container-fluid display-none" id="file-form-alert">
<span class="glyphicon glyphicon-warning-sign"></span><span id="file-form-alert-placeholder">Alert</span>
</div>
Expand Down
5 changes: 4 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
$i18nData = file_get_contents( __DIR__ . '/i18n/' . $lang . '/i18n.json' );
$i18nData = json_decode($i18nData, true);

// Get the url if passed
$url = isset( $_GET['url'] ) ? $_GET['url'] : '';

// Get the base html to output
$html = file_get_contents( __DIR__ . '/index.base.html' );
$html = str_replace( '{{i18n.lang}}', $lang, $html );
$html = str_replace( '{{inputattr}}', isset( $_GET['url'] ) ? ' value="'.htmlspecialchars($_GET['url']).'"' : '', $html );
$html = str_replace( '{{url}}', htmlspecialchars( $url ), $html );

// If we have any i18n data replace the i18n codes with new strings
if ( $i18nData && isset( $i18nData['index'] ) ) {
Expand Down

0 comments on commit 375fcf0

Please sign in to comment.