コード例 #1
0
 /**
  * returns the piwik config for a given page
  * call it with $this->pageinfo['uid'] as param from a backend module
  *
  * @param    integer $uid : Page ID
  * @throws Exception
  * @return    array        piwik config array
  */
 public function getPiwikConfigArray($uid)
 {
     $path = tx_piwikintegration_install::getInstaller()->getConfigObject()->initPiwikDatabase();
     if ($uid <= 0 || $uid != intval($uid)) {
         throw new \Exception('Problem with uid in tx_piwikintegration_helper.php::getPiwikSiteIdForPid');
     }
     if (isset($this->piwik_option[$uid])) {
         return $this->piwik_option[$uid];
     }
     //parse ts template
     $template_uid = 0;
     $tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
     // Defined global here!
     $tmpl->tt_track = 0;
     // Do not log time-performance information
     $tmpl->init();
     $tplRow = $tmpl->ext_getFirstTemplate($uid, $template_uid);
     if (is_array($tplRow) || 1) {
         // IF there was a template...
         $sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
         $rootLine = $sys_page->getRootLine($uid);
         $tmpl->runThroughTemplates($rootLine);
         // This generates the constants/config + hierarchy info for the template.
         $tmpl->generateConfig();
         if ($tmpl->setup['config.']['tx_piwik.']['customerPidLevel']) {
             $k = $tmpl->setup['config.']['tx_piwik.']['customerPidLevel'];
             $tmpl->setup['config.']['tx_piwik.']['customerRootPid'] = $rootLine[$k]['uid'];
         }
         if (!$tmpl->setup['config.']['tx_piwik.']['customerRootPid']) {
             $tmpl->setup['config.']['tx_piwik.']['customerRootPid'] = $rootLine[0]['uid'];
         }
         return $this->piwik_option[$uid] = $tmpl->setup['config.']['tx_piwik.'];
     }
     return array();
 }
コード例 #2
0
 /**
  * get Singleton function
  * @static
  * @return tx_piwikintegration_install
  */
 public static function getInstaller()
 {
     if (self::$installer == NULL) {
         self::$installer = new tx_piwikintegration_install();
     }
     return self::$installer;
 }
 static function getWidgetsForFlexForm(&$PA, &$fobj)
 {
     $PA['items'] = array();
     tx_piwikintegration_install::getInstaller()->getConfigObject()->initPiwikDatabase();
     $controller = Piwik_FrontController::getInstance()->init();
     $_GET['idSite'] = 1;
     $widgets = Piwik_GetWidgetsList();
     foreach ($widgets as $pluginCat => $plugin) {
         foreach ($plugin as $widget) {
             $PA['items'][] = array($pluginCat . ' : ' . $widget['name'], base64_encode(json_encode($widget['parameters'])), 'i/catalog.gif');
         }
     }
 }
コード例 #4
0
 /**
  * returns piwikBaseURL
  *
  * @return	string
  */
 public function getPiwikBaseURL()
 {
     if (TYPO3_MODE == 'BE') {
         tx_piwikintegration_install::getInstaller()->getConfigObject()->initPiwikFrameWork();
         $path = \Piwik\Url::getCurrentUrlWithoutFileName();
         $path = dirname($path);
         $path .= '/typo3conf/piwik/piwik/';
     } else {
         $path = 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . '/typo3conf/piwik/piwik/';
     }
     return $path;
 }
 /**
  * initializes the configuration for the plugin and gets the settings from
  * the flexform
  *
  * @param	array	$conf: array with TS configuration
  * @return	void
  */
 function init($conf)
 {
     $this->conf = $conf;
     $this->pi_setPiVarDefaults();
     $this->pi_loadLL();
     $this->pi_initPIflexForm();
     $this->extConf['widget'] = json_decode(base64_decode($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'widget')), true);
     $this->extConf['widget']['period'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'period');
     $this->extConf['widget']['moduleToWidgetize'] = $this->extConf['widget']['module'];
     $this->extConf['widget']['actionToWidgetize'] = $this->extConf['widget']['action'];
     $this->extConf['widget']['idSite'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'idsite');
     $this->extConf['height'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'div_height');
     $this->extConf['widget']['date'] = 'yesterday';
     $this->extConf['widget']['viewDataTable'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'viewDataTable');
     unset($this->extConf['widget']['module']);
     unset($this->extConf['widget']['action']);
     $content = '<div id="widgetIframe"><iframe width="100%" height="' . intval($this->extConf['height']) . '" src="';
     $content .= tx_piwikintegration_install::getInstaller()->getBaseUrl() . 'index.php?module=Widgetize&action=iframe' . \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', $this->extConf['widget']);
     $content .= '&disableLink=1" scrolling="no" frameborder="0" marginheight="0" marginwidth="0"></iframe></div>';
     return $content;
 }
