/**
  * checks the piwik environment
  *
  * @return bool
  * @throws Exception
  */
 protected function checkPiwikEnvironment()
 {
     // check if piwik is installed
     if (!\tx_piwikintegration_install::getInstaller()->checkInstallation()) {
         \tx_piwikintegration_install::getInstaller()->installPiwik();
         if (\tx_piwikintegration_install::getInstaller()->checkInstallation()) {
             $this->addFlashMessage('Piwik installed', 'Piwik is now installed / upgraded, wait a moment, reload the page ;) <meta http-equiv="refresh" content="2; URL=mod.php?M=web_txpiwikintegrationM1&uid=' . $this->id . '#reload">', \TYPO3\CMS\Core\Messaging\FlashMessage::OK);
         }
         return FALSE;
     }
     // check whether a page is selected
     if (!$this->id) {
         $this->addFlashMessage('Please select a page in the pagetree', '', \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE);
         return FALSE;
     }
     $t = $this->piwikHelper->getPiwikConfigArray($this->id);
     // check whether a configured page is selected
     if (!isset($t['piwik_idsite']) || !$this->piwikHelper->getPiwikSiteIdForPid($this->id)) {
         $this->addFlashMessage('Page is not configured. Did you include the Typoscript template?', '', \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE);
         return FALSE;
     }
     // check whether piwik_host is correct
     if ($t['piwik_host'] !== 'typo3conf/piwik/piwik/' && $t['piwik_host'] !== '/typo3conf/piwik/piwik/') {
         $this->addFlashMessage('Piwik host is not set correctly', '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         return FALSE;
     }
     unset($t);
     // check if patch level is correct
     if (!\tx_piwikintegration_install::getInstaller()->checkPiwikPatched()) {
         //prevent lost configuration and so the forced repair.
         $exclude = array('config/config.ini.php');
         \tx_piwikintegration_install::getInstaller()->patchPiwik($exclude);
     }
     return TRUE;
 }
 function getSitesForFlexForm(&$PA, &$fobj)
 {
     $this->init();
     //fetch anonymous accessable idsites
     $erg = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('idsite', tx_piwikintegration_div::getTblName('access'), 'login="******"');
     //build array for selecting more information
     $sites = array();
     foreach ($erg as $site) {
         $sites[] = $site['idsite'];
     }
     $accessableSites = implode(',', $sites);
     $erg = $GLOBALS['TYPO3_DB']->exec_SELECTquery('idsite,name,main_url', tx_piwikintegration_div::getTblName('site'), 'idsite IN(' . $accessableSites . ')', '', 'name, main_url, idsite');
     $PA['items'] = array();
     //render items
     while (($site = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($erg)) !== false) {
         $PA['items'][] = array($site['idsite'] . ' : ' . ($site['name'] ? $site['name'] . ' : ' . $site['main_url'] : $site['main_url']), $site['idsite'], 'i/domain.gif');
     }
 }
 /**
  * handler for cached output processing to assure that the siteid is created
  * in piwik	 
  *
  * @param	pointer $$params: passed params from the hook
  * @param	pointer $reference: to the parent object
  * @return	void
  */
 public function contentPostProc_all(&$params, &$reference)
 {
     $this->init($params, $reference);
     if ($this->extConf['piwik_idsite'] != 0) {
         $erg = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', tx_piwikintegration_div::getTblName('site'), 'idsite=' . intval($this->extConf['piwik_idsite']));
         $numRows = $GLOBALS['TYPO3_DB']->sql_num_rows($erg);
         //check wether siteid exists
         if ($numRows === 0) {
             //if not -> create
             //FIX currency for current Piwik version, since 0.6.3
             // $currency = Piwik_GetOption('SitesManager_DefaultCurrency') ? Piwik_GetOption('SitesManager_DefaultCurrency') : 'USD';
             //FIX timezone for current Piwik version, since 0.6.3
             // $timezone = Piwik_GetOption('SitesManager_DefaultTimezone') ? Piwik_GetOption('SitesManager_DefaultTimezone') : 'UTC';
             $GLOBALS['TYPO3_DB']->exec_INSERTquery(tx_piwikintegration_div::getTblName('site'), array('idsite' => intval($this->extConf['piwik_idsite']), 'name' => 'ID ' . intval($this->extConf['piwik_idsite']), 'main_url' => $this->baseUrl, 'ts_created' => date('Y-m-d H:i:s', time())));
         } elseif ($numRows > 1) {
             //more than once -> error
             die('piwik idsite table is inconsistent, please contact server administrator');
         }
     }
 }
 /**
  * This function makes a page statistics accessable for a user
  * call it with $this->pageinfo['uid'] as param from a backend module
  *
  * @param    integer $uid : pid for which the user will get access
  * @throws Exception
  * @return    void
  */
 public function correctUserRightsForPid($uid)
 {
     $this->initPiwikFrameWork();
     if ($uid <= 0 || $uid != intval($uid)) {
         throw new \Exception('Problem with uid in tx_piwikintegration_helper.php::correctUserRightsForPid');
     }
     $beUserName = $GLOBALS['BE_USER']->user['username'];
     /**
      * ensure, that user's right are added to the database
      * tx_piwikintegration_access		 
      */
     if ($GLOBALS['BE_USER']->user['admin'] != 1) {
         $erg = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', tx_piwikintegration_div::getTblName('access'), 'login="******" AND idsite=' . $this->getPiwikSiteIdForPid($uid), '', '', '0,1');
         if (count($erg) === 0) {
             $GLOBALS['TYPO3_DB']->exec_INSERTquery(tx_piwikintegration_div::getTblName('access'), array('login' => $beUserName, 'idsite' => $this->getPiwikSiteIdForPid($uid), 'access' => 'view'));
         }
     }
 }
Esempio n. 5
0
 /**
  * creates piwik site, if not existing
  *
  * @param $id
  * @internal param int $siteid : Piwik ID
  * @return    integer     piwik site id
  */
 public function makePiwikSiteExisting($id)
 {
     if ($id !== 0) {
         $erg = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', tx_piwikintegration_div::getTblName('site'), 'idsite = ' . intval($id), '', '', '0,1');
         if (count($erg) == 0) {
             //FIX currency for current Piwik version, since 0.6.3
             $currency = \Piwik\Option::get('SitesManager_DefaultCurrency') ? \Piwik\Option::get('SitesManager_DefaultCurrency') : 'USD';
             //FIX timezone for current Piwik version, since 0.6.3
             $timezone = \Piwik\Option::get('SitesManager_DefaultTimezone') ? \Piwik\Option::get('SitesManager_DefaultTimezone') : 'UTC';
             $GLOBALS['TYPO3_DB']->exec_INSERTquery(tx_piwikintegration_div::getTblName('site'), array('idsite' => $id, 'main_url' => 'http://' . $_SERVER["SERVER_NAME"], 'name' => 'Customer ' . $id, 'timezone' => $timezone, 'currency' => $currency, 'ts_created' => date('Y-m-d H:i:s', time())));
         }
     }
 }
 function resetUserRights()
 {
     $installer = tx_piwikintegration_install::getInstaller();
     $installer->getConfigObject();
     $GLOBALS['TYPO3_DB']->admin_query('TRUNCATE TABLE ' . tx_piwikintegration_div::getTblName('access'));
     return $GLOBALS['LANG']->getLL('action.resetUserRights.success');
 }