Version 4.7.13

This commit is contained in:
Neo committed 2025-12-19 16:14:56 -08:00
1 parent fd22d99e69
commit 7124a02564
954 files changed
+29277 -59308

No files matched your search

@@ -59,68 +59,7 @@ class _emailstats extends \IPS\Dispatcher\Controller
{
$activeTab = $this->_getActiveTab();
/* Determine minimum date */
$minimumDate = NULL;
if( \IPS\Settings::i()->prune_log_emailstats > 0 )
{
$minimumDate = \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_log_emailstats . 'D' ) );
}
/* We can't retrieve any stats prior to the new tracking being implemented */
try
{
$oldestLog = \IPS\Db::i()->select( 'MIN(time)', 'core_statistics', array( 'type=?', 'emails_sent' ) )->first();
if( !$minimumDate OR $oldestLog < $minimumDate->getTimestamp() )
{
$minimumDate = \IPS\DateTime::ts( $oldestLog );
}
}
catch( \UnderflowException $e )
{
/* We have nothing tracked, set minimum date to today */
$minimumDate = \IPS\DateTime::create();
}
$startDate = \IPS\DateTime::ts( time() - ( 60 * 60 * 24 * 30 ) );
/* If our start date is older than our minimum date, use that as the start date instead */
if ( $startDate->getTimestamp() < $minimumDate->getTimestamp() )
{
$startDate = $minimumDate;
}
$chart = new \IPS\Helpers\Chart\Callback(
\IPS\Http\Url::internal( 'app=core&module=activitystats&controller=emailstats&tab=' . $activeTab ),
array( $this, 'getResults' ),
'',
array(
'isStacked' => TRUE,
'backgroundColor' => '#ffffff',
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
'lineWidth' => 1,
'areaOpacity' => 0.4,
'height' => 450
),
'LineChart',
'daily',
array( 'start' => $startDate, 'end' => \IPS\DateTime::create() ),
'',
$minimumDate
);
$chart->availableTypes = array( 'LineChart', 'ColumnChart', 'BarChart' );
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('stats_emailstats_' . $activeTab);
/* Force the notice that the chart is displayed in the server time zone */
$chart->timezoneError = TRUE;
$chart->hideTimezoneLink = TRUE;
foreach( $this->_getEmailTypes() as $series )
{
$chart->addSeries( $series, 'number' );
}
$chart = \IPS\core\Statistics\Chart::loadFromExtension( 'core', ( $activeTab === 'emails' ) ? 'Emails' : 'EmailClicks' )->getChart( \IPS\Http\Url::internal( "app=core&module=activitystats&controller=emailstats&tab={$activeTab}" ) );
if ( \IPS\Request::i()->isAjax() )
{
@@ -133,85 +72,6 @@ class _emailstats extends \IPS\Dispatcher\Controller
}
}
/**
* Fetch the results
*
* @param \IPS\Helpers\Chart\Callback $chart Chart object
* @return array
*/
public function getResults( $chart )
{
$activeTab = $this->_getActiveTab();
$where = array( array( "time>?", 0 ) );
switch( $activeTab )
{
case 'emails':
$where[] = array( 'type=?', 'emails_sent' );
break;
case 'clicks':
$where[] = array( 'type=?', 'email_clicks' );
break;
}
if ( $chart->start )
{
$where[] = array( "value_4>=?", $chart->start->format('Y-m-d') );
}
if ( $chart->end )
{
$where[] = array( "value_4<=?", $chart->end->format('Y-m-d') );
}
$results = array();
foreach( \IPS\Db::i()->select( '*', 'core_statistics', $where, 'value_4 ASC' ) as $row )
{
/* We need to use month/days NOT prefixed with '0' - i.e. 2019-2-12 instead of 2019-02-12 - to match the chart helper */
$_date = new \IPS\DateTime( $row['value_4'] );
switch( $chart->timescale )
{
case 'daily':
$_date = $_date->format( 'Y-n-j' );
break;
case 'weekly':
$_date = $_date->format( 'o-W' );
break;
case 'monthly':
$_date = $_date->format( 'Y-n' );
break;
}
if( !isset( $results[ $_date ] ) )
{
$results[ $_date ] = array( 'time' => $_date );
foreach( $this->_getEmailTypes() as $series )
{
$results[ $_date ][ $series ] = 0;
}
}
$lang = $row['extra_data'];
try
{
$lang = \IPS\Member::loggedIn()->language()->get( 'emailstats__' . $row['extra_data'] );
}
catch( \UnderflowException $e ){}
$results[ $_date ][ $lang ] += (int) $row['value_1'];
}
return $results;
}
/**
* Get the active tab
*
@@ -219,7 +79,8 @@ class _emailstats extends \IPS\Dispatcher\Controller
*/
protected function _getActiveTab()
{
return ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $this->_getAvailableTabs() ) ) ? \IPS\Request::i()->tab : 'emails';
\IPS\Request::i()->tab ??= 'emails';
return ( array_key_exists( \IPS\Request::i()->tab, $this->_getAvailableTabs() ) ) ? \IPS\Request::i()->tab : 'emails';
}
/**
@@ -234,37 +95,4 @@ class _emailstats extends \IPS\Dispatcher\Controller
'clicks' => 'stats_emailstats_clicks',
);
}
/**
* @brief Cached email types
*/
protected $_emailTypes = NULL;
/**
* Get all possible email types logged
*
* @return array
*/
protected function _getEmailTypes()
{
if( $this->_emailTypes === NULL )
{
$this->_emailTypes = array();
foreach( \IPS\Db::i()->select( 'extra_data', 'core_statistics', array( 'type=?', 'emails_sent' ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_DISTINCT ) as $series )
{
$lang = $series;
try
{
$lang = \IPS\Member::loggedIn()->language()->get( 'emailstats__' . $series );
}
catch( \UnderflowException $e ){}
$this->_emailTypes[] = $lang;
}
}
return array_unique( $this->_emailTypes );
}
}