4 * webanalyticsPlugin Class
6 * Copyright 2012 Franck Villaume - TrivialDev
7 * http://fusionforge.org
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 class webanalyticsPlugin extends Plugin {
27 function __construct() {
28 parent::__construct();
29 $this->name = "webanalytics";
30 $this->text = _("webanalytics");
32 _("webanalytics plugin for FusionForge. Get the ability
33 to configure specific URL for web analytics tool
34 such as Piwik or Google Analytics.");
35 $this->_addHook('webanalytics_url');
36 $this->_addHook('webanalytics_admin');
37 $this->_addHook('site_admin_option_hook');
40 function CallHook($hookname, &$params) {
42 case "webanalytics_url": {
43 echo $this->getWebAnalyticsCodes();
47 case "webanalytics_admin":
48 case "site_admin_option_hook": {
49 echo '<li>'.$this->getAdminOptionLink().'</li>';
59 function getAdminOptionLink() {
60 return util_make_link('/plugins/'.$this->name.'/?type=globaladmin', _('Global WebAnalytics admin'), array('title' => _('Direct link to global configuration of this plugin')));
63 function getWebAnalyticsCodes() {
64 $codesFromDb = db_query_params('select code FROM plugin_webanalytics where is_enable = $1', array(1));
66 while ($arr = db_fetch_array($codesFromDb)) {
67 $codesString .= $arr['code'];
73 * getAvailableLinks - get all the links from the db
75 * @return array the available links
77 function getAvailableLinks() {
78 $links = db_query_params('select * FROM plugin_webanalytics', array());
79 $availableLinks = array();
80 while ($arr = db_fetch_array($links)) {
81 $availableLinks[] = $arr;
83 return $availableLinks;
87 * addLink - add a new valid link
89 * @param string $url the url
90 * @param string $name an informative name
91 * @return bool success or not
93 function addLink($url, $name) {
95 $res = db_query_params('insert into plugin_webanalytics (url, name, code, is_enable)
96 values ($1, $2, $3, $4)',
98 htmlspecialchars($url),
112 * deleteLink - delete a link
114 * @param int $idLink the link id
115 * @return bool success or not
117 function deleteLink($idLink) {
118 $res = db_query_params('delete from plugin_webanalytics where id_webanalytics = $1', array($idLink));
125 function updateLinkStatus($idLink, $linkStatus) {
126 $res = db_query_params('update plugin_webanalytics set is_enable = $1 where id_webanalytics = $2', array($linkStatus, $idLink));
133 function getLink($idLink) {
134 $res = db_query_params('select * from plugin_webanalytics where id_webanalytics = $1', array($idLink));
135 if (db_numrows($res) == 1) {
136 return db_fetch_array($res);
141 function updateLink($idLink, $url, $name) {
142 $res = db_query_params('update plugin_webanalytics set url = $1, name = $2, code = $3 where id_webanalytics = $4',
143 array(htmlspecialchars($url), $name, $url, $idLink));
151 * getHeader - initialize header and js
153 * @param string $type : user, project, globaladmin (aka group)
154 * @return bool success or not
156 function getHeader($type) {
159 case 'globaladmin': {
160 session_require_global_perm('forge_admin');
162 require_once($gfwww.'admin/admin_utils.php');
163 html_use_tablesorter();
164 site_admin_header(array('title'=>_('Site Global Webanalytics Admin'), 'toptab' => ''));
173 * getGlobalAdminView - display the Global Admin View
177 function getGlobalAdminView() {
179 $user = session_get_user();
180 include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
185 * getPluginDescription - display the description of this plugin in pluginman admin page
187 * @return string the description
189 function getPluginDescription() {
190 return _('Get the ability to configure specific URL for web analytics tool such as Piwik or Google Analytics.');