YaWK  24.1
Yet another WebKit
YAWK\PLUGINS\MESSAGES\messages Class Reference

The Messages Plugin Class. Allow your users to write messages to each other. More...

Public Member Functions

 __construct ($db, $location)
 messages constructor - check if class is called from frontend or backend More...
 
 drawInbox ($type, $messages, $lang)
 draw the complete Inbox More...
 
 drawMenu ($db, $lang)
 draw html (output) messages menu More...
 
 drawNewMessage ($to, $lang)
 draw a new message More...
 
 getInbox ($db, $lang)
 get inbox and draw menu More...
 
 MessageView ($db, $msg_id, $lang)
 view messages More...
 

Detailed Description

The Messages Plugin Class. Allow your users to write messages to each other.

Messages Plugin

Basic Messaging functions. This class serve functions fetch and draw messages, inbox and so on

Basic Features:

  • fetch all messages
  • fetch a single message
  • get Inbox Data
  • draw Inbox
  • mark messages as spam, read, unread
  • trash messages and many more


This plugin is definitly still in development.

Author
Daniel Retzl danie.nosp@m.lret.nosp@m.zl@gm.nosp@m.ail..nosp@m.com
Version
1.0.0/

Definition at line 21 of file messages.php.

Constructor & Destructor Documentation

◆ __construct()

YAWK\PLUGINS\MESSAGES\messages::__construct (   $db,
  $location 
)

messages constructor - check if class is called from frontend or backend

Parameters
object$dbdatabase
string$locationfrontend or backend

Definition at line 27 of file messages.php.

28  {
29  if (isset($location) && (!empty($location)))
30  { // check where the script is called from...
31  // get hostname
33  if ($location === "backend")
34  { // backend: set directory prefix
35  $prefix = "../";
36  }
37  else if ($location === "frontend")
38  { // frontend: no prefix needed
39  $prefix = $host.'';
40  }
41  else {
42  // default:
43  $prefix = $host.'';
44  }
45  }
46  else
47  { // if location is not set: no prefix as default
49  $prefix = '';
50  }
51 
52  echo "<script type=\"text/javascript\" src=\"$prefix"."system/plugins/messages/js/message-send.js\"></script>";
53  echo "<script type='text/javascript'>
54  function markAsSpam(msg_id)
55  {
56  $.ajax({
57  url:'$prefix"."system/plugins/messages/js/message-spam.php',
58  type:'post',
59  data:'msg_id='+msg_id,
60  success:function(data){
61  if(! data ){
62  alert('Something went wrong!');
63  return false;
64  }
65  else {
66  // hide affected row
67  $('#row-'+msg_id).css('color', '#610B0B').fadeToggle(400);
68  }
69  }
70  });
71  }
72 
73  function markAsTrash(msg_id)
74  {
75  $.ajax({
76  url:'$prefix"."system/plugins/messages/js/message-trash.php',
77  type:'post',
78  data:'msg_id='+msg_id,
79  success:function(data){
80  if(! data ){
81  alert('Something went wrong!');
82  return false;
83  }
84  else {
85  // hide affected row
86  $('#row-'+msg_id).fadeToggle(400);
87  }
88  }
89  });
90  }
91 
92  function closeMessage(msg_id)
93  {
94  $.ajax({
95  url:'$prefix"."system/plugins/messages/js/message-read.php',
96  type:'post',
97  data:'msg_id='+msg_id,
98  success:function(data){
99  if(! data ){
100  alert('Something went wrong!');
101  return false;
102  }
103  else {
104  // hide affected row
105  $('#messagebox').fadeToggle(400);
106  window.location.href = 'index.php?plugin=messages&pluginpage=mailbox';
107 
108  }
109  }
110  });
111  }
112 
113  function restoreFromTrash(msg_id)
114  {
115  $.ajax({
116  url:'$prefix"."system/plugins/messages/js/message-restore-trash.php',
117  type:'post',
118  data:'msg_id='+msg_id,
119  success:function(data){
120  if(! data ){
121  alert('Something went wrong!');
122  return false;
123  }
124  else {
125  // hide affected row
126  $('#row-'+msg_id).css('color', '#088A29').fadeToggle(400);
127  }
128  }
129  });
130  }
131 
132  function markAsDeleted(msg_id)
133  {
134  $.ajax({
135  url:'$prefix"."system/plugins/messages/js/message-delete.php',
136  type:'post',
137  data:'msg_id='+msg_id,
138  success:function(data){
139  if(! data ){
140  alert('Something went wrong!');
141  return false;
142  }
143  else {
144  // hide affected row
145  $('#row-'+msg_id).css('color', '#FF0000').fadeToggle(400);
146  }
147  }
148  });
149  }
150 
151  function markAsRead(msg_id)
152  {
153  $.ajax({
154  url:'$prefix"."system/plugins/messages/js/message-read.php',
155  type:'post',
156  data:'msg_id='+msg_id,
157  success:function(data){
158  if(! data ){
159  alert('Something went wrong!');
160  return false;
161  }
162  else {
163  // hide affected row
164  // $('#row-'+msg_id).toggleClass('bold', 'normal').fadeTo('fast', 0.8);
165  // $('#row-'+msg_id).toggleClass('normal', 'bold').fadeTo('fast', 1);
166  // $('#read-icon-'+msg_id).toggleClass('fa fa-envelope-o fa fa-envelope');
167  }
168  }
169  });
170  }
171 
172  function messageToggle(msg_id)
173  {
174  $.ajax({
175  url:'$prefix"."system/plugins/messages/js/message-toggle.php',
176  type:'post',
177  data:'msg_id='+msg_id,
178  success:function(data){
179  if(! data ){
180  alert('Something went wrong!');
181  return false;
182  }
183  else {
184  // hide affected row
185  $('#row-'+msg_id).toggleClass('bold', 'normal').fadeTo('fast', 0.8);
186  $('#row-'+msg_id).toggleClass('normal', 'bold').fadeTo('fast', 1);
187  $('#read-icon-'+msg_id).toggleClass('fa fa-envelope-o fa fa-envelope');
188  }
189  }
190  });
191  }
192  function refreshInbox(type)
193  {
194  $.ajax({
195  url:'$prefix"."system/plugins/messages/js/message-fetch.php',
196  type:'post',
197  data:'type='+type,
198  success:function(data){
199  if(! data ){
200  alert('Something went wrong!');
201  return false;
202  }
203  else {
204  // hide affected row
205  // alert('REFRESH! '+type);
206  // $('#row-'+id).fadeOut(420);
207  }
208  }
209  });
210  }
211 
212  </script>
213  <style type='text/css'>
214  .bold { font-weight: bold; }
215  .normal { font-weight: normal; opacity: 0.6; }
216  </style> ";
217  }
$prefix
Definition: actions.php:6
static getSetting($db, $property)
Get and return value for property from settings database.
Definition: settings.php:470
static getHost($db)
get hostname (url where yawk is installed) from database
Definition: sys.php:1115
$host
Definition: page-edit.php:65

