Example #1
0
    public function render()
    {
        $this->bigbrother = new BigBrother($this->modx);
        // Make sure we have a valid access token _before_ showing the widget
        $this->bigbrother->createAuthHeader();
        $this->modx->controller->addCss($this->bigbrother->config['css_url'] . 'dashboard.css');
        //jQuery + charts class
        $this->modx->controller->addJavascript($this->bigbrother->config['assets_url'] . 'mgr/lib/jquery.min.js');
        $this->modx->controller->addJavascript($this->bigbrother->config['assets_url'] . 'mgr/lib/highcharts.js');
        //Basic reusable panels
        $this->modx->controller->addJavascript($this->bigbrother->config['assets_url'] . 'mgr/lib/classes.js');
        $this->modx->controller->addJavascript($this->bigbrother->config['assets_url'] . 'mgr/lib/charts.js');
        $account = $this->bigbrother->getOption('account');
        if ($account == null) {
            $this->modx->controller->addJavascript($this->bigbrother->config['assets_url'] . 'dashboard/notlogged.js');
        } else {
            $this->modx->controller->addJavascript($this->bigbrother->config['assets_url'] . 'dashboard/dashboard.js');
        }
        $date = $this->bigbrother->getDates('d M Y');
        /** @var $page modAction */
        $page = $this->modx->getObject('modAction', array('namespace' => 'bigbrother', 'controller' => 'index'));
        $url = $this->bigbrother->getManagerLink() . '?a=' . $page->get('id');
        $this->modx->controller->addHtml('<script type="text/javascript">
    BigBrother.RedirectUrl = "' . $url . '";
    BigBrother.ConnectorUrl = "' . $this->bigbrother->config['connector_url'] . '";
    BigBrother.DateBegin = "' . $date['begin'] . '";
    BigBrother.DateEnd = "' . $date['end'] . '";
    BigBrother.account = "' . $this->bigbrother->getOption('account') . '";
    BigBrother.accountName = "' . $this->bigbrother->getOption('account_name') . '";
    Ext.applyIf(MODx.lang, ' . $this->modx->toJSON($this->modx->lexicon->loadCache('bigbrother', 'dashboard')) . ');
    Ext.onReady(function() {
        MODx.load({
            xtype: "bb-panel"
            ,user: "******" // Not needed, yet ?
        });
    });
</script>');
        return '<div id="bb-panel"></div>';
    }
Example #2
0
 /**
  * Call the GA API via curl
  * @param string $url
  * @return string
  */
 public function callAPI($url)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->ga->createAuthHeader($url, 'GET')));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $result = curl_exec($ch);
     if (curl_errno($ch)) {
         $this->error = curl_error($ch);
         $this->modx->log(modX::LOG_LEVEL_ERROR, 'cURL Error on API call to ' . $url . ': ' . $this->error);
         return false;
     }
     $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($http_code !== 200) {
         $this->error = $result;
         $this->modx->log(modX::LOG_LEVEL_ERROR, 'Non-200 HTTP Code returned from calling ' . $url . ': ' . $http_code . ' Result: ' . $this->error);
         return false;
     }
     curl_close($ch);
     return $this->modx->fromJSON($result);
 }