示例#1
0
 /**
  * Widget constructor
  *
  * @param WP_Piwik $wpPiwik
  *        	current WP-Piwik object
  * @param WP_Piwik\Settings $settings
  *        	current WP-Piwik settings
  * @param string $pageId
  *        	WordPress page ID (default: dashboard)
  * @param string $context
  *        	WordPress meta box context (defualt: side)
  * @param string $priority
  *        	WordPress meta box priority (default: default)
  * @param array $params
  *        	widget parameters (default: empty array)
  * @param boolean $isShortcode
  *        	is the widget shown inline? (default: false)
  */
 public function __construct($wpPiwik, $settings, $pageId = 'dashboard', $context = 'side', $priority = 'default', $params = array(), $isShortcode = false)
 {
     self::$wpPiwik = $wpPiwik;
     self::$settings = $settings;
     $this->pageId = $pageId;
     $this->context = $context;
     $this->priority = $priority;
     if (self::$settings->checkNetworkActivation() && function_exists('is_super_admin') && is_super_admin() && isset($_GET['wpmu_show_stats'])) {
         switch_to_blog((int) $_GET['wpmu_show_stats']);
         $this->blogId = get_current_blog_id();
         restore_current_blog();
     }
     $this->isShortcode = $isShortcode;
     $prefix = $this->pageId == 'dashboard' ? self::$settings->getGlobalOption('plugin_display_name') . ' - ' : '';
     $this->configure($prefix, $params);
     if (is_array($this->method)) {
         foreach ($this->method as $method) {
             $this->apiID[$method] = \WP_Piwik\Request::register($method, $this->parameter);
             self::$wpPiwik->log("Register request: " . $this->apiID[$method]);
         }
     } else {
         $this->apiID[$this->method] = \WP_Piwik\Request::register($this->method, $this->parameter);
         self::$wpPiwik->log("Register request: " . $this->apiID[$this->method]);
     }
     if ($this->isShortcode) {
         return;
     }
     add_meta_box($this->getName(), $this->title, array($this, 'show'), $pageId, $this->context, $this->priority);
 }
示例#2
0
    /**
     * Execute test script and display results
     */
    private function runTestscript()
    {
        ?>
		<div class="wp-piwik-debug">
		<h2>Testscript Result</h2>
		<?php 
        if (self::$wpPiwik->isConfigured()) {
            if (isset($_GET['testscript_id']) && $_GET['testscript_id']) {
                switch_to_blog((int) $_GET['testscript_id']);
            }
            ?>
		<textarea cols="80" rows="10"><?php 
            echo '`WP-Piwik ' . self::$wpPiwik->getPluginVersion() . "\nMode: " . self::$settings->getGlobalOption('piwik_mode') . "\n\n";
            ?>
Test 1/3: global.getPiwikVersion<?php 
            $GLOBALS['wp-piwik_debug'] = true;
            $id = \WP_Piwik\Request::register('API.getPiwikVersion', array());
            echo "\n\n";
            var_dump(self::$wpPiwik->request($id));
            echo "\n";
            var_dump(self::$wpPiwik->request($id, true));
            echo "\n";
            $GLOBALS['wp-piwik_debug'] = false;
            ?>
Test 2/3: SitesManager.getSitesWithAtLeastViewAccess<?php 
            $GLOBALS['wp-piwik_debug'] = true;
            $id = \WP_Piwik\Request::register('SitesManager.getSitesWithAtLeastViewAccess', array());
            echo "\n\n";
            var_dump(self::$wpPiwik->request($id));
            echo "\n";
            var_dump(self::$wpPiwik->request($id, true));
            echo "\n";
            $GLOBALS['wp-piwik_debug'] = false;
            ?>
Test 3/3: SitesManager.getSitesIdFromSiteUrl<?php 
            $GLOBALS['wp-piwik_debug'] = true;
            $id = \WP_Piwik\Request::register('SitesManager.getSitesIdFromSiteUrl', array('url' => get_bloginfo('url')));
            echo "\n\n";
            var_dump(self::$wpPiwik->request($id));
            echo "\n";
            var_dump(self::$wpPiwik->request($id, true));
            echo "\n";
            echo "\n\n";
            var_dump(self::$settings->getDebugData());
            echo "`";
            $GLOBALS['wp-piwik_debug'] = false;
            ?>
</textarea>
		<?php 
            if (isset($_GET['testscript_id']) && $_GET['testscript_id']) {
                restore_current_blog();
            }
        } else {
            echo '<p>Please configure WP-Piwik first.</p>';
        }
        ?>
		</div>
	<?php 
    }
示例#3
0
 private static function request($method, $parameters)
 {
     $request = \WP_Piwik\Request::register($method, $parameters);
     $response = $GLOBALS['wp-piwik']->request($request);
     return $response;
 }