References $db, $host, $prefix, YAWK\sys\getHost(), and YAWK\settings\getSetting().

Member Function Documentation

◆ drawInbox()

YAWK\PLUGINS\MESSAGES\messages::drawInbox (   $type,
  $messages,
  $lang 
)

draw the complete Inbox

Parameters
string$typespam, trash or all
array$messagesmessages array
Returns
string

Definition at line 433 of file messages.php.

433  {
434  $html = "<table class='table table-striped' id=\"table-sort\">
435  <tr style='font-weight:bold;' class='small'>
436  <td width='15%'>$lang[DATE]</td>
437  <td width='25%'>$lang[FROM] $lang[USER]</td>
438  <td width='50%'>$lang[MESSAGE] <small>($lang[PREVIEW])</small></td>
439  <td width='20%' style=\"text-align: center;\">$lang[ACTIONS]</td>
440  </tr>";
441  foreach ($messages as $email){
442  if ($email['msg_read'] === '0') { $style = "bold"; $envelope = "fa fa-envelope"; }
443  if ($email['msg_read'] === '1') { $style = "normal"; $envelope = "fa fa-envelope-o"; }
444 
445  if ($type === "trash" || $type === "spam")
446  {
447  if ($type === "spam")
448  {
449  $style = "text-danger";
450  $spam_icon = '';
451  $spam_action = '';
452  $spam_title = '';
453  }
454 
455  if ($type === "trash")
456  {
457  $spam_icon = '';
458  $spam_action = '';
459  $spam_title = '';
460  }
461 
462  $reply_icon = '';
463  $reply_action = '';
464  $reply_title = '';
465 
466  $revert_icon = "fa fa-undo";
467  $revert_action = "restoreFromTrash('$email[msg_id]')";
468  $revert_title = "$lang[RESTORE_MSG]";
469 
470  $trash_icon = "fa fa-trash";
471  $trash_action = "markAsDeleted('$email[msg_id]')";
472  $trash_title = "$lang[DEL_MSG]";
473  }
474  else
475  {
476  $revert_icon = $envelope;
477  $revert_action = "messageToggle('$email[msg_id]')";
478  $revert_title = "$lang[MARK_AS_READ]";
479 
480  $trash_icon = "fa fa-trash-o";
481  $trash_action = "markAsTrash('$email[msg_id]')";
482  $trash_title = "$lang[MOVE_TO_TRASH]";
483 
484  // $reply_icon = "fa fa-reply";
485  // $reply_action = "replyMessage('$email[msg_id]')";
486  // $reply_title = "reply";
487  // <i id=\"reply-$email[msg_id]\" class=\"$reply_icon\" onclick=\"$reply_action\" title=\"$reply_title\"></i>&nbsp;
488 
489 
490  $spam_icon = "fa fa-user-secret";
491  $spam_action = "markAsSpam('$email[msg_id]')";
492  $spam_title = "$lang[MARK_AS_SPAM]";
493  }
494  $msg_preview = substr($email['msg_body'],0 -64);
495  $html .= "
496  <tr id=\"row-$email[msg_id]\" class=\"$style\">
497  <td>$email[msg_date]</td>
498  <td><a href=\"index.php?plugin=messages&pluginpage=mailbox&msg_id=$email[msg_id]\"><div style=\"width:100%\">$email[username]</div></a></td>
499  <td><a href=\"index.php?plugin=messages&pluginpage=mailbox&msg_id=$email[msg_id]\"><div style=\"width:100%\">$msg_preview <small>[...]</small></div></a></td>
500  <td style=\"text-align:center\">
501  <i id=\"read-icon-$email[msg_id]\" class=\"$revert_icon\" onclick=\"$revert_action\" title=\"$revert_title\"></i>&nbsp;
502  <i class=\"$trash_icon\" onclick=\"$trash_action\" title=\"$trash_title\"></i>&nbsp;
503  <i class=\"$spam_icon\" onclick=\"$spam_action\" title=\"$spam_title\"></i>&nbsp;</td>
504  </tr>";
505  }
506  $html .= "</table>";
507  return $html;
508  }
$type
$messages
Definition: messages.php:14
$email
Definition: user-new.php:94