コード例 #6
0
    /**
     * @param $par
     * @throws Exception
     * @return void
     */
    function emSaveConstants($par)
    {
        if ($par['extKey'] == 'piwikintegration' && \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('submit')) {
            $newconf = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST();
            $newconf = $newconf['data'];
            //init piwik to get table prefix
            #$this->initPiwik();
            if (!tx_piwikintegration_install::getInstaller()->checkInstallation()) {
                return 'Problem moving database, Piwik is not installed ...';
            }
            $old_database = tx_piwikintegration_install::getInstaller()->getConfigObject()->getOption('database', 'dbname');
            $new_database = $newconf['databaseTablePrefix'];
            $this->table_prefix = tx_piwikintegration_install::getInstaller()->getConfigObject()->getOption('database', 'table_prefix');
            //walk through changes
            if ($old_database !== $new_database) {
                //create shortVars
                if ($new_database == '') {
                    $new_database = TYPO3_db;
                }
                //get tablenames and rename tables
                $suffix = '';
                if ($old_database != '') {
                    $suffix = ' FROM `' . $old_database . '`';
                }
                $erg = $GLOBALS['TYPO3_DB']->admin_query('SHOW TABLES' . $suffix);
                while (false !== ($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($erg))) {
                    if (substr($row[0], 0, 20) == 'tx_piwikintegration_') {
                        $GLOBALS['TYPO3_DB']->admin_query('RENAME TABLE `' . $old_database . '`.`' . $row[0] . '`
								 TO `' . $new_database . '`.`' . $row[0] . '`');
                    }
                }
                //change config
                $conf = tx_piwikintegration_install::getInstaller()->getConfigObject();
                $conf->setOption('database', 'tables_prefix', 'tx_piwikintegration_');
                $conf->setOption('database', 'dbname', $newconf['databaseTablePrefix']);
                $conf->setOption('database', 't3dbname', TYPO3_db);
            }
        }
    }
コード例 #7
0
 /**
  *
  */
 private function __construct()
 {
     $this->installer = tx_piwikintegration_install::getInstaller();
     $this->initPiwikFrameWork();
 }
コード例 #8
0
 /**
  * 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;
 }
コード例 #9
0
 function renameTables()
 {
     $buffer = 'Renamed all tables prepended with tx_piwikintegration to user_piwikintegration:';
     $tablesInstalled = $GLOBALS['TYPO3_DB']->admin_get_tables();
     foreach ($tablesInstalled as $table) {
         if (substr($table['Name'], 0, 20) === 'tx_piwikintegration_') {
             $newTableName = str_replace('tx_piwikintegration_', 'user_piwikintegration_', $table['Name']);
             $GLOBALS['TYPO3_DB']->admin_query('RENAME TABLE `' . $table['Name'] . '` to `' . $newTableName . '`');
             $buffer .= $table['Name'] . ', ';
         }
     }
     tx_piwikintegration_install::getInstaller()->getConfigObject()->setOption('database', 'tables_prefix', 'user_piwikintegration_');
     return $buffer;
 }