$1', $text);
+
+ // Code blocks
+ $text = preg_replace('/```(.+?)```/s', '$1', $text);
+
+ // Links
+ $text = preg_replace('/\[(.+?)\]\((.+?)\)/', '$1', $text);
+
+ // Blockquotes
+ $text = preg_replace('/^>\s+(.+)$/m', '$1', $text); + + // Unordered lists + $text = preg_replace('/^\-\s+(.+)$/m', '
(.+?)<\/code>/i', '`$1`', $markdown);
+ $markdown = preg_replace('/(.+?)<\/code><\/pre>/is', "```$1```", $markdown);
+
+ // Links
+ $markdown = preg_replace('/(.+?)<\/a>/i', '[$2]($1)', $markdown);
+
+ // Blockquotes
+ $markdown = preg_replace('/(.+?)<\/blockquote>/i', '> $1', $markdown);
+
+ // Lists (simplified)
+ $markdown = preg_replace('/(.+?)<\/ul>/is', '$1', $markdown);
+ $markdown = preg_replace('/- (.+?)<\/li>/i', '- $1', $markdown);
+
+ // Line breaks
+ $markdown = preg_replace('/
/i', "\n", $markdown);
+
+ // Decode HTML entities
+ $markdown = htmlspecialchars_decode($markdown, ENT_QUOTES);
+
+ // Clean up
+ $markdown = preg_replace('/\n{3,}/', "\n\n", $markdown);
+ $markdown = trim($markdown);
+
+ return $markdown;
+ }
+}
+?>
\ No newline at end of file
diff --git a/application/model/MessageModel.php b/application/model/MessageModel.php
index 6ecef85..3492ce4 100644
--- a/application/model/MessageModel.php
+++ b/application/model/MessageModel.php
@@ -6,8 +6,8 @@ class MessageModel
{
$database = DatabaseFactory::getFactory()->getConnection();
- $sql = "INSERT INTO messages (sender_id, receiver_id, group_type, subject, message)
- VALUES (:sender_id, :receiver_id, :group_type, :subject, :message)";
+ $sql = "INSERT INTO messages (sender_id, receiver_id, group_type, subject, message, is_read)
+ VALUES (:sender_id, :receiver_id, :group_type, :subject, :message, 0)";
$query = $database->prepare($sql);
return $query->execute(array(
':sender_id' => $sender_id,
@@ -170,6 +170,36 @@ class MessageModel
return $query->fetchAll();
}
+ public static function getGlobalMessages()
+ {
+ $database = DatabaseFactory::getFactory()->getConnection();
+
+ $sql = "SELECT m.*, u.user_name as sender_name,
+ 'received' as message_type
+ FROM messages m
+ JOIN users u ON m.sender_id = u.user_id
+ WHERE m.group_type = 'global'
+ AND m.receiver_id IS NULL
+ ORDER BY m.created_at ASC";
+
+ $query = $database->prepare($sql);
+ $query->execute();
+ return $query->fetchAll();
+ }
+
+ public static function sendToGlobal($sender_id, $message)
+ {
+ $database = DatabaseFactory::getFactory()->getConnection();
+
+ $sql = "INSERT INTO messages (sender_id, group_type, subject, message, is_read)
+ VALUES (:sender_id, 'global', 'Global Chat', :message, 1)";
+ $query = $database->prepare($sql);
+ return $query->execute(array(
+ ':sender_id' => $sender_id,
+ ':message' => $message
+ ));
+ }
+
public static function getAllUsers($current_user_id)
{
$database = DatabaseFactory::getFactory()->getConnection();
diff --git a/application/model/NoteModel.php b/application/model/NoteModel.php
index d67ba9f..704e96e 100644
--- a/application/model/NoteModel.php
+++ b/application/model/NoteModel.php
@@ -14,12 +14,20 @@ class NoteModel
{
$database = DatabaseFactory::getFactory()->getConnection();
- $sql = "SELECT user_id, note_id, note_text FROM notes WHERE user_id = :user_id";
+ $sql = "SELECT note_id, note_text, note_timestamp FROM notes WHERE user_id = :user_id ORDER BY note_timestamp DESC";
$query = $database->prepare($sql);
$query->execute(array(':user_id' => Session::get('user_id')));
// fetchAll() is the PDO method that gets all result rows
- return $query->fetchAll();
+ $notes = $query->fetchAll();
+
+ // Add markdown HTML to each note
+ require_once __DIR__ . '/../libs/SimpleMarkdown.php';
+ foreach ($notes as &$note) {
+ $note->note_html = SimpleMarkdown::parse($note->note_text);
+ }
+
+ return $notes;
}
/**
@@ -29,13 +37,21 @@ class NoteModel
*/
public static function getNote($note_id)
{
- $database = DatabaseFactory::getFactory()->getConnectionWithMySQLI();
+ $database = DatabaseFactory::getFactory()->getConnection();
- $sql = "SELECT user_id, note_id, note_text FROM notes WHERE user_id = :user_id AND note_id = :note_id LIMIT 1";
+ $sql = "SELECT note_id, note_text, note_timestamp FROM notes WHERE user_id = :user_id AND note_id = :note_id LIMIT 1";
$query = $database->prepare($sql);
$query->execute(array(':user_id' => Session::get('user_id'), ':note_id' => $note_id));
- return $query;
+ $result = $query->fetch();
+
+ // Add markdown HTML
+ if ($result) {
+ require_once __DIR__ . '/../libs/SimpleMarkdown.php';
+ $result->note_html = SimpleMarkdown::parse($result->note_text);
+ }
+
+ return $result ? $result : null;
}
/**
diff --git a/application/view/message/conversation.php b/application/view/message/conversation.php
index 7062df0..ebb1991 100644
--- a/application/view/message/conversation.php
+++ b/application/view/message/conversation.php
@@ -1,115 +1,17 @@
-
-
-
-
-
- Back to Messenger
-
-
-
-
+render('_templates/header'); ?>
-
-
-
-
-
- Conversation with = htmlspecialchars($this->other_user->user_name) ?>
-
-
-
-
-
-
+
+ renderFeedbackMessages(); ?>
+
+
+
+
+ Redirecting to Conversation...
+ If you're not redirected automatically, click here.
-
-
-
-
-
-render('_templates/footer'); ?>
+render('_templates/footer'); ?>
\ No newline at end of file
diff --git a/application/view/message/global.php b/application/view/message/global.php
new file mode 100644
index 0000000..d867812
--- /dev/null
+++ b/application/view/message/global.php
@@ -0,0 +1,17 @@
+render('_templates/header'); ?>
+
+
+ renderFeedbackMessages(); ?>
+
+
+
+
+ Redirecting to Global Chat...
+ If you're not redirected automatically, click here.
+
+
+
+render('_templates/footer'); ?>
\ No newline at end of file
diff --git a/application/view/message/index.php b/application/view/message/index.php
index 54779f2..7a072f5 100644
--- a/application/view/message/index.php
+++ b/application/view/message/index.php
@@ -1,175 +1,701 @@
-
- Messenger
+
+ Messenger
+ renderFeedbackMessages(); ?>
-
-
-
-
-
- Conversations
- unread_count > 0): ?>
- = $this->unread_count ?>
-
-
-
-
- conversations)): ?>
-
- No conversations yet
-
-
- conversations as $conv): ?>
-
-
- = htmlspecialchars($conv->user_name) ?>
- unread_count > 0): ?>
- = $conv->unread_count ?>
-
-
-
- = date('M j, Y', strtotime($conv->last_message_time)) ?>
-
-
-
-
-
-
-
+
+
+
+
-
-
- New Message
-
-