References $email, $messages, and $type.

Referenced by YAWK\PLUGINS\MESSAGES\messages\drawMenu().

◆ drawMenu()

YAWK\PLUGINS\MESSAGES\messages::drawMenu (   $db,
  $lang 
)

draw html (output) messages menu

Parameters
object$dbdatabase
Returns
string

Definition at line 515 of file messages.php.

516  { // check if there is an active tab request
517  if (isset($_GET['active']) && (!empty($_GET['active'])))
518  { // switch vars
519  switch ($_GET['active'])
520  { // set inbox as active tab
521  case "inbox":
522  $active_inbox = "class=\"active\"";
523  $active_inbox_tab_pane = 'class="tab-pane active"';
524  $active_compose = '';
525  $active_compose_tab_pane = 'tab-pane';
526  break;
527  // set compose as active tab
528  case "compose":
529  $active_inbox = '';
530  $active_inbox_tab_pane = 'class="tab-pane"';
531  $active_compose = "class=\"active\"";
532  $active_compose_tab_pane = "class='tab-pane active'";
533  }
534  }
535  else
536  { // set inbox as default active tab
537  $active_inbox = "class=\"active\"";
538  $active_inbox_tab_pane = 'class="tab-pane active"';
539  $active_compose = '';
540  $active_compose_tab_pane = "class='tab-pane'";
541  }
542  $html = "<div>
543  <!-- Nav tabs -->
544  <ul class=\"nav nav-tabs\" role=\"tablist\">
545  <li role=\"presentation\" $active_inbox onclick=\"refreshInbox('all')\"><a href=\"#inbox\" aria-controls=\"home\" role=\"tab\" data-toggle=\"tab\">
546  <i class=\"fa fa-envelope-o\"></i> &nbsp;$lang[INBOX]</a></li>
547 
548  <li role=\"presentation\" $active_compose><a href=\"#newmessage\" aria-controls=\"newmessage\" role=\"tab\" data-toggle=\"tab\">
549  <i class=\"fa fa-plus-square-o\"></i> &nbsp;$lang[MESSAGE]</a></li>
550 
551  <li role=\"presentation\"><a href=\"#trash\" aria-controls=\"messages\" role=\"tab\" data-toggle=\"tab\">
552  <i class=\"fa fa-trash-o\"></i> &nbsp;$lang[RECYCLE_BIN]</a></li>
553 
554  <li role=\"presentation\"><a href=\"#spam\" aria-controls=\"messages\" role=\"tab\" data-toggle=\"tab\">
555  <i class=\"fa fa-user-secret\"></i> &nbsp;$lang[SPAM]</a></li>
556  </ul>
557 
558  <!-- Tab panes -->
559  <div class=\"tab-content\">
560 
561  <!-- inbox -->
562  <div role=\"tabpanel\" $active_inbox_tab_pane id=\"inbox\">
563  <h4><i class=\"fa fa-envelope-o fa-2x\"></i> &nbsp;$lang[INBOX]</h4>";
564  // get inbox
565  $html .= self::drawInbox('all', self::fetchMessages($db, 'all'), $lang);
566  $html .= "
567  </div>
568 
569  <!-- new msg -->
570  <div role=\"tabpanel\" $active_compose_tab_pane id=\"newmessage\">
571  <h4><i class=\"fa fa-envelope fa-2x\"></i> &nbsp;$lang[MSG_COMPOSE]</h4>";
572  // get new message form
573  $html .= self::drawNewMessage('', $lang);
574  $html .= "</div>
575  <!-- trash -->
576  <div role=\"tabpanel\" class=\"tab-pane\" id=\"trash\">
577  <h4><i class=\"fa fa-trash fa-2x\"></i> &nbsp;$lang[RECYCLE_BIN_HEADING]</h4>";
578  // get trashed items
579  $html .= self::drawInbox('trash', self::fetchMessages($db, 'trash'), $lang);
580  $html .="</div>
581  <!-- spam -->
582  <div role=\"tabpanel\" class=\"tab-pane\" id=\"spam\">
583  <h4><i class=\"fa fa-user-secret fa-2x\"></i> &nbsp;$lang[SPAM_HEADING]</h4>";
584  // get spam items
585  $html .= self::drawInbox('spam', self::fetchMessages($db, 'spam'), $lang);
586  $html .= "</div>
587  </div>
588  </div>";
589  return $html;
590  }
print $lang['FILEMAN_UPLOAD']
drawNewMessage($to, $lang)
draw a new message
Definition: messages.php:597
drawInbox($type, $messages, $lang)
draw the complete Inbox
Definition: messages.php:433
print $_GET['id']
Definition: page-edit.php:357

