00001 <?php
00002
00017 import('classes.plugins.GenericPlugin');
00018
00019 class GoogleAnalyticsPlugin extends GenericPlugin {
00020
00027 function register($category, $path) {
00028 $success = parent::register($category, $path);
00029 if (!Config::getVar('general', 'installed')) return false;
00030 $this->addLocaleData();
00031 if ($success) {
00032
00033 HookRegistry::register('Templates::Common::Footer::PageFooter', array($this, 'insertFooter'));
00034
00035
00036 HookRegistry::register('Templates::Paper::Footer::PageFooter', array($this, 'insertFooter'));
00037
00038
00039 HookRegistry::register('Templates::Paper::Interstitial::PageFooter', array($this, 'insertFooter'));
00040
00041
00042 HookRegistry::register('Templates::Paper::PdfInterstitial::PageFooter', array($this, 'insertFooter'));
00043
00044
00045 HookRegistry::register('Templates::Rt::Footer::PageFooter', array($this, 'insertFooter'));
00046
00047
00048 HookRegistry::register('Templates::Help::Footer::PageFooter', array($this, 'insertFooter'));
00049 }
00050 return $success;
00051 }
00052
00059 function getName() {
00060 return 'GoogleAnalyticsPlugin';
00061 }
00062
00063 function getDisplayName() {
00064 return __('plugins.generic.googleAnalytics.displayName');
00065 }
00066
00067 function getDescription() {
00068 return __('plugins.generic.googleAnalytics.description');
00069 }
00070
00074 function smartyPluginUrl($params, &$smarty) {
00075 $path = array($this->getCategory(), $this->getName());
00076 if (is_array($params['path'])) {
00077 $params['path'] = array_merge($path, $params['path']);
00078 } elseif (!empty($params['path'])) {
00079 $params['path'] = array_merge($path, array($params['path']));
00080 } else {
00081 $params['path'] = $path;
00082 }
00083
00084 if (!empty($params['id'])) {
00085 $params['path'] = array_merge($params['path'], array($params['id']));
00086 unset($params['id']);
00087 }
00088 return $smarty->smartyUrl($params, $smarty);
00089 }
00090
00096 function setBreadcrumbs($isSubclass = false) {
00097 $templateMgr =& TemplateManager::getManager();
00098 $pageCrumbs = array(
00099 array(
00100 Request::url(null, null, 'user'),
00101 'navigation.user'
00102 ),
00103 array(
00104 Request::url(null, null, 'manager'),
00105 'user.role.manager'
00106 )
00107 );
00108 if ($isSubclass) $pageCrumbs[] = array(
00109 Request::url(null, null, 'manager', 'plugins'),
00110 'manager.plugins'
00111 );
00112
00113 $templateMgr->assign('pageHierarchy', $pageCrumbs);
00114 }
00115
00119 function getManagementVerbs() {
00120 $verbs = array();
00121 if ($this->getEnabled()) {
00122 $verbs[] = array(
00123 'disable',
00124 __('manager.plugins.disable')
00125 );
00126 $verbs[] = array(
00127 'settings',
00128 __('plugins.generic.googleAnalytics.manager.settings')
00129 );
00130 } else {
00131 $verbs[] = array(
00132 'enable',
00133 __('manager.plugins.enable')
00134 );
00135 }
00136 return $verbs;
00137 }
00138
00142 function getEnabled() {
00143 $conference =& Request::getConference();
00144 if (!$conference) return false;
00145 return $this->getSetting($conference->getId(), 0, 'enabled');
00146 }
00147
00151 function setEnabled($enabled) {
00152 $conference =& Request::getConference();
00153 if ($conference) {
00154 $this->updateSetting($conference->getId(), 0, 'enabled', $enabled ? true : false);
00155 return true;
00156 }
00157 return false;
00158 }
00159
00163 function insertFooter($hookName, $params) {
00164 if ($this->getEnabled()) {
00165 $smarty =& $params[1];
00166 $output =& $params[2];
00167 $templateMgr =& TemplateManager::getManager();
00168 $currentConference = $templateMgr->get_template_vars('currentConference');
00169
00170 if (!empty($currentConference)) {
00171 $conference =& Request::getConference();
00172 $conferenceId = $conference->getId();
00173 $googleAnalyticsSiteId = $this->getSetting($conferenceId, 0, 'googleAnalyticsSiteId');
00174
00175 if (!empty($googleAnalyticsSiteId)) {
00176 $templateMgr->assign('googleAnalyticsSiteId', $googleAnalyticsSiteId);
00177 $trackingCode = $this->getSetting($conferenceId, 0, 'trackingCode');
00178 if ($trackingCode == "ga") {
00179 $output .= $templateMgr->fetch($this->getTemplatePath() . 'pageTagGa.tpl');
00180 } else {
00181 $output .= $templateMgr->fetch($this->getTemplatePath() . 'pageTagUrchin.tpl');
00182 }
00183 }
00184 }
00185 }
00186 return false;
00187 }
00188
00189
00190
00191
00192
00193
00194
00195
00196 function manage($verb, $args, &$message) {
00197 $templateMgr =& TemplateManager::getManager();
00198 $templateMgr->register_function('plugin_url', array(&$this, 'smartyPluginUrl'));
00199 $conference =& Request::getConference();
00200 $returner = true;
00201
00202 switch ($verb) {
00203 case 'enable':
00204 $this->setEnabled(true);
00205 $returner = false;
00206 $message = __('plugins.generic.googleAnalytics.enabled');
00207 break;
00208 case 'disable':
00209 $this->setEnabled(false);
00210 $returner = false;
00211 $message = __('plugins.generic.sgoogleAnalyticsehl.disabled');
00212 break;
00213 case 'settings':
00214 if ($this->getEnabled()) {
00215 $this->import('GoogleAnalyticsSettingsForm');
00216 $form = new GoogleAnalyticsSettingsForm($this, $conference->getId());
00217 if (Request::getUserVar('save')) {
00218 $form->readInputData();
00219 if ($form->validate()) {
00220 $form->execute();
00221 Request::redirect(null, null, 'manager', 'plugin');
00222 } else {
00223 $this->setBreadCrumbs(true);
00224 $form->display();
00225 }
00226 } else {
00227 $this->setBreadCrumbs(true);
00228 $form->initData();
00229 $form->display();
00230 }
00231 } else {
00232 Request::redirect(null, null, 'manager');
00233 }
00234 break;
00235 default:
00236 Request::redirect(null, null, 'manager');
00237 }
00238 return $returner;
00239 }
00240 }
00241 ?>