-
Notifications
You must be signed in to change notification settings - Fork 100
Markdown support #24
base: master
Are you sure you want to change the base?
Markdown support #24
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,8 @@ | |
$range_end = mysql_real_escape_string($_POST['range_end']); | ||
$report_id = generateMeetingNotesID($range_start, $range_end); | ||
$notes = mysql_real_escape_string($_POST['weeklynotes']); | ||
$query = "INSERT INTO meeting_notes (report_id, range_start, range_end, timestamp, user, notes) VALUES ('$report_id', '$range_start', '$range_end', '$timestamp', '$username', '$notes')"; | ||
$notes_type = $_POST['editor']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. escaping here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh. I'll just swap in mysqli so we can stop worrying about this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Welp. I've fixed these two instances for now, but I'll hold off on using mysqli for when I'm sufficiently bored. :) |
||
$query = "INSERT INTO meeting_notes (report_id, range_start, range_end, timestamp, user, notes, notes_type) VALUES ('$report_id', '$range_start', '$range_end', '$timestamp', '$username', '$notes', '$notes_type')"; | ||
if (!mysql_query($query)) { | ||
echo "Database update failed, error: " . mysql_error(); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
$(function() { | ||
var unsaved_changes = false; | ||
|
||
$('textarea').on('change', function() { | ||
unsaved_changes = true; | ||
}); | ||
|
||
$('button[type=submit]').on('click', function() { | ||
unsaved_changes = false; | ||
}); | ||
|
||
window.onbeforeunload = function() { | ||
if (unsaved_changes) { | ||
return "You have unsaved changes"; | ||
} | ||
}; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/** | ||
* This is a editor. | ||
*/ | ||
|
||
class ExampleEditor { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like going overboard with OO principles but I think it makes sense to make an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quack quack. I like this. 👍 |
||
const TYPE = 'example'; | ||
|
||
/* | ||
* printEditor | ||
* Return any html necessary to render the editor | ||
* | ||
* @return string Some html | ||
*/ | ||
public function printEditor() { | ||
return ''; | ||
} | ||
|
||
/* | ||
* formatEntry | ||
* Format the entry using this editor | ||
* | ||
* @param string $data The input data | ||
* | ||
* @return string The output format | ||
*/ | ||
public function formatEntry($data) { | ||
return ''; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
include_once('markdown.php'); | ||
|
||
class MarkdownEditor { | ||
const TYPE = 'markdown'; | ||
|
||
public function printEditor() { | ||
return ''; | ||
} | ||
public function formatEntry($data) { | ||
return Markdown($data); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
class WYSIWYGEditor { | ||
const TYPE = 'wysiwyg'; | ||
|
||
public function printEditor() { | ||
return "<script>$('.textarea').wysihtml5({'image': false, 'color': false});</script>"; | ||
} | ||
public function formatEntry($data) { | ||
return $data; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,6 +237,37 @@ function printHeaderNav() { | |
} | ||
} | ||
|
||
function getEditor($editor_name) { | ||
global $editors; | ||
$editor_name = array_key_exists($editor_name, $editors) ? $editor_name:array_keys($editors)[0]; | ||
|
||
include_once($editors[$editor_name]['lib']); | ||
return new $editors[$editor_name]['class'](); | ||
} | ||
|
||
function getEditorNameByUser($username) { | ||
$editor_name = ''; | ||
$username = mysql_real_escape_string($username); | ||
if (connectToDB()) { | ||
$results = mysql_query("SELECT editor FROM user_profile where ldap_username='{$username}' LIMIT 1"); | ||
if (mysql_num_rows($results) == 1) { | ||
$editor_name = mysql_fetch_assoc($results)['editor']; | ||
} | ||
} | ||
|
||
return $editor_name; | ||
} | ||
|
||
function getEditorByUser($username, $override=null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might make more sense here to pass
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like. |
||
if ($override) { | ||
$editor_name = $override; | ||
} else { | ||
$editor_name = getEditorNameByUser($username); | ||
} | ||
|
||
return getEditor($editor_name); | ||
} | ||
|
||
function getGenericWeeklyReportsForWeek($range_start, $range_end) { | ||
connectToDB(); | ||
$query = "SELECT * FROM generic_weekly WHERE id IN (SELECT max(id) FROM generic_weekly where range_start='{$range_start}' AND range_end='{$range_end}' GROUP BY(user)) ORDER BY user ASC;"; | ||
|
@@ -481,22 +512,41 @@ function formatOnCallRowForPrint(array $n) { | |
} | ||
|
||
function formatWeeklyReportForPrint(array $data) { | ||
$editor = getEditor($data['report_type']); | ||
$content = $editor->formatEntry($data['report']); | ||
$pretty_time = getPrettyTime($data['timestamp']); | ||
$html = "<h3>{$data['user']}<small> written {$pretty_time}</small></h3>"; | ||
$html .= "<div class='well well-small'><p>{$data['report']}</p></div>"; | ||
$html .= "<div class='well well-small'><p>{$content}</p></div>"; | ||
|
||
return $html; | ||
} | ||
|
||
function formatMeetingNotesForPrint(array $data, $small_header = false) { | ||
$editor = getEditor($data['notes_type']); | ||
$content = $editor->formatEntry($data['notes']); | ||
$html = ($small_header) ? "<h4>Notes " : "<h2>Meeting Notes <small>"; | ||
$html .= "taken by {$data['user']} at the " . getTeamName() ." Meeting held on " . date("l jS F Y", $data['timestamp']); | ||
$html .= ($small_header) ? "</h4>" : "</small></h2>"; | ||
$html .= "<div class='well well-small'>{$data['notes']}</div>"; | ||
$html .= "<div class='well well-small'>{$content}</div>"; | ||
|
||
return $html; | ||
} | ||
|
||
function printEditorsList() { | ||
global $editors; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we make this not global but have a function to get the available editors or something like that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current design grabs the config data for each editor from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I feel like this is more consistent with the current architecture of the app. 🎱 |
||
|
||
echo '<div class="btn-group dropup">'; | ||
echo '<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">'; | ||
echo 'Editor <span class="caret"></span>'; | ||
echo '</a>'; | ||
echo '<ul class="dropdown-menu">'; | ||
foreach ($editors as $name=>$val) { | ||
printf('<li><a href="?editor=%s">%s</a></li>', $name, $name); | ||
} | ||
echo '</ul>'; | ||
echo '</div>'; | ||
} | ||
|
||
function printWeeklyHints($username, $from, $to) { | ||
$wanted_hints = getTeamConfig('weekly_hints'); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we also wanna escape this?