1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-19 13:37:09 +01:00
php-e107/e107_plugins/pm/pm_func.php

139 lines
3.7 KiB
PHP
Raw Normal View History

2006-12-02 04:36:16 +00:00
<?php
/*
2009-11-17 13:48:46 +00:00
* e107 website system
*
2014-08-02 13:28:09 +02:00
* Copyright (C) 2008-2014 e107 Inc (e107.org)
2009-11-17 13:48:46 +00:00
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
2009-12-17 22:47:20 +00:00
* Private messenger plugin - utility functions
2009-11-17 13:48:46 +00:00
*
*/
2006-12-02 04:36:16 +00:00
if (!defined('e107_INIT')) { exit; }
2009-12-17 22:47:20 +00:00
class pmbox_manager
2006-12-02 04:36:16 +00:00
{
2009-12-17 22:47:20 +00:00
protected $pmPrefs = array();
protected $pmDB;
public function __construct($prefs='')
2006-12-02 04:36:16 +00:00
{
2009-12-17 22:47:20 +00:00
$this->pmDB = e107::getDb();
// $this->pmPrefs = $prefs;
$this->pmPrefs = e107::pref('pm');
}
public function prefs()
{
return $this->pmPrefs;
2006-12-02 04:36:16 +00:00
}
2009-12-17 22:47:20 +00:00
/**
* Get the box-related information for inbox or outbox - limits, message count etc
* The information read from the DB is cached internally for efficiency
*
* @param string $which = inbox|outbox|clear
*
* @return array
*
*/
function pm_getInfo($which = 'inbox')
2006-12-02 04:36:16 +00:00
{
2009-12-17 22:47:20 +00:00
static $pm_info;
if('clear' == $which)
2006-12-02 04:36:16 +00:00
{
2009-12-17 22:47:20 +00:00
unset($pm_info['inbox']);
unset($pm_info['outbox']);
return;
2006-12-02 04:36:16 +00:00
}
2009-12-17 22:47:20 +00:00
if('inbox' == $which)
2006-12-02 04:36:16 +00:00
{
2009-12-17 22:47:20 +00:00
$qry = "SELECT count(pm.pm_id) AS total, SUM(pm.pm_size)/1024 size, SUM(pm.pm_read = 0) as unread FROM `#private_msg` as pm WHERE pm.pm_to = ".USERID." AND pm.pm_read_del = 0";
}
else
{
$qry = "SELECT count(pm.pm_from) AS total, SUM(pm.pm_size)/1024 size, SUM(pm.pm_read = 0) as unread FROM `#private_msg` as pm WHERE pm.pm_from = ".USERID." AND pm.pm_sent_del = 0";
2009-12-17 22:47:20 +00:00
}
if(!isset($pm_info[$which]['total']))
{
2014-08-02 13:28:09 +02:00
$this->pmDB->gen($qry);
$pm_info[$which] = $this->pmDB->fetch();
2009-12-17 22:47:20 +00:00
if ($which == 'inbox' && ($this->pmPrefs['animate'] == 1 || $this->pmPrefs['popup'] == 1))
2006-12-02 04:36:16 +00:00
{
2009-12-17 22:47:20 +00:00
if($new = $this->pmDB->db_Count('private_msg', '(*)', "WHERE pm_sent > '".USERLV."' AND pm_read = 0 AND pm_to = '".USERID."' AND pm_read_del != 1"))
{
$pm_info['inbox']['new'] = $new;
}
else
{
$pm_info['inbox']['new'] = 0;
}
2006-12-02 04:36:16 +00:00
}
2009-12-17 22:47:20 +00:00
}
if(!isset($pm_info[$which]['limit']))
{
if(varset($this->pmPrefs['pm_limits'],0) > 0)
2006-12-02 04:36:16 +00:00
{
2009-12-17 22:47:20 +00:00
if($this->pmPrefs['pm_limits'] == 1)
{
$qry = "SELECT MAX(gen_user_id) AS inbox_limit, MAX(gen_ip) as outbox_limit FROM `#generic` WHERE gen_type='pm_limit' AND gen_datestamp IN (".USERCLASS_LIST.")";
}
else
{
$qry = "SELECT MAX(gen_intdata) AS inbox_limit, MAX(gen_chardata) as outbox_limit FROM `#generic` WHERE gen_type='pm_limit' AND gen_datestamp IN (".USERCLASS_LIST.")";
}
2014-08-02 13:28:09 +02:00
if($this->pmDB->gen($qry))
2009-12-17 22:47:20 +00:00
{
2014-08-02 13:28:09 +02:00
$row = $this->pmDB->fetch();
2009-12-17 22:47:20 +00:00
$pm_info['inbox']['limit'] = $row['inbox_limit'];
$pm_info['outbox']['limit'] = $row['outbox_limit'];
}
$pm_info['inbox']['limit_val'] = ($this->pmPrefs['pm_limits'] == 1 ? varset($pm_info['inbox']['total'],'') : varset($pm_info['inbox']['size'],''));
if(!$pm_info['inbox']['limit'] || !$pm_info['inbox']['limit_val'])
{
$pm_info['inbox']['filled'] = 0;
}
else
{
$pm_info['inbox']['filled'] = number_format($pm_info['inbox']['limit_val']/$pm_info['inbox']['limit'] * 100, 2);
}
$pm_info['outbox']['limit_val'] = ($this->pmPrefs['pm_limits'] == 1 ? varset($pm_info['outbox']['total'],'') : varset($pm_info['outbox']['size'],''));
if(!$pm_info['outbox']['limit'] || !$pm_info['outbox']['limit_val'])
{
$pm_info['outbox']['filled'] = 0;
}
else
{
$pm_info['outbox']['filled'] = number_format($pm_info['outbox']['limit_val']/$pm_info['outbox']['limit'] * 100, 2);
}
2006-12-02 04:36:16 +00:00
}
else
{
2009-12-17 22:47:20 +00:00
$pm_info['inbox']['limit'] = '';
$pm_info['outbox']['limit'] = '';
$pm_info['inbox']['filled'] = '';
$pm_info['outbox']['filled'] = '';
2006-12-02 04:36:16 +00:00
}
}
2009-12-17 22:47:20 +00:00
return $pm_info;
2006-12-02 04:36:16 +00:00
}
2009-12-17 22:47:20 +00:00
2006-12-02 04:36:16 +00:00
}
2009-12-17 22:47:20 +00:00
2017-12-11 17:11:22 -08:00
// Backward compat. fix.
function pm_getInfo($which = 'inbox')
{
$pm = new pmbox_manager;
return $pm->pm_getInfo($which);
2009-12-17 22:47:20 +00:00
2017-12-11 17:11:22 -08:00
}