mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-05 02:39:47 +02:00
Add Piwik and Google Analytics statistic modules
Hide user agent from recently played if not at least a content manager user
This commit is contained in:
parent
f81c4d6654
commit
2b100a73cf
7 changed files with 273 additions and 12 deletions
|
@ -37,4 +37,5 @@ should be implemented as a public method:
|
||||||
stream_song_preview(string $file)
|
stream_song_preview(string $file)
|
||||||
display_home()
|
display_home()
|
||||||
external_share(string $url, string $text)
|
external_share(string $url, string $text)
|
||||||
display_user_field(library_item $libitem = null)
|
display_user_field(library_item $libitem = null)
|
||||||
|
display_on_footer
|
|
@ -287,6 +287,15 @@ END;
|
||||||
if (!defined("TABLE_RENDERED")) {
|
if (!defined("TABLE_RENDERED")) {
|
||||||
show_table_render();
|
show_table_render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$plugins = Plugin::get_plugins('display_on_footer');
|
||||||
|
foreach ($plugins as $plugin_name) {
|
||||||
|
$plugin = new Plugin($plugin_name);
|
||||||
|
if ($plugin->load($GLOBALS['user'])) {
|
||||||
|
$plugin->_plugin->display_on_footer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
require_once AmpConfig::get('prefix') . '/templates/footer.inc.php';
|
require_once AmpConfig::get('prefix') . '/templates/footer.inc.php';
|
||||||
if (isset($_REQUEST['profiling'])) {
|
if (isset($_REQUEST['profiling'])) {
|
||||||
Dba::show_profile();
|
Dba::show_profile();
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
# Apache 2.4
|
||||||
|
<IfModule mod_authz_core.c>
|
||||||
|
Require all granted
|
||||||
|
</IfModule>
|
||||||
|
|
||||||
|
# Apache 2.2
|
||||||
<IfModule mod_access.c>
|
<IfModule mod_access.c>
|
||||||
Allow from all
|
Allow from all
|
||||||
</IfModule>
|
</IfModule>
|
111
modules/plugins/GoogleAnalytics.plugin.php
Normal file
111
modules/plugins/GoogleAnalytics.plugin.php
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
<?php
|
||||||
|
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* LICENSE: GNU General Public License, version 2 (GPLv2)
|
||||||
|
* Copyright 2001 - 2015 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 AmpacheGoogleAnalytics {
|
||||||
|
public $name = 'GoogleAnalytics';
|
||||||
|
public $categories = 'stats';
|
||||||
|
public $description = 'Google Analytics statistics';
|
||||||
|
public $url = '';
|
||||||
|
public $version = '000001';
|
||||||
|
public $min_ampache = '370034';
|
||||||
|
public $max_ampache = '999999';
|
||||||
|
|
||||||
|
// These are internal settings used by this class, run this->load to
|
||||||
|
// fill them out
|
||||||
|
private $tracking_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* This function does nothing...
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* install
|
||||||
|
* This is a required plugin function. It inserts our preferences
|
||||||
|
* into Ampache
|
||||||
|
*/
|
||||||
|
public function install() {
|
||||||
|
// Check and see if it's already installed
|
||||||
|
if (Preference::exists('googleanalytics_tracking_id')) { return false; }
|
||||||
|
|
||||||
|
Preference::insert('googleanalytics_tracking_id','Google Analytics Tracking ID','',100,'string','plugins');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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('googleanalytics_tracking_id');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* upgrade
|
||||||
|
* This is a recommended plugin function
|
||||||
|
*/
|
||||||
|
public function upgrade() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* display_user_field
|
||||||
|
* This display the module in user page
|
||||||
|
*/
|
||||||
|
public function display_on_footer() {
|
||||||
|
echo "<!-- Google Analytics -->\n";
|
||||||
|
echo "<script>\n";
|
||||||
|
echo "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n";
|
||||||
|
echo "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n";
|
||||||
|
echo "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n";
|
||||||
|
echo "})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n";
|
||||||
|
echo "ga('create', '" . scrub_out($this->tracking_id) ."', 'auto');\n";
|
||||||
|
echo "ga('send', 'pageview');\n";
|
||||||
|
echo "</script>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* load
|
||||||
|
* This loads up the data we need into this object, this stuff comes
|
||||||
|
* from the preferences.
|
||||||
|
*/
|
||||||
|
public function load($user) {
|
||||||
|
$this->user = $user;
|
||||||
|
$user->set_preferences();
|
||||||
|
$data = $user->prefs;
|
||||||
|
|
||||||
|
$this->tracking_id = trim($data['googleanalytics_tracking_id']);
|
||||||
|
if (!strlen($this->tracking_id)) {
|
||||||
|
debug_event($this->name,'No Tracking ID, user field plugin skipped','3');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -87,17 +87,17 @@ class AmpachePaypal {
|
||||||
$lang = substr(AmpConfig::get('lang'), 0, 2);
|
$lang = substr(AmpConfig::get('lang'), 0, 2);
|
||||||
if (empty($lang)) $lang = 'US';
|
if (empty($lang)) $lang = 'US';
|
||||||
|
|
||||||
echo "<form action='https://www.paypal.com/cgi-bin/webscr' method='post' target='_top'>";
|
echo "<form action='https://www.paypal.com/cgi-bin/webscr' method='post' target='_top'>\n";
|
||||||
echo "<input type='hidden' name='cmd' value='_donations'>";
|
echo "<input type='hidden' name='cmd' value='_donations'>\n";
|
||||||
echo "<input type='hidden' name='business' value='" . scrub_out($this->business) . "'>";
|
echo "<input type='hidden' name='business' value='" . scrub_out($this->business) . "'>\n";
|
||||||
echo "<input type='hidden' name='lc' value='" . $lang . "'>";
|
echo "<input type='hidden' name='lc' value='" . $lang . "'>\n";
|
||||||
echo "<input type='hidden' name='item_name' value='" . $name . "'>";
|
echo "<input type='hidden' name='item_name' value='" . $name . "'>\n";
|
||||||
echo "<input type='hidden' name='no_note' value='0'>";
|
echo "<input type='hidden' name='no_note' value='0'>\n";
|
||||||
echo "<input type='hidden' name='currency_code' value='" . scrub_out($this->currency_code) . "'>";
|
echo "<input type='hidden' name='currency_code' value='" . scrub_out($this->currency_code) . "'>\n";
|
||||||
echo "<input type='hidden' name='bn' value='PP-DonationsBF:btn_donate_SM.gif:NonHostedGuest'>";
|
echo "<input type='hidden' name='bn' value='PP-DonationsBF:btn_donate_SM.gif:NonHostedGuest'>\n";
|
||||||
echo "<input type='image' src='https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif' border='0' name='submit' alt='PayPal - The safer, easier way to pay online!'>";
|
echo "<input type='image' src='https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif' border='0' name='submit' alt='PayPal - The safer, easier way to pay online!'>\n";
|
||||||
echo "<img alt='' border='0' src='https://www.paypalobjects.com/fr_XC/i/scr/pixel.gif' width='1' height='1'>";
|
echo "<img alt='' border='0' src='https://www.paypalobjects.com/fr_XC/i/scr/pixel.gif' width='1' height='1'>\n";
|
||||||
echo "</form>";
|
echo "</form>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
128
modules/plugins/Piwik.plugin.php
Normal file
128
modules/plugins/Piwik.plugin.php
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
<?php
|
||||||
|
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* LICENSE: GNU General Public License, version 2 (GPLv2)
|
||||||
|
* Copyright 2001 - 2015 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 AmpachePiwik {
|
||||||
|
public $name = 'Piwik';
|
||||||
|
public $categories = 'stats';
|
||||||
|
public $description = 'Piwik statistics';
|
||||||
|
public $url = '';
|
||||||
|
public $version = '000001';
|
||||||
|
public $min_ampache = '370034';
|
||||||
|
public $max_ampache = '999999';
|
||||||
|
|
||||||
|
// These are internal settings used by this class, run this->load to
|
||||||
|
// fill them out
|
||||||
|
private $site_id;
|
||||||
|
private $piwik_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* This function does nothing...
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* install
|
||||||
|
* This is a required plugin function. It inserts our preferences
|
||||||
|
* into Ampache
|
||||||
|
*/
|
||||||
|
public function install() {
|
||||||
|
// Check and see if it's already installed
|
||||||
|
if (Preference::exists('piwik_site_id')) { return false; }
|
||||||
|
|
||||||
|
Preference::insert('piwik_site_id','Piwik Site ID','1',100,'string','plugins');
|
||||||
|
Preference::insert('piwik_url','Piwik URL', AmpConfig::get('web_path') . '/piwik/',100,'string','plugins');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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('piwik_site_id');
|
||||||
|
Preference::delete('piwik_url');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* upgrade
|
||||||
|
* This is a recommended plugin function
|
||||||
|
*/
|
||||||
|
public function upgrade() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* display_user_field
|
||||||
|
* This display the module in user page
|
||||||
|
*/
|
||||||
|
public function display_on_footer() {
|
||||||
|
echo "<!-- Piwik -->\n";
|
||||||
|
echo "<script type='text/javascript'>\n";
|
||||||
|
echo "var _paq = _paq || [];\n";
|
||||||
|
echo "_paq.push(['trackPageView']);\n";
|
||||||
|
echo "_paq.push(['enableLinkTracking']);\n";
|
||||||
|
echo "(function() {\n";
|
||||||
|
echo "var u='" . scrub_out($this->piwik_url) . "';\n";
|
||||||
|
echo "_paq.push(['setTrackerUrl', u+'piwik.php']);\n";
|
||||||
|
echo "_paq.push(['setSiteId', " . scrub_out($this->site_id) . "]);\n";
|
||||||
|
if ($GLOBALS['user']->id > 0) {
|
||||||
|
echo "_paq.push(['setUserId', '" . $GLOBALS['user']->username . "']);\n";
|
||||||
|
}
|
||||||
|
echo "var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];\n";
|
||||||
|
echo "g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);\n";
|
||||||
|
echo "})();\n";
|
||||||
|
echo "</script>\n";
|
||||||
|
echo "<noscript><p><img src='" . scrub_out($this->piwik_url) . "piwik.php?idsite=" . scrub_out($this->site_id) . "' style='border:0;' alt='' /></p></noscript>\n";
|
||||||
|
echo "<!-- End Piwik Code -->\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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->site_id = trim($data['piwik_site_id']);
|
||||||
|
if (!strlen($this->site_id)) {
|
||||||
|
debug_event($this->name,'No Piwik Site ID, user field plugin skipped','3');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->piwik_url = trim($data['piwik_url']);
|
||||||
|
if (!strlen($this->piwik_url)) {
|
||||||
|
debug_event($this->name,'No Piwik URL, user field plugin skipped','3');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,7 +33,9 @@ UI::show_box_top(T_('Recently Played') . $link, 'box box_recently_played');
|
||||||
<th class="cel_artist"><?php echo T_('Artist'); ?></th>
|
<th class="cel_artist"><?php echo T_('Artist'); ?></th>
|
||||||
<th class="cel_username"><?php echo T_('Username'); ?></th>
|
<th class="cel_username"><?php echo T_('Username'); ?></th>
|
||||||
<th class="cel_lastplayed"><?php echo T_('Last Played'); ?></th>
|
<th class="cel_lastplayed"><?php echo T_('Last Played'); ?></th>
|
||||||
|
<?php if (Access::check('interface', 50)) { ?>
|
||||||
<th class="cel_agent"><?php echo T_('Agent'); ?></th>
|
<th class="cel_agent"><?php echo T_('Agent'); ?></th>
|
||||||
|
<?php } ?>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -123,11 +125,13 @@ foreach ($data as $row) {
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="cel_lastplayed"><?php echo $time_string; ?></td>
|
<td class="cel_lastplayed"><?php echo $time_string; ?></td>
|
||||||
|
<?php if (Access::check('interface', 50)) { ?>
|
||||||
<td class="cel_agent">
|
<td class="cel_agent">
|
||||||
<?php if (!empty($agent)) {
|
<?php if (!empty($agent)) {
|
||||||
echo UI::get_icon('info', $agent);
|
echo UI::get_icon('info', $agent);
|
||||||
} ?>
|
} ?>
|
||||||
</td>
|
</td>
|
||||||
|
<?php } ?>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
++$nb;
|
++$nb;
|
||||||
|
@ -148,7 +152,9 @@ foreach ($data as $row) {
|
||||||
<th class="cel_artist"><?php echo T_('Artist'); ?></th>
|
<th class="cel_artist"><?php echo T_('Artist'); ?></th>
|
||||||
<th class="cel_username"><?php echo T_('Username'); ?></th>
|
<th class="cel_username"><?php echo T_('Username'); ?></th>
|
||||||
<th class="cel_lastplayed"><?php echo T_('Last Played'); ?></th>
|
<th class="cel_lastplayed"><?php echo T_('Last Played'); ?></th>
|
||||||
|
<?php if (Access::check('interface', 50)) { ?>
|
||||||
<th class="cel_agent"><?php echo T_('Agent'); ?></th>
|
<th class="cel_agent"><?php echo T_('Agent'); ?></th>
|
||||||
|
<?php } ?>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue