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() {
29 $this->name = "webanalytics" ;
30 $this->text = "webanalytics" ;
31 $this->_addHook('webanalytics_url');
32 $this->_addHook('webanalytics_admin');
33 $this->_addHook('site_admin_option_hook');
36 function CallHook ($hookname, &$params) {
38 case "webanalytics_url": {
39 echo $this->getWebAnalyticsCodes();
43 case "webanalytics_admin":
44 case "site_admin_option_hook": {
45 echo '<li>'.$this->getAdminOptionLink().'</li>';
53 function getAdminOptionLink() {
54 return util_make_link('/plugins/'.$this->name.'/?type=globaladmin', _('Global WebAnalytics admin'), array('class' => 'tabtitle', 'title' => _('Direct link to global configuration of this plugin.')));
57 function getWebAnalyticsCodes() {
58 $codesFromDb = db_query_params('select code FROM plugin_webanalytics where is_enable = $1', array(1));
60 while ($arr = db_fetch_array($codesFromDb)) {
61 $codesString .= $arr['code'];
67 * getAvailableLinks - get all the links from the db
69 * @return array the available links
71 function getAvailableLinks() {
72 $links = db_query_params('select * FROM plugin_webanalytics', array());
73 $availableLinks = array();
74 while ($arr = db_fetch_array($links)) {
75 $availableLinks[] = $arr;
77 return $availableLinks;
81 * addLink - add a new valid link
83 * @param string the url
84 * @param string an informative name
85 * @return bool success or not
87 function addLink($url, $name) {
89 $res = db_query_params('insert into plugin_webanalytics (url, name, code, is_enable)
90 values ($1, $2, $3, $4)',
92 htmlspecialchars($url),
106 * deleteLink - delete a link
108 * @param int the link id
109 * @return bool success or not
111 function deleteLink($idLink) {
112 $res = db_query_params('delete from plugin_webanalytics where id_webanalytics = $1', array($idLink));
119 function updateLinkStatus($idLink, $linkStatus) {
120 $res = db_query_params('update plugin_webanalytics set is_enable = $1 where id_webanalytics = $2', array($linkStatus, $idLink));
128 * getHeader - initialize header and js
130 * @param string type : user, project, globaladmin (aka group)
131 * @return bool success or not
133 function getHeader($type) {
137 case 'globaladmin': {
138 session_require_global_perm('forge_admin');
140 require_once($gfwww.'admin/admin_utils.php');
141 use_javascript('/js/sortable.js');
142 site_admin_header(array('title'=>_('Site Global Webanalytics Admin'), 'toptab' => ''));
151 * getGlobalAdminView - display the Global Admin View
155 function getGlobalAdminView() {
157 $user = session_get_user();
158 include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
163 * getPluginDescription - display the description of this plugin in pluginman admin page
165 * @return string the description
167 function getPluginDescription() {
168 return _('Get the ability to configure specific URL for web analytics tool such as Piwik or Google Analytics.');