mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-06 03:49:56 +02:00
Add count_type column on object_count table
Add stream control plugins (Hits and Bandwidth)
This commit is contained in:
parent
a5bd894531
commit
b98b1a5a95
11 changed files with 370 additions and 16 deletions
126
modules/plugins/StreamHits.plugin.php
Normal file
126
modules/plugins/StreamHits.plugin.php
Normal file
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
|
||||
/**
|
||||
*
|
||||
* LICENSE: GNU General Public License, version 2 (GPLv2)
|
||||
* Copyright 2001 - 2014 Ampache.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License v2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
class AmpacheStreamHits
|
||||
{
|
||||
public $name = 'Stream Hits';
|
||||
public $categories = 'stream_control';
|
||||
public $description = 'Stream Control Hits per user';
|
||||
public $url = '';
|
||||
public $version = '000001';
|
||||
public $min_ampache = '370024';
|
||||
public $max_ampache = '999999';
|
||||
|
||||
private $user_id;
|
||||
private $hits_days;
|
||||
private $hits_max;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* This function does nothing...
|
||||
*/
|
||||
public function __construct() {
|
||||
return true;
|
||||
|
||||
} // constructor
|
||||
|
||||
/**
|
||||
* install
|
||||
* This is a required plugin function. It inserts our preferences
|
||||
* into Ampache
|
||||
*/
|
||||
public function install() {
|
||||
if (Preference::exists('stream_control_hits_max')) { return false; }
|
||||
Preference::insert('stream_control_hits_max','Stream control maximal hits','-1','50','integer','plugins');
|
||||
Preference::insert('stream_control_hits_days','Stream control hits history (days)','30','50','integer','plugins');
|
||||
return true;
|
||||
} // install
|
||||
|
||||
/**
|
||||
* uninstall
|
||||
* This is a required plugin function. It removes our preferences from
|
||||
* the database returning it to its original form
|
||||
*/
|
||||
public function uninstall() {
|
||||
Preference::delete('stream_control_hits_max');
|
||||
Preference::delete('stream_control_hits_days');
|
||||
return true;
|
||||
} // uninstall
|
||||
|
||||
/**
|
||||
* upgrade
|
||||
* This is a recommended plugin function
|
||||
*/
|
||||
public function upgrade() {
|
||||
return true;
|
||||
} // upgrade
|
||||
|
||||
/**
|
||||
* Check stream control
|
||||
* @param array $media_ids
|
||||
* @return boolean
|
||||
*/
|
||||
public function stream_control($media_ids)
|
||||
{
|
||||
// No check if unlimited hits (= -1)
|
||||
if ($this->hits_max < 0)
|
||||
return true;
|
||||
|
||||
$next_total = count($media_ids);
|
||||
|
||||
$graph = new Graph();
|
||||
$end_date = time();
|
||||
$start_date = $end_date - ($this->hits_days * 86400);
|
||||
$current_total = $graph->get_total_hits($this->user_id, $start_date, $end_date);
|
||||
$next_total += $current_total;
|
||||
|
||||
debug_event('stream_control_bandwidth', 'Next stream hits will be ' . $next_total . ' / ' . $this->hits_max, 3);
|
||||
|
||||
return ($next_total <= $this->hits_max);
|
||||
}
|
||||
|
||||
/**
|
||||
* load
|
||||
* This loads up the data we need into this object, this stuff comes
|
||||
* from the preferences.
|
||||
*/
|
||||
public function load($user) {
|
||||
$user->set_preferences();
|
||||
$data = $user->prefs;
|
||||
|
||||
$this->user_id = $user->id;
|
||||
if (intval($data['stream_control_hits_max'])) {
|
||||
$this->hits_max = intval($data['stream_control_hits_max']);
|
||||
}
|
||||
else {
|
||||
$this->hits_max = -1;
|
||||
}
|
||||
if (intval($data['stream_control_hits_days']) > 0) {
|
||||
$this->hits_days = intval($data['stream_control_hits_days']);
|
||||
}
|
||||
else {
|
||||
$this->hits_days = 30;
|
||||
}
|
||||
|
||||
return true;
|
||||
} // load
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue