Skip to content

Commit 2bfe7b4

Browse files
author
root
committed
Fixes #23
1 parent 91f9b66 commit 2bfe7b4

File tree

3 files changed

+23
-37
lines changed

3 files changed

+23
-37
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>Cookbook</name>
66
<summary>An integrated cookbook using schema.org JSON files as recipes</summary>
77
<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>
8-
<version>0.1.12</version>
8+
<version>0.2.0</version>
99
<licence>agpl</licence>
1010
<author mail="[email protected]" >Jeppe Zapp</author>
1111
<namespace>Cookbook</namespace>

lib/Service/RecipeService.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ public function checkRecipe($json) {
165165
if(is_array($json['recipeInstructions'])) {
166166
foreach($json['recipeInstructions'] as $i => $step) {
167167
if(is_string($step)) {
168-
$json['recipeInstructions'][$i] = $this->cleanUpString($step);
168+
$json['recipeInstructions'][$i] = $this->cleanUpString($step, true);
169169
} else if(is_array($step) && isset($step['text'])) {
170-
$json['recipeInstructions'][$i] = $this->cleanUpString($step['text']);
170+
$json['recipeInstructions'][$i] = $this->cleanUpString($step['text'], true);
171171
} else {
172172
$json['recipeInstructions'][$i] = '';
173173
}
@@ -704,11 +704,17 @@ private function isRecipeFile($file) {
704704
*
705705
* @return string
706706
*/
707-
private function cleanUpString($str) {
707+
private function cleanUpString($str, $preserve_newlines = false) {
708708
if(!$str) { return ''; }
709709

710710
$str = strip_tags($str);
711-
$str = str_replace(["\r", "\n", "\t", "\\"], '', $str);
711+
712+
if(!$preserve_newlines) {
713+
$str = str_replace(["\r", "\n"], '', $str);
714+
}
715+
716+
$str = str_replace(["\t", "\\"], '', $str);
717+
712718
$str = html_entity_decode($str);
713719

714720
return $str;

templates/content/recipe.php

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,31 @@
66
<?php } ?>
77

88
<h2><?php echo $_['name']; ?></h2>
9-
9+
1010
<div class="recipe-details">
11+
<?php if(isset($_['url']) && $_['url']) { ?>
12+
<p><strong><?php p($l->t('Source')); ?>: </strong><a target="_blank" href="<?php echo $_['url']; ?>"><?php echo $_['url']; ?></a></p>
13+
<?php } ?>
14+
1115
<p><?php echo $_['description']; ?></p>
1216

1317
<?php if(isset($_['prepTime']) && $_['prepTime']) {
1418
$prep_interval = new DateInterval($_['prepTime']);
1519
$prep_mins = $prep_interval->format('%i');
1620
$prep_hours = $prep_interval->format('%h');
17-
if($prep_hours > 0) {
18-
$prep_hour_string = $prep_hours.' '.($prep_hours > 1 ? 'Hours' : 'Hour').' ';
19-
} else {
20-
$prep_hour_string = "";
21-
}
22-
if($prep_mins > 0) {
23-
$prep_min_string = $prep_mins.' '.($prep_mins > 1 ? 'Mins' : 'Min');
24-
} else {
25-
$prep_min_string = "";
26-
}
27-
?>
28-
<p><strong>Prep: </strong><?php echo $prep_hour_string.$prep_min_string; ?></p>
21+
?>
22+
<p><strong><?php p($l->t('Preparation time')); ?>: </strong><?php echo $prep_hours . ':' . $prep_mins; ?></p>
2923
<?php } ?>
24+
3025
<?php if(isset($_['cookTime']) && $_['cookTime']) {
3126
$cook_interval = new DateInterval($_['cookTime']);
3227
$cook_mins = $cook_interval->format('%i');
3328
$cook_hours = $cook_interval->format('%h');
34-
if($cook_hours > 0) {
35-
$cook_hour_string = $cook_hours.' '.($cook_hours > 1 ? 'Hours' : 'Hour').' ';
36-
} else {
37-
$cook_hour_string = "";
38-
}
39-
if($cook_mins > 0) {
40-
$cook_min_string = $cook_mins.' '.($cook_mins > 1 ? 'Mins' : 'Min');
41-
} else {
42-
$cook_min_string = "";
43-
}
44-
?>
45-
<p><strong>Cook: </strong><?php echo $cook_hour_string.$cook_min_string; ?></p>
29+
?>
30+
<p><strong><?php p($l->t('Cooking time')); ?>: </strong><?php echo $cook_hours . ':' . $cook_mins; ?></p>
4631
<?php } ?>
4732

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

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

9176
<?php foreach($_['recipeInstructions'] as $step) { ?>
92-
<li><?php echo $step; ?></li>
77+
<li><?php echo nl2br($step); ?></li>
9378
<?php } ?>
9479
</ul>
9580
</main>
9681

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

0 commit comments

Comments
 (0)