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