References $_GET, $db, $lang, YAWK\PLUGINS\MESSAGES\messages\drawInbox(), and YAWK\PLUGINS\MESSAGES\messages\drawNewMessage().

Referenced by YAWK\PLUGINS\MESSAGES\messages\getInbox().

◆ drawNewMessage()

YAWK\PLUGINS\MESSAGES\messages::drawNewMessage (   $to,
  $lang 
)

draw a new message

Parameters
string$tousername to send
Returns
string message fieldset

Definition at line 597 of file messages.php.

597  {
598  $key = "U3E44ERG0H0M3";
599  if (isset($_GET['to']) && (!empty($_GET['to'])))
600  { // set new message recipient from given GET var
601  $to= $_GET['to'];
602  }
603  if (isset($to) && (!empty($to)))
604  {
605  $replyLabel = "$lang[REPLY_TO]";
606  $msg_to = "value=\"$to\"";
607  }
608  else
609  {
610  $replyLabel = "$lang[RECIPIENT_USERNAME]";
611  $msg_to = '';
612  }
613  return "
614  <fieldset id=\"comment_thread\" class=\"animated zoomInDown\">
615  <label for=\"msg_to\">$replyLabel</label> <input id=\"msg_to\" type=\"text\" $msg_to class=\"form-control\" name=\"msg_to\" size=\"16\" placeholder=\"to:\" maxlength=\"64\">
616  <label for=\"msg_body\">$lang[YOUR_MSG]</label> <textarea id=\"msg_body\" name=\"msg_body\" class=\"form-control\" cols=\"68\" rows=\"12\"></textarea><br>
617  <input type=\"button\" class=\"btn btn-success\" id=\"submit_post\" name=\"save_comment\" title=\"$lang[SEND]\" value=\"$lang[MSG_SEND_BTN]\">
618  <input type=\"hidden\" name=\"msg_from\" value=\"$_SESSION[username]\" id=\"msg_from\">
619  <input type=\"hidden\" name=\"fromUID\" value=\"$_SESSION[uid]\" id=\"fromUID\">
620  <input type=\"hidden\" name=\"token\" value=\"".$key."\" id=\"token\">
621  </fieldset>
622  ";
623  }
$msg_to
Definition: message-new.php:19

