forked from jdorfman/commando
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view-recipe.php
143 lines (126 loc) · 5.55 KB
/
view-recipe.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/*
# Copyright 2012 NodeSocket, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
*/
($_SERVER['SCRIPT_NAME'] !== "/controller.php") ? require_once(__DIR__ . "/classes/Requires.php") : Links::$pretty = true;
require_once(__DIR__ . "/markdown/markdown.php");
Functions::check_required_parameters(array($_GET['param1']));
$result = MySQLQueries::get_recipe_head_version($_GET['param1']);
$head = MySQLConnection::fetch_object($result);
if(isset($_GET['param2']) && !empty($_GET['param2'])) {
$recipe_version = $_GET['param2'];
} else {
$recipe_version = $head->recipe_version;
}
$result = MySQLQueries::get_recipe_by_version($_GET['param1'], $recipe_version);
$recipe = MySQLConnection::fetch_object($result);
$recipe = Functions::format_dates($recipe);
//Get recipe versions
$recipe_versions = array();
$result = MySQLQueries::get_recipe_versions($_GET['param1']);
while($row = MySQLConnection::fetch_object($result)) {
$recipe_versions[] = $row;
}
//Calculate Statistics
$recipe->lines = (substr_count($recipe->content, "\n") + 1);
$recipe->length = Functions::formatBytes(strlen($recipe->content));
//Get the correct language for code-pretty
switch($recipe->interpreter) {
case 'shell':
$code_pretty_lang = "lang-sh";
break;
case 'bash':
$code_pretty_lang = "lang-bsh";
break;
case 'node.js':
$code_pretty_lang = "lang-js";
break;
case 'perl':
$code_pretty_lang = "lang-perl";
break;
case 'python':
$code_pretty_lang = "lang-py";
break;
}
Header::set_title("Commando.io - View Recipe");
Header::render(array("chosen", "code-pretty"));
Navigation::render("recipes");
?>
<div class="container">
<div>
<h1 class="header" style="float: left;"><?php echo $recipe->name ?></h1>
<div style="float: right;">
<a class="btn btn-large disabled"><?php echo substr($recipe->version, 0, 10) ?><?php if($recipe->recipe_version === $head->recipe_version): ?> (HEAD)<?php endif; ?></a>
</div>
</div>
<div class="row">
<div class="span12 well">
<?php if($recipe->recipe_version === $head->recipe_version): ?>
<a href="<?php echo Links::render("edit-recipe", array($recipe->id)) ?>" class="btn btn-primary btn-large"><i class="icon-edit icon-white"></i> Edit Recipe</a>
<a id="delete-recipe" href="/actions/delete_recipe.php?id=<?php echo $recipe->id ?>" class="btn btn-large"><i class="icon-remove"></i> Delete Recipe</a>
<?php else: ?>
<div class="alert alert-info no-bottom-margin">
<h4>Notice!</h4>
You are viewing an <strong><u>old version</u></strong> of this recipe. Only the <strong><u>head</u></strong> version of recipes may be edited. If you would like to make modifications to this recipe, navigate to the <a href="<?php echo Links::render("view-recipe", array($recipe->id)) ?>">head</a>.
</div>
<?php endif; ?>
</div>
</div>
<div class="row">
<div class="span12 well">
<div id="recipe-notes" class="alert alert-grey fade in" <?php if(empty($recipe->notes)): ?>style="display: none;"<?php endif; ?>>
<a class="close" data-dismiss="alert">×</a>
<?php echo Markdown($recipe->notes) ?>
</div>
<div class="navbar navbar-static">
<div class="navbar-inner">
<div class="container" style="width: auto;">
<a class="brand"><?php echo ucfirst($recipe->interpreter) ?></a>
<ul class="nav">
<li class="divider-vertical"></li>
<li>
<a><?php echo $recipe->lines ?> <?php echo $recipe->lines == 1 ? 'line' : 'lines'; ?> / <?php echo $recipe->length ?></a>
</li>
<li class="divider-vertical"></li>
<li>
<a>Added: <?php echo $recipe->added ?></a>
</li>
</ul>
<ul class="navbar-form nav pull-right">
<li>
<select name="versions" id="recipe-versions" class="span2" data-placeholder="">
<?php foreach($recipe_versions as $recipe_version): ?>
<option value="
<?php
if($recipe_version->id !== $head->recipe_version) {
echo Links::render("view-recipe", array($recipe->id, $recipe_version->id));
} else {
echo Links::render("view-recipe", array($recipe->id));
}
?>
" <?php if($recipe_version->id === $recipe->recipe_version) { echo 'selected="selected"'; } ?>><?php echo substr($recipe_version->version, 0, 10) ?><?php if($recipe_version->id === $head->recipe_version): ?> (HEAD)<?php endif; ?></option>
<?php endforeach; ?>
</select>
</li>
</ul>
</div>
</div>
</div>
<pre class="prettyprint <?php echo $code_pretty_lang ?> linenums"><?php echo $recipe->content ?></pre>
</div>
</div>
<?php
Footer::render(array("chosen", "code-pretty", "bootbox", "view-recipe"));
?>