1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-27 01:40:22 +02:00

Code formatting and cleanup.

This commit is contained in:
Cameron
2017-04-12 17:23:03 -07:00
parent 544ff80f98
commit 1d4aa96be6

View File

@@ -1,5 +1,5 @@
<?php <?php
/* /*
* e107 website system * e107 website system
* *
* Copyright (C) 2008-2013 e107 Inc (e107.org) * Copyright (C) 2008-2013 e107 Inc (e107.org)
@@ -11,7 +11,7 @@
*/ */
/** /**
* e107 Private messenger plugin * e107 Private messenger plugin
* *
* @package e107_plugins * @package e107_plugins
@@ -19,33 +19,33 @@
*/ */
$retrieve_prefs[] = 'pm_prefs'; $retrieve_prefs[] = 'pm_prefs';
if (!defined('e107_INIT')) if(!defined('e107_INIT'))
{ {
require_once("../../class2.php"); require_once("../../class2.php");
} }
if (!e107::isInstalled('pm')) if(!e107::isInstalled('pm'))
{ {
e107::redirect(); e107::redirect();
exit; exit;
} }
if(vartrue($_POST['keyword'])) if(vartrue($_POST['keyword']))
{ {
pm_user_lookup(); pm_user_lookup();
} }
e107::css('pm','pm.css'); e107::css('pm', 'pm.css');
require_once(e_PLUGIN.'pm/pm_class.php'); require_once(e_PLUGIN . 'pm/pm_class.php');
require_once(e_PLUGIN.'pm/pm_func.php'); require_once(e_PLUGIN . 'pm/pm_func.php');
e107::includeLan(e_PLUGIN.'pm/languages/'.e_LANGUAGE.'.php'); e107::includeLan(e_PLUGIN . 'pm/languages/' . e_LANGUAGE . '.php');
e107::getScParser(); e107::getScParser();
// require_once(e_PLUGIN.'pm/shortcodes/batch/pm_shortcodes.php'); // require_once(e_PLUGIN.'pm/shortcodes/batch/pm_shortcodes.php');
if(!defined('ATTACHMENT_ICON')) if(!defined('ATTACHMENT_ICON'))
{ {
if(deftrue('BOOTSTRAP') && deftrue('FONTAWESOME')) if(deftrue('BOOTSTRAP') && deftrue('FONTAWESOME'))
{ {
define('ATTACHMENT_ICON', $tp->toGlyph('fa-paperclip')); define('ATTACHMENT_ICON', $tp->toGlyph('fa-paperclip'));
@@ -53,69 +53,73 @@ if(!defined('ATTACHMENT_ICON'))
else else
{ {
define('ATTACHMENT_ICON', "<img src='".e_PLUGIN."pm/images/attach.png' alt='' />"); define('ATTACHMENT_ICON', "<img src='" . e_PLUGIN . "pm/images/attach.png' alt='' />");
}
} }
}
if(deftrue('BOOTSTRAP') && deftrue('FONTAWESOME')) if(deftrue('BOOTSTRAP') && deftrue('FONTAWESOME'))
{ {
define('PM_DELETE_ICON', $tp->toGlyph('fa-trash', 'fw=1')); define('PM_DELETE_ICON', $tp->toGlyph('fa-trash', 'fw=1'));
} }
else else
{ {
define("PM_DELETE_ICON","<img src='".e_PLUGIN_ABS."pm/images/mail_delete.png' alt='".LAN_DELETE."' class='icon S16' />"); define("PM_DELETE_ICON", "<img src='" . e_PLUGIN_ABS . "pm/images/mail_delete.png' alt='" . LAN_DELETE . "' class='icon S16' />");
} }
$qs = explode('.', e_QUERY); $qs = explode('.', e_QUERY);
$action = varset($qs[0],'inbox'); $action = varset($qs[0], 'inbox');
if (!$action) $action = 'inbox'; if(!$action)
{
$action = 'inbox';
}
if(!empty($_GET['mode'])) if(!empty($_GET['mode']))
{ {
$action = $tp->filter($_GET['mode']); $action = $tp->filter($_GET['mode']);
} }
/* /*
if($action == 'textarea' || $action == 'input') if($action == 'textarea' || $action == 'input')
{ {
if($qs[1] == 'pm_to') { if($qs[1] == 'pm_to') {
require_once(e_HANDLER.'user_select_class.php'); require_once(e_HANDLER.'user_select_class.php');
$us = new user_select; $us = new user_select;
$us->popup(); $us->popup();
exit; exit;
} }
}*/ }*/
$pm_proc_id = intval(varset($qs[1],0)); $pm_proc_id = intval(varset($qs[1], 0));
//$pm_prefs = $sysprefs->getArray('pm_prefs'); //$pm_prefs = $sysprefs->getArray('pm_prefs');
$pm_prefs = e107::getPlugPref('pm'); $pm_prefs = e107::getPlugPref('pm');
$pm_prefs['perpage'] = intval($pm_prefs['perpage']); $pm_prefs['perpage'] = intval($pm_prefs['perpage']);
if($pm_prefs['perpage'] == 0) if($pm_prefs['perpage'] == 0)
{ {
$pm_prefs['perpage'] = 10; $pm_prefs['perpage'] = 10;
} }
if(!isset($pm_prefs['pm_class']) || !check_class($pm_prefs['pm_class'])) if(!isset($pm_prefs['pm_class']) || !check_class($pm_prefs['pm_class']))
{ {
require_once(HEADERF); require_once(HEADERF);
$ns->tablerender(LAN_PM, LAN_PM_12); $ns->tablerender(LAN_PM, LAN_PM_12);
require_once(FOOTERF); require_once(FOOTERF);
exit; exit;
} }
//setScVar('pm_handler_shortcodes','pmPrefs', $pm_prefs); //setScVar('pm_handler_shortcodes','pmPrefs', $pm_prefs);
$pmManager = new pmbox_manager($pm_prefs); $pmManager = new pmbox_manager($pm_prefs);
//setScVar('pm_handler_shortcodes','pmManager', &$pmManager);
//setScVar('pm_handler_shortcodes','pmManager', &$pmManager);
class pm_extended extends private_message class pm_extended extends private_message
{ {
protected $pmManager = NULL;
protected $pmManager = null;
/** /**
* Constructor * Constructor
@@ -130,7 +134,6 @@ class pm_extended extends private_message
} }
/** /**
* Show the 'Send to' form * Show the 'Send to' form
* @param array|int $to_uid - a PM block of message to reply to, or UID of user to send to * @param array|int $to_uid - a PM block of message to reply to, or UID of user to send to
@@ -142,24 +145,23 @@ class pm_extended extends private_message
$pm_info = array(); $pm_info = array();
$pm_outbox = $this->pmManager->pm_getInfo('outbox'); $pm_outbox = $this->pmManager->pm_getInfo('outbox');
if (is_array($to_uid)) if(is_array($to_uid))
{ {
$pm_info = $to_uid; // We've been passed a 'reply to' PM $pm_info = $to_uid; // We've been passed a 'reply to' PM
$to_uid = $pm_info['pm_from']; $to_uid = $pm_info['pm_from'];
} }
if(!empty($to_uid)) if(!empty($to_uid))
{ {
if($this->canSendTo($to_uid) == false) if($this->canSendTo($to_uid) == false)
{ {
return "<div class='alert alert-danger'>".LAN_PM_114."</div>";// sending to this user is not permitted. return "<div class='alert alert-danger'>" . LAN_PM_114 . "</div>";// sending to this user is not permitted.
} }
$sql2 = e107::getDb('sql2'); $sql2 = e107::getDb('sql2');
if($sql2->select('user', 'user_name', 'user_id = '.intval($to_uid))) //TODO add a check for userclass. if($sql2->select('user', 'user_name', 'user_id = ' . intval($to_uid))) //TODO add a check for userclass.
{ {
$row = $sql2->fetch(); $row = $sql2->fetch();
$pm_info['from_name'] = $row['user_name']; $pm_info['from_name'] = $row['user_name'];
@@ -167,36 +169,46 @@ class pm_extended extends private_message
} }
else else
{ {
return "<div class='alert alert-danger'>".LAN_PM_115."</div>"; return "<div class='alert alert-danger'>" . LAN_PM_115 . "</div>";
} }
} }
//echo "Show_send: {$to_uid} from {$pm_info['from_name']} is happening<br />"; //echo "Show_send: {$to_uid} from {$pm_info['from_name']} is happening<br />";
if($pm_outbox['outbox']['filled'] >= 100) if($pm_outbox['outbox']['filled'] >= 100)
{ {
return str_replace('{PERCENT}', $pm_outbox['outbox']['filled'], LAN_PM_13); return str_replace('{PERCENT}', $pm_outbox['outbox']['filled'], LAN_PM_13);
} }
// $tpl_file = THEME.'pm_template.php'; // $tpl_file = THEME.'pm_template.php';
// include_once(is_readable($tpl_file) ? $tpl_file : e_PLUGIN.'pm/pm_template.php'); // include_once(is_readable($tpl_file) ? $tpl_file : e_PLUGIN.'pm/pm_template.php');
if(THEME_LEGACY){
include_once(THEME.'pm_template.php'); if(THEME_LEGACY === true)
{
include_once(THEME . 'pm_template.php');
$PM_SEND_PM = $this->updateTemplate($PM_SEND_PM); $PM_SEND_PM = $this->updateTemplate($PM_SEND_PM);
} }
if (!$PM_SEND_PM){$PM_SEND_PM = e107::getTemplate('pm', 'pm', 'send');}
if(empty($PM_SEND_PM))
{
$PM_SEND_PM = e107::getTemplate('pm', 'pm', 'send');
}
$enc = (check_class($this->pmPrefs['attach_class']) ? "enctype='multipart/form-data'" : ''); $enc = (check_class($this->pmPrefs['attach_class']) ? "enctype='multipart/form-data'" : '');
// setScVar('pm_handler_shortcodes','pmInfo', $pm_info); // setScVar('pm_handler_shortcodes','pmInfo', $pm_info);
$sc = e107::getScBatch('pm',true, 'pm'); $sc = e107::getScBatch('pm', true, 'pm');
$sc->setVars($pm_info); $sc->setVars($pm_info);
$sc->wrapper('pm'); $sc->wrapper('pm');
// $PM_SEND_PM = $this->updateTemplate($PM_SEND_PM); // $PM_SEND_PM = $this->updateTemplate($PM_SEND_PM);
$text = "<form {$enc} method='post' action='".e_SELF."' id='dataform'> $text = "<form {$enc} method='post' action='" . e_REQUEST_SELF . "' id='dataform'>
<div><input type='hidden' name='numsent' value='{$pm_outbox['outbox']['total']}' />". <div><input type='hidden' name='numsent' value='{$pm_outbox['outbox']['total']}' />" .
e107::getParser()->parseTemplate($PM_SEND_PM, TRUE, $sc). e107::getParser()->parseTemplate($PM_SEND_PM, true, $sc) .
'</div></form>'; '</div></form>';
return $text; return $text;
} }
@@ -214,41 +226,50 @@ class pm_extended extends private_message
// $tpl_file = THEME.'pm_template.php'; // $tpl_file = THEME.'pm_template.php';
// include(is_readable($tpl_file) ? $tpl_file : e_PLUGIN.'pm/pm_template.php'); // include(is_readable($tpl_file) ? $tpl_file : e_PLUGIN.'pm/pm_template.php');
if(THEME_LEGACY){ if(THEME_LEGACY === true)
include_once(THEME.'pm_template.php'); {
include_once(THEME . 'pm_template.php');
// Is updateTemplate really necessary for v2.x templates? // Is updateTemplate really necessary for v2.x templates?
$PM_INBOX = array();
$PM_INBOX['start'] = $this->updateTemplate($PM_INBOX_HEADER); $PM_INBOX['start'] = $this->updateTemplate($PM_INBOX_HEADER);
$PM_INBOX['item'] = $this->updateTemplate($PM_INBOX_TABLE); $PM_INBOX['item'] = $this->updateTemplate($PM_INBOX_TABLE);
$PM_INBOX['empty'] = $this->updateTemplate($PM_INBOX_EMPTY); $PM_INBOX['empty'] = $this->updateTemplate($PM_INBOX_EMPTY);
$PM_INBOX['end'] = $this->updateTemplate($PM_INBOX_FOOTER); $PM_INBOX['end'] = $this->updateTemplate($PM_INBOX_FOOTER);
} }
if (!$PM_INBOX){$PM_INBOX = e107::getTemplate('pm', 'pm', 'inbox');}
if(empty($PM_INBOX))
{
$PM_INBOX = e107::getTemplate('pm', 'pm', 'inbox');
}
$pm_blocks = $this->block_get(); $pm_blocks = $this->block_get();
$pmlist = $this->pm_get_inbox(USERID, $start, $this->pmPrefs['perpage']); $pmlist = $this->pm_get_inbox(USERID, $start, $this->pmPrefs['perpage']);
// setScVar('pm_handler_shortcodes', 'pmNextPrev', array('start' => $start, 'total' => $pmlist['total_messages'])); // setScVar('pm_handler_shortcodes', 'pmNextPrev', array('start' => $start, 'total' => $pmlist['total_messages']));
$sc = e107::getScBatch('pm',true, 'pm'); $sc = e107::getScBatch('pm', true, 'pm');
$sc->pmNextPrev = array('start' => $start, 'total' => $pmlist['total_messages']); $sc->pmNextPrev = array('start' => $start, 'total' => $pmlist['total_messages']);
$sc->wrapper('pm'); $sc->wrapper('pm');
// Is updateTemplate really necessary for v2.x templates? // Is updateTemplate really necessary for v2.x templates?
/* /*
$PM_INBOX_HEADER = $this->updateTemplate($PM_INBOX['start']); $PM_INBOX_HEADER = $this->updateTemplate($PM_INBOX['start']);
$PM_INBOX_TABLE = $this->updateTemplate($PM_INBOX['item']); $PM_INBOX_TABLE = $this->updateTemplate($PM_INBOX['item']);
$PM_INBOX_EMPTY = $this->updateTemplate($PM_INBOX['empty']); $PM_INBOX_EMPTY = $this->updateTemplate($PM_INBOX['empty']);
$PM_INBOX_FOOTER = $this->updateTemplate($PM_INBOX['end']); $PM_INBOX_FOOTER = $this->updateTemplate($PM_INBOX['end']);
*/ */
$txt = "<form method='post' action='".e_REQUEST_SELF."?".e_QUERY."'>"; $txt = "<form method='post' action='" . e_REQUEST_SELF . "?" . e_QUERY . "'>";
$txt .= $tp->parseTemplate($PM_INBOX['start'], true, $sc); $txt .= $tp->parseTemplate($PM_INBOX['start'], true, $sc);
if($pmlist['total_messages']) if($pmlist['total_messages'])
{ {
foreach($pmlist['messages'] as $rec) foreach($pmlist['messages'] as $rec)
{ {
if(trim($rec['pm_subject']) == '') { $rec['pm_subject'] = '['.LAN_PM_61.']'; } if(trim($rec['pm_subject']) == '')
{
$rec['pm_subject'] = '[' . LAN_PM_61 . ']';
}
$sc->setVars($rec); $sc->setVars($rec);
$txt .= $tp->parseTemplate($PM_INBOX['item'], true, $sc); $txt .= $tp->parseTemplate($PM_INBOX['item'], true, $sc);
} }
@@ -278,16 +299,22 @@ class pm_extended extends private_message
// $tpl_file = THEME.'pm_template.php'; // $tpl_file = THEME.'pm_template.php';
// include(is_readable($tpl_file) ? $tpl_file : e_PLUGIN.'pm/pm_template.php'); // include(is_readable($tpl_file) ? $tpl_file : e_PLUGIN.'pm/pm_template.php');
if(THEME_LEGACY){ if(THEME_LEGACY === true)
include_once(THEME.'pm_template.php'); {
include_once(THEME . 'pm_template.php');
// Is updateTemplate really necessary for v2.x templates? // Is updateTemplate really necessary for v2.x templates?
$PM_OUTBOX = array();
$PM_OUTBOX['start'] = $this->updateTemplate($PM_OUTBOX_HEADER); $PM_OUTBOX['start'] = $this->updateTemplate($PM_OUTBOX_HEADER);
$PM_OUTBOX['item'] = $this->updateTemplate($PM_OUTBOX_TABLE); $PM_OUTBOX['item'] = $this->updateTemplate($PM_OUTBOX_TABLE);
$PM_OUTBOX['empty'] = $this->updateTemplate($PM_OUTBOX_EMPTY); $PM_OUTBOX['empty'] = $this->updateTemplate($PM_OUTBOX_EMPTY);
$PM_OUTBOX['end'] = $this->updateTemplate($PM_OUTBOX_FOOTER); $PM_OUTBOX['end'] = $this->updateTemplate($PM_OUTBOX_FOOTER);
} }
if (!$PM_OUTBOX){$PM_OUTBOX = e107::getTemplate('pm', 'pm', 'outbox');}
if(empty($PM_OUTBOX))
{
$PM_OUTBOX = e107::getTemplate('pm', 'pm', 'outbox');
}
$pmlist = $this->pm_get_outbox(USERID, $start, $this->pmPrefs['perpage']); $pmlist = $this->pm_get_outbox(USERID, $start, $this->pmPrefs['perpage']);
// setScVar('pm_handler_shortcodes', 'pmNextPrev', array('start' => $start, 'total' => $pmlist['total_messages'])); // setScVar('pm_handler_shortcodes', 'pmNextPrev', array('start' => $start, 'total' => $pmlist['total_messages']));
@@ -297,19 +324,23 @@ class pm_extended extends private_message
$sc->wrapper('pm'); $sc->wrapper('pm');
// Is updateTemplate really necessary for v2.x templates? // Is updateTemplate really necessary for v2.x templates?
/* /*
$PM_OUTBOX_HEADER = $this->updateTemplate($PM_OUTBOX['start']); $PM_OUTBOX_HEADER = $this->updateTemplate($PM_OUTBOX['start']);
$PM_OUTBOX_TABLE = $this->updateTemplate($PM_OUTBOX['item']); $PM_OUTBOX_TABLE = $this->updateTemplate($PM_OUTBOX['item']);
$PM_OUTBOX_EMPTY = $this->updateTemplate($PM_OUTBOX['empty']); $PM_OUTBOX_EMPTY = $this->updateTemplate($PM_OUTBOX['empty']);
$PM_OUTBOX_FOOTER = $this->updateTemplate($PM_OUTBOX['end']); $PM_OUTBOX_FOOTER = $this->updateTemplate($PM_OUTBOX['end']);
*/ */
$txt = "<form method='post' action='".e_SELF."?".e_QUERY."'>"; $txt = "<form method='post' action='" . e_REQUEST_SELF . "?" . e_QUERY . "'>";
$txt .= $tp->parseTemplate($PM_OUTBOX['start'], true, $sc); $txt .= $tp->parseTemplate($PM_OUTBOX['start'], true, $sc);
if($pmlist['total_messages']) if($pmlist['total_messages'])
{ {
foreach($pmlist['messages'] as $rec) foreach($pmlist['messages'] as $rec)
{ {
if(trim($rec['pm_subject']) == '') { $rec['pm_subject'] = '['.LAN_PM_61.']'; } if(trim($rec['pm_subject']) == '')
{
$rec['pm_subject'] = '[' . LAN_PM_61 . ']';
}
// setScVar('pm_handler_shortcodes','pmInfo', $rec); // setScVar('pm_handler_shortcodes','pmInfo', $rec);
$sc->setVars($rec); $sc->setVars($rec);
$txt .= $tp->parseTemplate($PM_OUTBOX['item'], true, $sc); $txt .= $tp->parseTemplate($PM_OUTBOX['item'], true, $sc);
@@ -321,6 +352,7 @@ class pm_extended extends private_message
} }
$txt .= $tp->parseTemplate($PM_OUTBOX['end'], true, $sc); $txt .= $tp->parseTemplate($PM_OUTBOX['end'], true, $sc);
$txt .= '</form>'; $txt .= '</form>';
return $txt; return $txt;
} }
@@ -338,23 +370,28 @@ class pm_extended extends private_message
// $tpl_file = THEME.'pm_template.php'; // $tpl_file = THEME.'pm_template.php';
// include_once(is_readable($tpl_file) ? $tpl_file : e_PLUGIN.'pm/pm_template.php'); // include_once(is_readable($tpl_file) ? $tpl_file : e_PLUGIN.'pm/pm_template.php');
if(THEME_LEGACY){ if(THEME_LEGACY === true)
include_once(THEME.'pm_template.php'); {
$PM_SHOW = null;
include_once(THEME . 'pm_template.php');
$PM_SHOW = $this->updateTemplate($PM_SHOW); $PM_SHOW = $this->updateTemplate($PM_SHOW);
} }
if (!$PM_SHOW){$PM_SHOW = e107::getTemplate('pm', 'pm', 'show');}
if(empty($PM_SHOW))
{
$PM_SHOW = e107::getTemplate('pm', 'pm', 'show');
}
$pm_info = $this->pm_get($pmid); $pm_info = $this->pm_get($pmid);
$sc = e107::getScBatch('pm',true, 'pm'); $sc = e107::getScBatch('pm', true, 'pm');
$sc->setVars($pm_info); $sc->setVars($pm_info);
$sc->wrapper('pm'); $sc->wrapper('pm');
if($pm_info['pm_to'] != USERID && $pm_info['pm_from'] != USERID) if($pm_info['pm_to'] != USERID && $pm_info['pm_from'] != USERID)
{ {
$ns->tablerender(LAN_PM, LAN_PM_60); $ns->tablerender(LAN_PM, LAN_PM_60);
return; return null;
} }
if($pm_info['pm_read'] == 0 && $pm_info['pm_to'] == USERID) if($pm_info['pm_read'] == 0 && $pm_info['pm_to'] == USERID)
@@ -372,32 +409,43 @@ class pm_extended extends private_message
if($comeFrom == 'outbox') if($comeFrom == 'outbox')
{ {
$bread = array('text'=> LAN_PLUGIN_PM_OUTBOX, 'url'=>e107::url('pm','index').'?mode=outbox'); $bread = array('text' => LAN_PLUGIN_PM_OUTBOX, 'url' => e107::url('pm', 'index') . '?mode=outbox');
} }
else else
{ {
$bread = array('text'=> LAN_PLUGIN_PM_INBOX, 'url'=>e107::url('pm','index').'?mode=inbox'); $bread = array('text' => LAN_PLUGIN_PM_INBOX, 'url' => e107::url('pm', 'index') . '?mode=inbox');
} }
$ns->tablerender(LAN_PM, $this->breadcrumb($bread ,'#'.$pmid).$txt); $ns->tablerender(LAN_PM, $this->breadcrumb($bread, '#' . $pmid) . $txt);
if (!$comeFrom) if(!$comeFrom)
{ {
if ($pm_info['pm_from'] == USERID) { $comeFrom = 'outbox'; } if($pm_info['pm_from'] == USERID)
{
$comeFrom = 'outbox';
}
} }
// Need to show inbox or outbox from start // Need to show inbox or outbox from start
if ($comeFrom == 'outbox') if($comeFrom == 'outbox')
{ // Show Outbox { // Show Outbox
$caption = ''; $caption = '';
if(!deftrue('BOOTSTRAP')){ $caption .= LAN_PM." - ".LAN_PLUGIN_PM_OUTBOX; } if(!deftrue('BOOTSTRAP'))
{
$caption .= LAN_PM . " - " . LAN_PLUGIN_PM_OUTBOX;
}
$ns->tablerender($caption, $this->show_outbox(), 'PM'); $ns->tablerender($caption, $this->show_outbox(), 'PM');
} }
else else
{ // Show Inbox { // Show Inbox
$caption = ''; $caption = '';
if(!deftrue('BOOTSTRAP')){ $caption .= LAN_PM." - ".LAN_PLUGIN_PM_INBOX; } if(!deftrue('BOOTSTRAP'))
{
$caption .= LAN_PM . " - " . LAN_PLUGIN_PM_INBOX;
}
$ns->tablerender($caption, $this->show_inbox(), 'PM'); $ns->tablerender($caption, $this->show_inbox(), 'PM');
} }
} }
@@ -414,33 +462,40 @@ class pm_extended extends private_message
$tp = e107::getParser(); $tp = e107::getParser();
// $tpl_file = THEME.'pm_template.php'; // $tpl_file = THEME.'pm_template.php';
// include(is_readable($tpl_file) ? $tpl_file : e_PLUGIN.'pm/pm_template.php'); // include(is_readable($tpl_file) ? $tpl_file : e_PLUGIN.'pm/pm_template.php');
if(THEME_LEGACY){ if(THEME_LEGACY === true)
include_once(THEME.'pm_template.php'); {
include_once(THEME . 'pm_template.php');
// Is updateTemplate really necessary for v2.x templates? // Is updateTemplate really necessary for v2.x templates?
$PM_BLOCKED = array();
$PM_BLOCKED['start'] = $this->updateTemplate($PM_BLOCKED_HEADER); $PM_BLOCKED['start'] = $this->updateTemplate($PM_BLOCKED_HEADER);
$PM_BLOCKED['item'] = $this->updateTemplate($PM_BLOCKED_TABLE); $PM_BLOCKED['item'] = $this->updateTemplate($PM_BLOCKED_TABLE);
$PM_BLOCKED['empty'] = $this->updateTemplate($PM_BLOCKED_EMPTY); $PM_BLOCKED['empty'] = $this->updateTemplate($PM_BLOCKED_EMPTY);
$PM_BLOCKED['end'] = $this->updateTemplate($PM_BLOCKED_FOOTER); $PM_BLOCKED['end'] = $this->updateTemplate($PM_BLOCKED_FOOTER);
} }
if (!$PM_BLOCKED){$PM_BLOCKED = e107::getTemplate('pm', 'pm', 'blocked');}
if(empty($PM_BLOCKED))
{
$PM_BLOCKED = e107::getTemplate('pm', 'pm', 'blocked');
}
$pmBlocks = $this->block_get_user(); // TODO - handle pagination, maybe (is it likely to be necessary?) $pmBlocks = $this->block_get_user(); // TODO - handle pagination, maybe (is it likely to be necessary?)
$sc = e107::getScBatch('pm',TRUE, 'pm'); $sc = e107::getScBatch('pm', true, 'pm');
$sc->pmBlocks = $pmBlocks; $sc->pmBlocks = $pmBlocks;
$sc->wrapper('pm'); $sc->wrapper('pm');
// Is updateTemplate really necessary for v2.x templates? // Is updateTemplate really necessary for v2.x templates?
/* /*
$PM_BLOCKED_HEADER = $this->updateTemplate($PM_BLOCKED['start']); $PM_BLOCKED_HEADER = $this->updateTemplate($PM_BLOCKED['start']);
$PM_BLOCKED_TABLE = $this->updateTemplate($PM_BLOCKED['item']); $PM_BLOCKED_TABLE = $this->updateTemplate($PM_BLOCKED['item']);
$PM_BLOCKED_EMPTY = $this->updateTemplate($PM_BLOCKED['empty']); $PM_BLOCKED_EMPTY = $this->updateTemplate($PM_BLOCKED['empty']);
$PM_BLOCKED_FOOTER = $this->updateTemplate($PM_BLOCKED['end']); $PM_BLOCKED_FOOTER = $this->updateTemplate($PM_BLOCKED['end']);
*/ */
$txt = "<form method='post' action='".e_SELF."?".e_QUERY."'>"; $txt = "<form method='post' action='" . e_REQUEST_SELF . "?" . e_QUERY . "'>";
$txt .= $tp->parseTemplate($PM_BLOCKED['start'], true, $sc); $txt .= $tp->parseTemplate($PM_BLOCKED['start'], true, $sc);
if($pmTotalBlocked = count($pmBlocks)) if($pmTotalBlocked = count($pmBlocks))
{ {
foreach($pmBlocks as $pmBlocked) foreach($pmBlocks as $pmBlocked)
@@ -456,6 +511,7 @@ class pm_extended extends private_message
} }
$txt .= $tp->parseTemplate($PM_BLOCKED['end'], true, $sc); $txt .= $tp->parseTemplate($PM_BLOCKED['end'], true, $sc);
$txt .= '</form>'; $txt .= '</form>';
return $txt; return $txt;
} }
@@ -521,7 +577,7 @@ class pm_extended extends private_message
{ {
if($to_info = $this->pm_getuid($to)) if($to_info = $this->pm_getuid($to))
{ // Check whether sender is blocked - if so, add one to count { // Check whether sender is blocked - if so, add one to count
if(!e107::getDb()->update('private_msg_block',"pm_block_count=pm_block_count+1 WHERE pm_block_from = '".USERID."' AND pm_block_to = '".e107::getParser()->toDB($to)."'")) if(!e107::getDb()->update('private_msg_block', "pm_block_count=pm_block_count+1 WHERE pm_block_from = '" . USERID . "' AND pm_block_to = '" . e107::getParser()->toDB($to) . "'"))
{ {
$_POST['to_array'][] = $to_info; $_POST['to_array'][] = $to_info;
} }
@@ -539,9 +595,9 @@ class pm_extended extends private_message
return LAN_PM_17; return LAN_PM_17;
} }
if(e107::getDb()->update('private_msg_block',"pm_block_count=pm_block_count+1 WHERE pm_block_from = '".USERID."' AND pm_block_to = '{$to_info['user_id']}'")) if(e107::getDb()->update('private_msg_block', "pm_block_count=pm_block_count+1 WHERE pm_block_from = '" . USERID . "' AND pm_block_to = '{$to_info['user_id']}'"))
{ {
return LAN_PM_18.$to_info['user_name']; return LAN_PM_18 . $to_info['user_name'];
} }
} }
} }
@@ -562,7 +618,7 @@ class pm_extended extends private_message
{ {
if($maxsize > 0 && $_FILES['file_userfile']['size'][$fid] > $maxsize) if($maxsize > 0 && $_FILES['file_userfile']['size'][$fid] > $maxsize)
{ {
$msg .= str_replace("{FILENAME}", $_FILES['file_userfile']['name'][$fid], LAN_PM_62)."<br />"; $msg .= str_replace("{FILENAME}", $_FILES['file_userfile']['name'][$fid], LAN_PM_62) . "<br />";
$_FILES['file_userfile']['size'][$fid] = 0; $_FILES['file_userfile']['size'][$fid] = 0;
} }
$totalsize += $_FILES['file_userfile']['size'][$fid]; $totalsize += $_FILES['file_userfile']['size'][$fid];
@@ -597,14 +653,14 @@ class pm_extended extends private_message
{ {
if(!empty($var['message'])) if(!empty($var['message']))
{ {
$msg .= $var['message']."<br />"; $msg .= $var['message'] . "<br />";
} }
} }
} }
else else
{ {
$msg .= LAN_PM_23.'<br />'; $msg .= LAN_PM_23 . '<br />';
unset($_POST['uploaded']); unset($_POST['uploaded']);
} }
@@ -612,7 +668,7 @@ class pm_extended extends private_message
$_POST['from_id'] = USERID; $_POST['from_id'] = USERID;
return $msg.$this->add($_POST); return $msg . $this->add($_POST);
} }
} }
@@ -620,14 +676,13 @@ class pm_extended extends private_message
function processAttachments() function processAttachments()
{ {
$randnum = rand(1000, 9999); $randnum = rand(1000, 9999);
$type = 'attachment+'.$randnum.'_'; $type = 'attachment+' . $randnum . '_';
return e107::getFile()->getUploaded("attachments",$type, array('max_file_count'=>3));
return e107::getFile()->getUploaded("attachments", $type, array('max_file_count' => 3));
} }
function breadcrumb($type = '', $other)
function breadcrumb($type='',$other)
{ {
if(!deftrue('BOOTSTRAP')) if(!deftrue('BOOTSTRAP'))
{ {
@@ -635,11 +690,11 @@ class pm_extended extends private_message
} }
$array = array(); $array = array();
$array[0] = array('text'=>LAN_PM, 'url'=>e107::url('pm','index')); $array[0] = array('text' => LAN_PM, 'url' => e107::url('pm', 'index'));
if(is_string($type)) if(is_string($type))
{ {
$array[1] = array('text'=>$type, 'url'=>null); $array[1] = array('text' => $type, 'url' => null);
} }
elseif(is_array($type)) elseif(is_array($type))
{ {
@@ -648,98 +703,92 @@ class pm_extended extends private_message
if($other) if($other)
{ {
$array[2] = array('text'=>$other, 'url'=>null); $array[2] = array('text' => $other, 'url' => null);
} }
return e107::getForm()->breadcrumb($array); return e107::getForm()->breadcrumb($array);
} }
} }
/**
/**
* Look up users matching a keyword, output a list of those found * Look up users matching a keyword, output a list of those found
* Direct echo * Direct echo
*/ */
function pm_user_lookup() function pm_user_lookup()
{ {
$sql = e107::getDb(); $sql = e107::getDb();
$tp = e107::getParser(); $tp = e107::getParser();
$query = "SELECT * FROM #user WHERE user_name REGEXP '^".$tp->filter($_POST['keyword'],'w')."' "; $query = "SELECT * FROM #user WHERE user_name REGEXP '^" . $tp->filter($_POST['keyword'], 'w') . "' ";
if($sql->gen($query)) if($sql->gen($query))
{ {
echo '['; echo '[';
while($row = $sql->fetch()) while($row = $sql->fetch())
{ {
$u[] = "{\"caption\":\"".$row['user_name']."\",\"value\":".$row['user_id']."}"; $u[] = "{\"caption\":\"" . $row['user_name'] . "\",\"value\":" . $row['user_id'] . "}";
} }
echo implode(",",$u); echo implode(",", $u);
echo ']'; echo ']';
} }
exit; exit;
} }
//$pm =& new private_message;
$pm = new pm_extended($pm_prefs, $pmManager);
$message = '';
//$pm =& new private_message; $pmSource = '';
$pm = new pm_extended($pm_prefs, $pmManager); if(isset($_POST['pm_come_from']))
{
$message = '';
$pmSource = '';
if (isset($_POST['pm_come_from']))
{
$pmSource = $tp->toDB($_POST['pm_come_from']); $pmSource = $tp->toDB($_POST['pm_come_from']);
} }
elseif (isset($qs[2])) elseif(isset($qs[2]))
{ {
$pmSource = $tp->toDB($qs[2]); $pmSource = $tp->toDB($qs[2]);
} }
//Auto-delete message, if timeout set in admin
//Auto-delete message, if timeout set in admin $del_qry = array();
$del_qry = array(); $read_timeout = intval($pm_prefs['read_timeout']);
$read_timeout = intval($pm_prefs['read_timeout']); $unread_timeout = intval($pm_prefs['unread_timeout']);
$unread_timeout = intval($pm_prefs['unread_timeout']); if($read_timeout > 0)
if($read_timeout > 0) {
{ $timeout = time() - ($read_timeout * 86400);
$timeout = time()-($read_timeout * 86400);
$del_qry[] = "(pm_sent < {$timeout} AND pm_read > 0)"; $del_qry[] = "(pm_sent < {$timeout} AND pm_read > 0)";
} }
if($unread_timeout > 0) if($unread_timeout > 0)
{ {
$timeout = time()-($unread_timeout * 86400); $timeout = time() - ($unread_timeout * 86400);
$del_qry[] = "(pm_sent < {$timeout} AND pm_read = 0)"; $del_qry[] = "(pm_sent < {$timeout} AND pm_read = 0)";
} }
if(count($del_qry) > 0) if(count($del_qry) > 0)
{ {
$qry = implode(' OR ', $del_qry).' AND (pm_from = '.USERID.' OR pm_to = '.USERID.')'; $qry = implode(' OR ', $del_qry) . ' AND (pm_from = ' . USERID . ' OR pm_to = ' . USERID . ')';
if($sql->select('private_msg', 'pm_id', $qry)) if($sql->select('private_msg', 'pm_id', $qry))
{ {
$delList = $sql->db_getList(); $delList = $sql->db_getList();
foreach($delList as $p) foreach($delList as $p)
{ {
$pm->del($p['pm_id'], TRUE); $pm->del($p['pm_id'], true);
}
} }
} }
}
if('del' == $action || isset($_POST['pm_delete_selected'])) if('del' == $action || isset($_POST['pm_delete_selected']))
{ {
if(isset($_POST['pm_delete_selected'])) if(isset($_POST['pm_delete_selected']))
{ {
foreach(array_keys($_POST['selected_pm']) as $id) foreach(array_keys($_POST['selected_pm']) as $id)
{ {
$message .= LAN_PM_24.": {$id} <br />"; $message .= LAN_PM_24 . ": {$id} <br />";
$message .= $pm->del($id); $message .= $pm->del($id);
} }
} }
@@ -747,7 +796,7 @@ if('del' == $action || isset($_POST['pm_delete_selected']))
{ {
$message = $pm->del($pm_proc_id); $message = $pm->del($pm_proc_id);
} }
if ($pmSource) if($pmSource)
{ {
$action = $pmSource; $action = $pmSource;
} }
@@ -764,17 +813,17 @@ if('del' == $action || isset($_POST['pm_delete_selected']))
} }
$pm_proc_id = 0; $pm_proc_id = 0;
unset($qs); unset($qs);
} }
if('delblocked' == $action || isset($_POST['pm_delete_blocked_selected'])) if('delblocked' == $action || isset($_POST['pm_delete_blocked_selected']))
{ {
if(isset($_POST['pm_delete_blocked_selected'])) if(isset($_POST['pm_delete_blocked_selected']))
{ {
foreach(array_keys($_POST['selected_pm']) as $id) foreach(array_keys($_POST['selected_pm']) as $id)
{ {
$message .= LAN_PM_70.": {$id} <br />"; $message .= LAN_PM_70 . ": {$id} <br />";
$message .= $pm->block_del($id).'<br />'; $message .= $pm->block_del($id) . '<br />';
} }
} }
elseif('delblocked' == $action) elseif('delblocked' == $action)
@@ -784,88 +833,98 @@ if('delblocked' == $action || isset($_POST['pm_delete_blocked_selected']))
$action = 'blocked'; $action = 'blocked';
$pm_proc_id = 0; $pm_proc_id = 0;
unset($qs); unset($qs);
} }
if('block' == $action) if('block' == $action)
{ {
$message = $pm->block_add($pm_proc_id); $message = $pm->block_add($pm_proc_id);
$action = 'inbox'; $action = 'inbox';
$pm_proc_id = 0; $pm_proc_id = 0;
} }
if('unblock' == $action) if('unblock' == $action)
{ {
$message = $pm->block_del($pm_proc_id); $message = $pm->block_del($pm_proc_id);
$action = 'inbox'; $action = 'inbox';
$pm_proc_id = 0; $pm_proc_id = 0;
} }
if('get' == $action) if('get' == $action)
{ {
$pm->send_file($pm_proc_id, intval($qs[2])); $pm->send_file($pm_proc_id, intval($qs[2]));
exit; exit;
} }
require_once(HEADERF); require_once(HEADERF);
if(isset($_POST['postpm'])) if(isset($_POST['postpm']))
{ {
$message = $pm->post_pm(); $message = $pm->post_pm();
$action = 'outbox'; $action = 'outbox';
} }
$mes = e107::getMessage(); $mes = e107::getMessage();
if($message != '') if($message != '')
{ {
$mes->add($message); $mes->add($message);
// $ns->tablerender('', "<div class='alert alert-block'>". $message."</div>"); // $ns->tablerender('', "<div class='alert alert-block'>". $message."</div>");
} }
//----------------------------------------- //-----------------------------------------
// DISPLAY TASKS // DISPLAY TASKS
//----------------------------------------- //-----------------------------------------
switch ($action) switch($action)
{ {
case 'send' : case 'send' :
$ns->tablerender(LAN_PM, $pm->breadcrumb(LAN_PLUGIN_PM_NEW). $mes->render() . $pm->show_send($pm_proc_id)); $ns->tablerender(LAN_PM, $pm->breadcrumb(LAN_PLUGIN_PM_NEW) . $mes->render() . $pm->show_send($pm_proc_id));
break; break;
case 'reply' : case 'reply' :
$pmid = $pm_proc_id; $pmid = $pm_proc_id;
if($pm_info = $pm->pm_get($pmid)) if($pm_info = $pm->pm_get($pmid))
{ {
if($pm_info['pm_to'] != USERID) if($pm_info['pm_to'] != USERID)
{ {
$ns->tablerender(LAN_PM, $pm->breadcrumb(LAN_PM_55).$mes->render() . LAN_PM_56); $ns->tablerender(LAN_PM, $pm->breadcrumb(LAN_PM_55) . $mes->render() . LAN_PM_56);
} }
else else
{ {
$ns->tablerender(LAN_PM, $pm->breadcrumb(LAN_PM_55). $mes->render() . $pm->show_send($pm_info)); $ns->tablerender(LAN_PM, $pm->breadcrumb(LAN_PM_55) . $mes->render() . $pm->show_send($pm_info));
} }
} }
else else
{ {
$ns->tablerender(LAN_PM, $pm->breadcrumb(LAN_PM_55). $mes->render() . LAN_PM_57); $ns->tablerender(LAN_PM, $pm->breadcrumb(LAN_PM_55) . $mes->render() . LAN_PM_57);
} }
break; break;
case 'inbox' : case 'inbox' :
$caption = LAN_PM; $caption = LAN_PM;
if(!deftrue('BOOTSTRAP')){ $caption .= ' - '.LAN_PLUGIN_PM_INBOX; }
$ns->tablerender($caption, $pm->breadcrumb(LAN_PLUGIN_PM_INBOX). $mes->render() . $pm->show_inbox($pm_proc_id), 'PM'); if(THEME_LEGACY === true)
{
$caption .= ' - ' . LAN_PLUGIN_PM_INBOX;
}
$ns->tablerender($caption, $pm->breadcrumb(LAN_PLUGIN_PM_INBOX) . $mes->render() . $pm->show_inbox($pm_proc_id), 'PM');
break; break;
case 'outbox' : case 'outbox' :
$caption = LAN_PM; $caption = LAN_PM;
if(!deftrue('BOOTSTRAP')){ $caption .= ' - '.LAN_PLUGIN_PM_OUTBOX; }
$ns->tablerender($caption, $pm->breadcrumb(LAN_PLUGIN_PM_OUTBOX).$mes->render() . $pm->show_outbox($pm_proc_id), 'PM'); if(THEME_LEGACY === true)
{
$caption .= ' - ' . LAN_PLUGIN_PM_OUTBOX;
}
$ns->tablerender($caption, $pm->breadcrumb(LAN_PLUGIN_PM_OUTBOX) . $mes->render() . $pm->show_outbox($pm_proc_id), 'PM');
break; break;
case 'show' : case 'show' :
@@ -875,12 +934,17 @@ switch ($action)
case 'blocked' : case 'blocked' :
$caption = LAN_PM; $caption = LAN_PM;
if(!deftrue('BOOTSTRAP')){ $caption .= ' - '.LAN_PM_66; }
$ns->tablerender($caption, $pm->breadcrumb('blocked').$mes->render() . $pm->showBlocked($pm_proc_id), 'PM'); if(THEME_LEGACY === true)
{
$caption .= ' - ' . LAN_PM_66;
}
$ns->tablerender($caption, $pm->breadcrumb('blocked') . $mes->render() . $pm->showBlocked($pm_proc_id), 'PM');
break; break;
} }
require_once(FOOTERF); require_once(FOOTERF);
exit; exit;
?> ?>