References $_GET, and $msg_to.

Referenced by YAWK\PLUGINS\MESSAGES\messages\drawMenu(), and YAWK\PLUGINS\MESSAGES\messages\MessageView().

◆ getInbox()

YAWK\PLUGINS\MESSAGES\messages::getInbox (   $db,
  $lang 
)

get inbox and draw menu

Parameters
object$dbdatabase
Returns
string

Definition at line 253 of file messages.php.

253  {
254  $html = "";
255  $html .= self::drawMenu($db, $lang);
256  return $html;
257  }
drawMenu($db, $lang)
draw html (output) messages menu
Definition: messages.php:515

References $db, $lang, and YAWK\PLUGINS\MESSAGES\messages\drawMenu().

◆ MessageView()

YAWK\PLUGINS\MESSAGES\messages::MessageView (   $db,
  $msg_id,
  $lang 
)

view messages

Parameters
object$dbdatabase
int$msg_idmessage ID
Returns
string

Definition at line 393 of file messages.php.

394  {
395  $message = self::fetchSingleMessage($db, $msg_id);
396  $from = \YAWK\user::getUserNameFromID($db, $message['fromUID']);
397  $picture = \YAWK\user::getUserImage("backend", $from, "img-circle", 64, 64);
398  $timeAgo = \YAWK\sys::time_ago($message['msg_date'], $lang);
399  $splitDate = \YAWK\sys::splitDateShort($message['msg_date']);
400  self::markAsRead($db, $msg_id);
401 
402  $html = "<br><br><br>
403  <div class=\"row\">
404  <div class=\"col-md-8\"><div class=\"box box-primary\">
405  <div class=\"box-header with-border\">
406  <h3 class=\"box-title\">$picture &nbsp;$lang[MESSAGE] $lang[FROM] <b><a href=\"index.php?page=user-edit&user=$from\">$from</a></b> $timeAgo <small>($splitDate[month], $splitDate[day] $splitDate[year], $splitDate[time])</small> </h3>
407  <div class=\"box-tools pull-right\">
408  <span class=\"label label-primary\">$message[msg_date]</span>
409  <button class=\"btn btn-box-tool\" data-widget=\"remove\" onclick=\"closeMessage('$message[msg_id]')\" data-toggle=\"tooltip\" title=\"$lang[CLOSE]\"><i class=\"fa fa-times\"></i></button>
410  </div>
411  <div class=\"box-body\"><h3>$message[msg_body]</h3><hr></div></div></div></div>
412  <div class=\"col-md-4\" id=\"messagebox\">";
413  $html .= self::drawNewMessage($from, $lang); $html .="</div>
414  </div>";
415 
416  $html .= "
417  <div class=\"row\">
418  <div class=\"col-md-8\">";
419  $html .= self::drawRelatedMessages($db, self::fetchRelatedMessages($db, $message['fromUID'], $message['toUID'], $message['msg_id']), $lang);
420 
421  $html .= "</div>
422  <div class=\"col-md-4\">&nbsp;</div>
423  </div>";
424  return $html;
425  }
static time_ago($userdate, $lang)
how many time is been gone since given date
Definition: sys.php:1630
static splitDateShort($date)
split a date to month, day, year and time this is the same as splitDate() but keep the months short
Definition: sys.php:1572
static getUserImage($location, $user, $cssClass, $w, $h)
return and output user image
Definition: user.php:1079
if(!isset($db)) $msg_id

References $db, $lang, $msg_id, YAWK\PLUGINS\MESSAGES\messages\drawNewMessage(), YAWK\user\getUserImage(), YAWK\sys\splitDateShort(), and YAWK\sys\time_ago().


The documentation for this class was generated from the following file: