Skip to content

Commit

Permalink
Fixes #23
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Aug 20, 2019
1 parent 91f9b66 commit 2bfe7b4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 37 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<name>Cookbook</name>
<summary>An integrated cookbook using schema.org JSON files as recipes</summary>
<description><![CDATA[A library for all your recipes. It uses JSON files following the schema.org recipe format. To add a recipe to the collection, you can paste in the URL of the recipe, and the provided web page will be parsed and downloaded to whichever folder you specify in the app settings.]]></description>
<version>0.1.12</version>
<version>0.2.0</version>
<licence>agpl</licence>
<author mail="mrzapp@users.noreply.github.com" >Jeppe Zapp</author>
<namespace>Cookbook</namespace>
Expand Down
14 changes: 10 additions & 4 deletions lib/Service/RecipeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public function checkRecipe($json) {
if(is_array($json['recipeInstructions'])) {
foreach($json['recipeInstructions'] as $i => $step) {
if(is_string($step)) {
$json['recipeInstructions'][$i] = $this->cleanUpString($step);
$json['recipeInstructions'][$i] = $this->cleanUpString($step, true);
} else if(is_array($step) && isset($step['text'])) {
$json['recipeInstructions'][$i] = $this->cleanUpString($step['text']);
$json['recipeInstructions'][$i] = $this->cleanUpString($step['text'], true);
} else {
$json['recipeInstructions'][$i] = '';
}
Expand Down Expand Up @@ -704,11 +704,17 @@ private function isRecipeFile($file) {
*
* @return string
*/
private function cleanUpString($str) {
private function cleanUpString($str, $preserve_newlines = false) {
if(!$str) { return ''; }

$str = strip_tags($str);
$str = str_replace(["\r", "\n", "\t", "\\"], '', $str);

if(!$preserve_newlines) {
$str = str_replace(["\r", "\n"], '', $str);
}

$str = str_replace(["\t", "\\"], '', $str);

$str = html_entity_decode($str);

return $str;
Expand Down
44 changes: 12 additions & 32 deletions templates/content/recipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,31 @@
<?php } ?>

<h2><?php echo $_['name']; ?></h2>

<div class="recipe-details">
<?php if(isset($_['url']) && $_['url']) { ?>
<p><strong><?php p($l->t('Source')); ?>: </strong><a target="_blank" href="<?php echo $_['url']; ?>"><?php echo $_['url']; ?></a></p>
<?php } ?>

<p><?php echo $_['description']; ?></p>

<?php if(isset($_['prepTime']) && $_['prepTime']) {
$prep_interval = new DateInterval($_['prepTime']);
$prep_mins = $prep_interval->format('%i');
$prep_hours = $prep_interval->format('%h');
if($prep_hours > 0) {
$prep_hour_string = $prep_hours.' '.($prep_hours > 1 ? 'Hours' : 'Hour').' ';
} else {
$prep_hour_string = "";
}
if($prep_mins > 0) {
$prep_min_string = $prep_mins.' '.($prep_mins > 1 ? 'Mins' : 'Min');
} else {
$prep_min_string = "";
}
?>
<p><strong>Prep: </strong><?php echo $prep_hour_string.$prep_min_string; ?></p>
?>
<p><strong><?php p($l->t('Preparation time')); ?>: </strong><?php echo $prep_hours . ':' . $prep_mins; ?></p>
<?php } ?>

<?php if(isset($_['cookTime']) && $_['cookTime']) {
$cook_interval = new DateInterval($_['cookTime']);
$cook_mins = $cook_interval->format('%i');
$cook_hours = $cook_interval->format('%h');
if($cook_hours > 0) {
$cook_hour_string = $cook_hours.' '.($cook_hours > 1 ? 'Hours' : 'Hour').' ';
} else {
$cook_hour_string = "";
}
if($cook_mins > 0) {
$cook_min_string = $cook_mins.' '.($cook_mins > 1 ? 'Mins' : 'Min');
} else {
$cook_min_string = "";
}
?>
<p><strong>Cook: </strong><?php echo $cook_hour_string.$cook_min_string; ?></p>
?>
<p><strong><?php p($l->t('Cooking time')); ?>: </strong><?php echo $cook_hours . ':' . $cook_mins; ?></p>
<?php } ?>

<p><?php p($l->n('One serving', '%n servings', $_['recipeYield'])); ?></p>
<p><strong><?php p($l->t('Servings')); ?>: </strong><?php echo $_['recipeYield']; ?></p>
</div>

<?php if(isset($_['dailyDozen'])) { ?>
Expand Down Expand Up @@ -89,13 +74,8 @@
<h3><?php p($l->t('Instructions')); ?></h3>

<?php foreach($_['recipeInstructions'] as $step) { ?>
<li><?php echo $step; ?></li>
<li><?php echo nl2br($step); ?></li>
<?php } ?>
</ul>
</main>


<?php if(isset($_['url']) && $_['url']) { ?>
<p><a href="<?php echo $_['url']; ?>">Original Source</a></p>
<?php } ?>

0 comments on commit 2bfe7b4

Please sign in to comment.