Skip to content

Commit 49634ae

Browse files
committed
Next pass at bootstrap conversion
1 parent 841dc08 commit 49634ae

File tree

6 files changed

+87
-89
lines changed

6 files changed

+87
-89
lines changed

src/libraries/Document.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ public function getUserId() {
250250
return $this->user_id;
251251
}
252252

253+
public function isMarkdown() {
254+
return ($this->options_bitmask & self::OPTION_MARKDOWN);
255+
}
256+
257+
public function isPublished() {
258+
return ($this->options_bitmask & self::OPTION_PUBLISHED);
259+
}
260+
253261
protected static function normalize(StdClass &$data) {
254262
$data->content = (string) $data->content;
255263
$data->created_datetime = (string) $data->created_datetime;

src/templates/Document/Delete.phtml

Lines changed: 43 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,46 @@
1-
<?php
2-
1+
<?php /* vim: set colorcolumn=: */
32
namespace BNETDocs\Templates\Document;
4-
53
use \CarlBennett\MVC\Libraries\Pair;
6-
7-
$title = "Delete Document";
8-
$description = "This form allows an individual to delete a document.";
9-
10-
$this->opengraph->attach(new Pair("url", "/document/delete"));
11-
$this->opengraph->attach(new Pair("type", "article"));
12-
13-
switch ($this->getContext()->error) {
14-
case "ACL_NOT_SET":
15-
$message = "You do not have the privilege to delete documents.";
16-
break;
17-
case "NOT_FOUND":
18-
$message = "Cannot find document by that id.";
19-
break;
20-
case "NOT_LOGGED_IN":
21-
$message = "You must be logged in to delete documents.";
22-
break;
23-
case "INTERNAL_ERROR":
24-
$message = "An internal error occurred while processing your request. "
25-
. "Our staff have been notified of the issue. Try again later.";
26-
break;
27-
default:
28-
$message = $this->getContext()->error;
4+
$title = 'Delete Document';
5+
$description = 'This form allows an individual to delete a document.';
6+
$this->opengraph->attach(new Pair('url', '/document/delete'));
7+
$this->opengraph->attach(new Pair('type', 'article'));
8+
$error = $this->getContext()->error;
9+
$id = $this->getContext()->id;
10+
$doc_title = $this->getContext()->title;
11+
switch ($error)
12+
{
13+
case 'ACL_NOT_SET': $message = 'You do not have the privilege to delete documents.'; break;
14+
case 'NOT_FOUND': $message = 'Cannot find document by that id.'; break;
15+
case 'NOT_LOGGED_IN': $message = 'You must be logged in to delete documents.'; break;
16+
case 'INTERNAL_ERROR': $message = 'An internal error occurred while processing your request. Our staff have been notified of the issue. Try again later.'; break;
17+
default: $message = $error;
2918
}
30-
31-
require("./header.inc.phtml");
32-
?>
33-
<article>
34-
<?php if (is_null($this->getContext()->error)) { ?>
35-
<header>Delete Document</header>
36-
<form method="POST" action="?id=<?php echo
37-
htmlspecialchars($this->getContext()->id, ENT_HTML5, "UTF-8"); ?>">
38-
<section>
39-
<p>Are you sure you wish to delete this document?</p>
40-
<p><input type="text" readonly="readonly" value="<?php echo filter_var($this->getContext()->title, FILTER_SANITIZE_STRING); ?>" tabindex="1"/></p>
41-
<p><input type="submit" value="Delete Document" tabindex="2" autofocus="autofocus"/></p>
42-
</section>
43-
</form>
44-
<?php } else if ($this->getContext()->error === false) { ?>
45-
<header class="green">Document Deleted</header>
46-
<section class="green">
47-
<p>You have successfully deleted the document!</p>
48-
<p>Use the navigation to the left to move to another page.</p>
49-
</section>
50-
<?php } else { ?>
51-
<header class="red">Delete Document</header>
52-
<section class="red">
53-
<p>An error occurred while attempting to delete the document.</p>
54-
<p><?php echo $message; ?></p>
55-
<p>Use the navigation to the left to move to another page.</p>
56-
</section>
57-
<?php } ?>
58-
</article>
59-
<?php require("./footer.inc.phtml"); ?>
19+
require('./header.inc.phtml'); ?>
20+
<div class="container mb-3">
21+
<? if (is_null($this->getContext()->error)) { ?>
22+
<h1 class="text-danger">Delete Document</h1>
23+
<form method="POST" action="?id=<?=filter_var($id, FILTER_SANITIZE_FULL_SPECIAL_CHARS)?>">
24+
<div class="form-group">
25+
<p class="text-danger">Are you sure you wish to delete this document?</p>
26+
<div class="card text-light"><div class="card-body"><?=filter_var($doc_title, FILTER_SANITIZE_FULL_SPECIAL_CHARS)?></div></div>
27+
</div>
28+
<div class="form-group text-center">
29+
<a class="btn btn-primary" href="javascript:history.go(-1);" tabindex="1">Back</a>
30+
<input class="btn btn-danger" type="submit" value="Delete Document" tabindex="2" autofocus="autofocus"/>
31+
</div>
32+
</form>
33+
<? } else if ($this->getContext()->error === false) { ?>
34+
<h1 class="text-success">Document Deleted</h1>
35+
<div class="alert alert-success">
36+
<p class="mb-0">You have successfully deleted the document!</p>
37+
</div>
38+
<? } else { ?>
39+
<h1 class="text-danger">Delete Document</h1>
40+
<div class="alert alert-danger">
41+
<p>An error occurred while attempting to delete the document.</p>
42+
<p class="mb-0"><?=$message?></p>
43+
</div>
44+
<? } ?>
45+
</div>
46+
<? require('./footer.inc.phtml'); ?>

src/templates/Document/Edit.phtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ require('./header.inc.phtml'); ?>
3535
<div class="alert alert-success">
3636
<p class="mb-0">The document was successfully edited!</p>
3737
</div>
38-
<a class="btn btn-primary" href="<?=Common::relativeUrlToAbsolute('/document/' . rawurlencode($document_id))?>">Back</a>
38+
<div class="text-center">
39+
<a class="btn btn-primary" href="<?=Common::relativeUrlToAbsolute('/document/' . rawurlencode($document_id))?>"><svg class="float-left align-middle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-right"><polyline points="9 18 15 12 9 6"></polyline></svg> Return to Document</a>
40+
</div>
3941
<? } ?>
4042
</div>
4143
<? require('./footer.inc.phtml'); ?>

src/templates/Document/Index.phtml

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,66 +16,63 @@ require('./header.inc.phtml'); ?>
1616
<label for="order">Order by:</label>
1717
<select class="form-control form-control-sm" name="order" id="order" onchange="form.submit();"
1818
style="display:inline-block;width:200px;">
19-
<option value="created-asc"<?php
19+
<option value="created-asc"<?
2020
if ($order === 'created-asc') { echo ' selected="selected"';
2121
} ?>>Created (Ascending)</option>
22-
<option value="created-desc"<?php
22+
<option value="created-desc"<?
2323
if ($order === 'created-desc') { echo ' selected="selected"';
2424
} ?>>Created (Descending)</option>
25-
<option value="id-asc"<?php
25+
<option value="id-asc"<?
2626
if ($order === 'id-asc') { echo ' selected="selected"';
2727
} ?>>Id (Ascending)</option>
28-
<option value="id-desc"<?php
28+
<option value="id-desc"<?
2929
if ($order === 'id-desc') { echo ' selected="selected"';
3030
} ?>>Id (Descending)</option>
31-
<option value="title-asc"<?php
31+
<option value="title-asc"<?
3232
if ($order === 'title-asc') { echo ' selected="selected"';
3333
} ?>>Title (Ascending)</option>
34-
<option value="title-desc"<?php
34+
<option value="title-desc"<?
3535
if ($order === 'title-desc') { echo ' selected="selected"';
3636
} ?>>Title (Descending)</option>
37-
<option value="updated-asc"<?php
37+
<option value="updated-asc"<?
3838
if ($order === 'updated-asc') { echo ' selected="selected"';
3939
} ?>>Updated (Ascending)</option>
40-
<option value="updated-desc"<?php
40+
<option value="updated-desc"<?
4141
if ($order === 'updated-desc') { echo ' selected="selected"';
4242
} ?>>Updated (Descending)</option>
43-
<option value="user-id-asc"<?php
43+
<option value="user-id-asc"<?
4444
if ($order === 'user-id-asc') { echo ' selected="selected"';
4545
} ?>>User Id (Ascending)</option>
46-
<option value="user-id-desc"<?php
46+
<option value="user-id-desc"<?
4747
if ($order === 'user-id-desc') { echo ' selected="selected"';
4848
} ?>>User Id (Descending)</option>
4949
</select>
5050
<input class="btn btn-sm btn-secondary" type="submit" value="Reorder"/>
5151
</form>
5252
<table class="table table-hover table-striped" id="docs_tbl">
53-
<thead>
54-
<tr>
55-
<th class="left">Found <?php echo number_format($this->getContext()->sum_documents); ?> document<?php echo ($this->getContext()->sum_documents != 1 ? "s" : ""); ?></th>
56-
<th class="left">Author</th>
57-
</tr>
58-
</thead><tbody>
59-
<?php foreach ($this->getContext()->documents as $document) {
60-
$user = $document->getUser();
61-
if ($user) {
62-
$user_url = $user->getURI();
63-
$avatar_url = $user->getAvatarURI(22);
64-
}
65-
?>
66-
<tr>
67-
<td><strong><a href="<?php echo $document->getURI(); ?>"><?php echo filter_var($document->getTitle(), FILTER_SANITIZE_STRING); ?></a></strong><br/><span style="color:#aaa;"><?php echo rtrim(Common::stripUpTo(Common::stripUpTo(trim(filter_var($document->getContent(true), FILTER_SANITIZE_STRING)), "\n", 90), ". ", 90), "."); ?></span></td>
68-
<td><?php if ($user) { ?><a href="<?php echo $user_url; ?>"><img class="avatar" src="<?php echo $avatar_url; ?>"/>&nbsp;<?php echo filter_var($user->getName(), FILTER_SANITIZE_STRING); ?></a><?php } else { ?>Anonymous<?php } ?></td>
69-
</tr>
70-
<?php } ?>
53+
<thead><tr><th class="left">Document</th><th class="left">Author</th></tr></thead><tbody>
54+
<? foreach ($this->getContext()->documents as $document)
55+
{
56+
$doc_title = filter_var($document->getTitle(), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
57+
$doc_brief = rtrim(Common::stripUpTo(Common::stripUpTo(trim(filter_var($document->getContent(true), FILTER_SANITIZE_STRING)), "\n", 128), '. ', 128), '.');
58+
$doc_user = $document->getUser();
59+
$doc_user_string = ($doc_user ?
60+
sprintf('<a href="%s"><img class="img-fluid rounded mr-2" src="%s"/>%s</a>',
61+
$doc_user->getURI(), $doc_user->getAvatarURI(40), filter_var($doc_user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS)
62+
) : 'Anonymous'
63+
);
64+
echo '<tr><td><strong><a href="' . $document->getURI() . '">' . $doc_title . '</a></strong><br/>'
65+
. '<span class="text-muted">' . $doc_brief . '</span></td><td>' . $doc_user_string . '</td></tr>';
66+
} ?>
7167
</tbody></table>
7268
</div>
73-
<?php ob_start(); ?>
69+
<? ob_start(); ?>
7470
<script type="text/javascript">
7571
$(document).ready(function(){
7672
$('#order_by_form').hide();
7773
$('#docs_tbl').DataTable({
78-
"responsive": true
74+
"language": {"zeroRecords": "No matching documents found"},
75+
"responsive": true,
7976
});
8077
});
8178
</script>

src/templates/Document/View.phtml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ if ($object)
2222
$created_dt = $object->getCreatedDateTime();
2323
$edited_dt = $object->getEditedDateTime();
2424
$user = $object->getUser();
25+
$draft = !$object->isPublished();
2526
}
2627
$this->opengraph->attach(new Pair('url', $url));
2728
$edit_url = Common::relativeUrlToAbsolute('/document/edit?id=' . rawurlencode($object_id));
@@ -31,7 +32,10 @@ $delete_visible = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION
3132
require_once('./MarkdownBootstrapFix.inc.php');
3233
require('./header.inc.phtml'); ?>
3334
<div class="container mb-3">
34-
<? if ($object) { ?>
35+
<? if ($object) {
36+
if ($draft) { ?>
37+
<div class="alert alert-warning">This document is marked as <strong>draft</strong>. Edit the document to <strong>publish</strong> it.</div>
38+
<? } ?>
3539
<span class="float-right ml-1"><a class="btn btn-sm btn-primary" href="https://twitter.com/share?text=<?=urlencode($title)?>&amp;url=<?=urlencode($url)?>" rel="external" data-popup="1"><img src="<?=Common::relativeUrlToAbsolute('/a/social-twitter-24px.png')?>"/></a></span>
3640
<span class="float-right ml-1"><a class="btn btn-sm btn-primary" href="https://facebook.com/sharer/sharer.php?u=<?=urlencode($url)?>" rel="external" data-popup="1"><img src="<?=Common::relativeUrlToAbsolute('/a/social-facebook-24px.png')?>"/></a></span>
3741
<? if ($delete_visible) { ?>

src/templates/MarkdownBootstrapFix.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function MarkdownBootstrapFix(string $v)
1616
$v = str_replace('<img ', '<img class="img-fluid" ', $v);
1717

1818
// Code Blocks
19-
$v = str_replace('<pre><code>', '<pre class="border border-primary p-2 pre-scrollable rounded text-light" style="overflow-y:auto;"><code>', $v);
19+
$v = str_replace('<pre><code>', '<pre class="border border-primary overflow-auto p-2 pre-scrollable rounded text-light"><code>', $v);
2020

2121
return $v;
2222
}

0 commit comments

Comments
 (0)