예제 #1
0
    /**
     * This method displays a text containing an help about "How to build plugins for Piwik".
     * This help is then used on http://piwik.org/docs/plugins/functions
     *
     */
    function index()
    {
        $out = '';
        $out .= '<i>This page aims to list the different functions you can use when programming plugins for Piwik.</i><br />';
        $out .= '<b>Be careful, the following APIs may change in the near future as Piwik is still in development.</b><br />';
        $out .= '<h2>General</h2>';
        $out .= '<h3>Accessible from your plugin controller</h3>';
        $out .= '<code>$this->date</code> = current selected <b>Piwik_Date</b> object (<a href="http://dev.piwik.org/trac/browser/trunk/core/Date.php">class</a>)<br />';
        $out .= '<code>$period = Piwik_Common::getRequestVar("period");</code> - Get the current selected period<br />';
        $out .= '<code>$idSite = Piwik_Common::getRequestVar("idSite");</code> - Get the selected idSite<br />';
        $out .= '<code>$site = new Piwik_Site($idSite);</code> - Build the Piwik_Site object (<a href="http://dev.piwik.org/trac/browser/trunk/core/Site.php">class</a>)<br />';
        $out .= '<code>$this->str_date</code> = current selected date in YYYY-MM-DD format<br />';
        $out .= '<h3>Misc</h3>';
        $out .= '<code>Piwik_AddMenu( $mainMenuName, $subMenuName, $url );</code> - Adds an entry to the menu in the Piwik interface (See the example in the <a href="http://dev.piwik.org/trac/browser/tags/1.0/plugins/UserCountry/UserCountry.php#L76">UserCountry Plugin file</a>)<br />';
        $out .= '<code>Piwik_AddWidget( $widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters = array());</code> - Adds a widget that users can add in the dashboard, or export using the Widgets link at the top of the screen. See the example in the <a href="http://dev.piwik.org/trac/browser/tags/1.0/plugins/UserCountry/UserCountry.php#L70">UserCountry Plugin file</a> or any other plugin)<br />';
        $out .= '<code>Piwik_Common::prefixTable("site")</code> = <b>' . Piwik_Common::prefixTable("site") . '</b><br />';
        $out .= '<h2>User access</h2>';
        $out .= '<code>Piwik::getCurrentUserLogin()</code> = <b>' . Piwik::getCurrentUserLogin() . '</b><br />';
        $out .= '<code>Piwik::isUserHasSomeAdminAccess()</code> = <b>' . self::boolToString(Piwik::isUserHasSomeAdminAccess()) . '</b><br />';
        $out .= '<code>Piwik::isUserHasAdminAccess( array $idSites = array(1,2) )</code> = <b>' . self::boolToString(Piwik::isUserHasAdminAccess(array(1, 2))) . '</b><br />';
        $out .= '<code>Piwik::isUserHasViewAccess( array $idSites = array(1) ) </code> = <b>' . self::boolToString(Piwik::isUserHasViewAccess(array(1))) . '</b><br />';
        $out .= '<code>Piwik::isUserIsSuperUser()</code> = <b>' . self::boolToString(Piwik::isUserIsSuperUser()) . '</b><br />';
        $out .= '<h2>Execute SQL queries</h2>';
        $txtQuery = "SELECT token_auth FROM " . Piwik_Common::prefixTable('user') . " WHERE login = ?";
        $result = Piwik_FetchOne($txtQuery, array('anonymous'));
        $out .= '<code>Piwik_FetchOne("' . $txtQuery . '", array("anonymous"))</code> = <b>' . var_export($result, true) . '</b><br />';
        $out .= '<br />';
        $query = Piwik_Query($txtQuery, array('anonymous'));
        $fetched = $query->fetch();
        $token_auth = $fetched['token_auth'];
        $out .= '<code>$query = Piwik_Query("' . $txtQuery . '", array("anonymous"))</code><br />';
        $out .= '<code>$fetched = $query->fetch();</code><br />';
        $out .= 'At this point, we have: <code>$fetched[\'token_auth\'] == <b>' . var_export($token_auth, true) . '</b></code><br />';
        $out .= '<h2>Example Sites information API</h2>';
        $out .= '<code>Piwik_SitesManager_API::getInstance()->getSitesWithViewAccess()</code> = <b><pre>' . var_export(Piwik_SitesManager_API::getInstance()->getSitesWithViewAccess(), true) . '</pre></b><br />';
        $out .= '<code>Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess()</code> = <b><pre>' . var_export(Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess(), true) . '</pre></b><br />';
        $out .= '<h2>Example API  Users information</h2>';
        $out .= 'View the list of API methods you can call on <a href="http://piwik.org/docs/analytics-api/reference">API reference</a><br />';
        $out .= 'For example you can try <code>Piwik_UsersManager_API::getInstance()->getUsersSitesFromAccess("view");</code> or <code>Piwik_UsersManager_API::getInstance()->deleteUser("userToDelete");</code><br />';
        $out .= '<h2>Javascript in Piwik</h2>';
        $out .= '<h3>i18n internationalization</h3>';
        $out .= 'In order to translate strings within Javascript code, you can use the javascript function _pk_translate( token );.
				<ul><li>The "token" parameter is the string unique key found in the translation file. For this token string to be available in Javascript, you must
				suffix your token by "_js" in the language file. For example, you can add <code>\'Goals_AddGoal_js\' => \'Add Goal\',</code> in the lang/en.php file</li>
				<li>You then need to instruct Piwik to load your Javascript translations for your plugin; by default, all translation strings are not loaded in Javascript for performance reasons. This can be done by calling a custom-made Smarty modifier before the Javascript code requiring translations, eg. 
					<code>{loadJavascriptTranslations plugins=\'$YOUR_PLUGIN_NAME\'}</code>. In our previous example, the $YOUR_PLUGIN_NAME being Goals, we would write <code>{loadJavascriptTranslations plugins=\'Goals\'}</code>
					</li><li>You can then print this string from your JS code by doing <code>_pk_translate(\'Goals_AddGoal_js\');</code>.
					</li></ul>';
        $out .= '<h3>Reload a widget in the dashboard</h3>';
        $out .= 'It is sometimes useful to reload one widget in the dashboard (for example, every 20 seconds for a real time widget, or after a setting change). 
					You can easily force your widget to reload in the dashboard by calling the helper function <code>piwik.dashboardObject.reloadEnclosingWidget($(this));</code>.';
        $out .= '<h2>Smarty plugins</h2>';
        $out .= 'There are some builtin plugins for Smarty especially developped for Piwik. <br />
				You can find them on the <a href="http://dev.piwik.org/trac/browser/trunk/core/SmartyPlugins">SVN at /trunk/core/SmartyPlugins</a>. <br />
				More documentation to come about smarty plugins.<br />';
        echo $out;
    }
예제 #2
0
 function index()
 {
     $view = Piwik_View::factory('overview');
     $this->setGeneralVariablesView($view);
     $view->funnels = $this->funnels;
     $view->funnelsJSON = json_encode($this->funnels);
     $view->userCanEditFunnels = Piwik::isUserHasAdminAccess($this->idSite);
     $view->goalsWithoutFunnels = Piwik_Funnels_API::getInstance()->getGoalsWithoutFunnels($this->idSite);
     echo $view->render();
 }
예제 #3
0
 function addNewExperiment()
 {
     $view = Piwik_View::factory('add_new_experiment');
     $this->setGeneralVariablesView($view);
     $view->userCanEditExperiments = Piwik::isUserHasAdminAccess($this->idSite);
     $view->goalsPluginDeactived = !Piwik_PluginsManager::getInstance()->isPluginActivated('Goals');
     $view->goals = Piwik_Goals_API::getInstance()->getGoals($this->idSite);
     $view->onlyShowAddNewExperiment = true;
     echo $view->render();
 }
예제 #4
0
파일: API.php 프로젝트: Gninety/Microweber
 public function getSegmentsMetadata($idSites = array(), $_hideImplementationData = true)
 {
     $segments = array();
     Piwik_PostEvent('API.getSegmentsMetadata', $segments, $idSites);
     $segments[] = array('type' => 'dimension', 'category' => 'Visit', 'name' => 'General_VisitorIP', 'segment' => 'visitIp', 'acceptedValues' => '13.54.122.1, etc.', 'sqlSegment' => 'location_ip', 'sqlFilter' => array('Piwik_Common', 'getIp'), 'permission' => Piwik::isUserHasAdminAccess($idSites));
     $segments[] = array('type' => 'dimension', 'category' => 'Visit', 'name' => 'General_VisitorID', 'segment' => 'visitorId', 'acceptedValues' => '34c31e04394bdc63 - any 16 chars ID requested via the Tracking API function getVisitorId()', 'sqlSegment' => 'idvisitor', 'sqlFilter' => array('Piwik_Common', 'convertVisitorIdToBin'));
     $segments[] = array('type' => 'metric', 'category' => 'Visit', 'name' => 'General_NbActions', 'segment' => 'actions', 'sqlSegment' => 'visit_total_actions');
     $segments[] = array('type' => 'metric', 'category' => 'Visit', 'name' => 'General_ColumnVisitDuration', 'segment' => 'visitDuration', 'sqlSegment' => 'visit_total_time');
     $segments[] = array('type' => 'dimension', 'category' => 'Visit', 'name' => 'General_VisitType', 'segment' => 'visitorType', 'acceptedValues' => 'new, returning', 'sqlSegment' => 'visitor_returning', 'sqlFilter' => create_function('$type', 'return $type == "new" ? 0 : 1;'));
     $segments[] = array('type' => 'metric', 'category' => 'Visit', 'name' => 'General_DaysSinceLastVisit', 'segment' => 'daysSinceLastVisit', 'sqlSegment' => 'visitor_days_since_last');
     $segments[] = array('type' => 'metric', 'category' => 'Visit', 'name' => 'General_DaysSinceFirstVisit', 'segment' => 'daysSinceFirstVisit', 'sqlSegment' => 'visitor_days_since_first');
     $segments[] = array('type' => 'metric', 'category' => 'Visit', 'name' => 'General_NumberOfVisits', 'segment' => 'visitCount', 'sqlSegment' => 'visitor_count_visits');
     $segments[] = array('type' => 'metric', 'category' => 'Visit', 'name' => 'General_VisitConvertedGoal', 'segment' => 'visitConverted', 'acceptedValues' => '0, 1', 'sqlSegment' => 'visit_goal_converted');
     foreach ($segments as &$segment) {
         $segment['name'] = Piwik_Translate($segment['name']);
         $segment['category'] = Piwik_Translate($segment['category']);
         if ($_hideImplementationData) {
             unset($segment['sqlFilter']);
             unset($segment['sqlSegment']);
         }
     }
     usort($segments, array($this, 'sortSegments'));
     return $segments;
 }
예제 #5
0
 function addNewGoal()
 {
     $view = Piwik_View::factory('add_new_goal');
     $view->userCanEditGoals = Piwik::isUserHasAdminAccess($this->idSite);
     $view->currency = Piwik::getCurrency();
     $view->onlyShowAddNewGoal = true;
     echo $view->render();
 }
예제 #6
0
 public function getSegmentsMetadata($idSites = array(), $_hideImplementationData = true)
 {
     $segments = array();
     Piwik_PostEvent('API.getSegmentsMetadata', $segments, $idSites);
     $segments[] = array('type' => 'dimension', 'category' => 'Visit', 'name' => 'General_VisitorIP', 'segment' => 'visitIp', 'acceptedValues' => '13.54.122.1, etc.', 'sqlSegment' => 'log_visit.location_ip', 'sqlFilter' => array('Piwik_IP', 'P2N'), 'permission' => Piwik::isUserHasAdminAccess($idSites));
     $segments[] = array('type' => 'dimension', 'category' => 'Visit', 'name' => 'General_VisitorID', 'segment' => 'visitorId', 'acceptedValues' => '34c31e04394bdc63 - any 16 Hexadecimal chars ID, which can be fetched using the Tracking API function getVisitorId()', 'sqlSegment' => 'log_visit.idvisitor', 'sqlFilter' => array('Piwik_Common', 'convertVisitorIdToBin'));
     $segments[] = array('type' => 'metric', 'category' => 'Visit', 'name' => 'General_NbActions', 'segment' => 'actions', 'sqlSegment' => 'log_visit.visit_total_actions');
     $segments[] = array('type' => 'metric', 'category' => 'Visit', 'name' => 'General_ColumnVisitDuration', 'segment' => 'visitDuration', 'sqlSegment' => 'log_visit.visit_total_time');
     $segments[] = array('type' => 'dimension', 'category' => 'Visit', 'name' => Piwik_Translate('General_VisitType') . ". " . Piwik_Translate('General_VisitTypeExample', '"&segment=visitorType==returning,visitorType==returningCustomer"'), 'segment' => 'visitorType', 'acceptedValues' => 'new, returning, returningCustomer', 'sqlSegment' => 'log_visit.visitor_returning', 'sqlFilter' => create_function('$type', 'return $type == "new" ? 0 : ($type == "returning" ? 1 : 2);'));
     $segments[] = array('type' => 'metric', 'category' => 'Visit', 'name' => 'General_DaysSinceLastVisit', 'segment' => 'daysSinceLastVisit', 'sqlSegment' => 'log_visit.visitor_days_since_last');
     $segments[] = array('type' => 'metric', 'category' => 'Visit', 'name' => 'General_DaysSinceFirstVisit', 'segment' => 'daysSinceFirstVisit', 'sqlSegment' => 'log_visit.visitor_days_since_first');
     $segments[] = array('type' => 'metric', 'category' => 'Visit', 'name' => 'General_NumberOfVisits', 'segment' => 'visitCount', 'sqlSegment' => 'log_visit.visitor_count_visits');
     $segments[] = array('type' => 'dimension', 'category' => 'Visit', 'name' => 'General_VisitConvertedGoal', 'segment' => 'visitConverted', 'acceptedValues' => '0, 1', 'sqlSegment' => 'log_visit.visit_goal_converted');
     $segments[] = array('type' => 'dimension', 'category' => 'Visit', 'name' => Piwik_Translate('General_EcommerceVisitStatus', '"&segment=visitEcommerceStatus==ordered,visitEcommerceStatus==orderedThenAbandonedCart"'), 'segment' => 'visitEcommerceStatus', 'acceptedValues' => implode(", ", self::$visitEcommerceStatus), 'sqlSegment' => 'log_visit.visit_goal_buyer', 'sqlFilter' => array('Piwik_API_API', 'getVisitEcommerceStatus'));
     $segments[] = array('type' => 'metric', 'category' => 'Visit', 'name' => 'General_DaysSinceLastEcommerceOrder', 'segment' => 'daysSinceLastEcommerceOrder', 'sqlSegment' => 'log_visit.visitor_days_since_order');
     foreach ($segments as &$segment) {
         $segment['name'] = Piwik_Translate($segment['name']);
         $segment['category'] = Piwik_Translate($segment['category']);
         if ($_hideImplementationData) {
             unset($segment['sqlFilter']);
             unset($segment['sqlSegment']);
         }
     }
     usort($segments, array($this, 'sortSegments'));
     return $segments;
 }
예제 #7
0
	/**
	 * This method displays a text containing an help about "How to build plugins for Piwik".
	 * This help is then used on http://dev.piwik.org/trac/wiki/Plugins/GlobalFunctions
	 *
	 */
	function index()
	{
		$out = '';
		$out .= '<i>This page aims to list the different functions you can use when programming plugins for Piwik.</i><br>';
		$out .= '<b>Be careful, the following APIs may change in the near future as Piwik is still in development.</b><br>';
		
		$out .= '<h2>General</h2>';
		$out .= '<h3>Accessible from your plugin controller</h3>';
		
		$out .= '<code>$this->date</code> = current selected <b>Piwik_Date</b> object (<a href="http://dev.piwik.org/trac/browser/trunk/core/Date.php">class</a>)<br/>';
		$out .= '<code>$period = Piwik_Common::getRequestVar("period");</code> - Get the current selected period<br/>';
		$out .= '<code>$idSite = Piwik_Common::getRequestVar("idSite");</code> - Get the selected idSite<br/>';
		$out .= '<code>$site = new Piwik_Site($idSite);</code> - Build the Piwik_Site object (<a href="http://dev.piwik.org/trac/browser/trunk/core/Site.php">class</a>)<br/>';
		$out .= '<code>$this->str_date</code> = current selected date in YYYY-MM-DD format<br/>';
		
		$out .= '<h3>Misc</h3>';
		$out .= '<code>Piwik_AddMenu( $mainMenuName, $subMenuName, $url );</code> - Adds an entry to the menu in the Piwik interface (See the example in the <a href="http://dev.piwik.org/trac/browser/trunk/plugins/UserCountry/UserCountry.php#L146">UserCountry Plugin file</a>)<br/>';
		$out .= '<code>Piwik_AddWidget( $widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters = array());</code> - Adds a widget that users can add in the dashboard, or export using the Widgets link at the top of the screen. See the example in the <a href="http://dev.piwik.org/trac/browser/trunk/plugins/UserCountry/UserCountry.php#L143">UserCountry Plugin file</a> or any other plugin)<br/>';
		$out .= '<code>Piwik::prefixTable("site")</code> = <b>' . Piwik::prefixTable("site") . '</b><br/>';
		
		
		$out .= '<h2>User access</h2>';
		$out .= '<code>Piwik::getCurrentUserLogin()</code> = <b>' . Piwik::getCurrentUserLogin() . '</b><br/>';
		$out .= '<code>Piwik::isUserHasSomeAdminAccess()</code> = <b>' . self::boolToString(Piwik::isUserHasSomeAdminAccess()) . '</b><br/>';
		$out .= '<code>Piwik::isUserHasAdminAccess( array $idSites = array(1,2) )</code> = <b>' . self::boolToString(Piwik::isUserHasAdminAccess(array(1,2) )) . '</b><br/>';
		$out .= '<code>Piwik::isUserHasViewAccess( array $idSites = array(1) ) </code> = <b>' . self::boolToString(Piwik::isUserHasViewAccess(array(1))) . '</b><br/>';
		$out .= '<code>Piwik::isUserIsSuperUser()</code> = <b>' . self::boolToString(Piwik::isUserIsSuperUser()) . '</b><br/>';
		
		$out .= '<h2>Execute SQL queries</h2>';
		$txtQuery = "SELECT token_auth FROM ".Piwik::prefixTable('user')." WHERE login = ?";
		$result = Piwik_FetchOne($txtQuery, array('anonymous'));
		$out .= '<code>Piwik_FetchOne("'.$txtQuery.'", array("anonymous"))</code> = <b>' . var_export($result,true) . '</b><br/>';
		$out .= '<br>';
		
		$query = Piwik_Query($txtQuery, array('anonymous'));
		$fetched = $query->fetch();
		$token_auth = $fetched['token_auth'];
		
		$out .= '<code>$query = Piwik_Query("'.$txtQuery.'", array("anonymous"))</code><br>';
		$out .= '<code>$fetched = $query->fetch();</code><br>';
		$out .= 'At this point, we have: <code>$fetched[\'token_auth\'] == <b>'.var_export($token_auth,true) . '</b></code><br/>';
		
  		$out .= '<h2>Example Sites information API</h2>';
		$out .= '<code>Piwik_SitesManager_API::getSitesWithViewAccess()</code> = <b><pre>' .var_export(Piwik_SitesManager_API::getSitesWithViewAccess(),true) . '</pre></b><br/>';
		$out .= '<code>Piwik_SitesManager_API::getSitesWithAdminAccess()</code> = <b><pre>' .var_export(Piwik_SitesManager_API::getSitesWithAdminAccess(),true) . '</pre></b><br/>';

		$out .= '<h2>Example API  Users information</h2>';
		$out .= 'View the list of API methods you can call on <a href="http://dev.piwik.org/trac/wiki/API/Reference#Methods">API reference</a><br/>';
		$out .= 'For example you can try <code>Piwik_UsersManager_API::getUsersSitesFromAccess("view");</code> or <code>Piwik_UsersManager_API::deleteUser("userToDelete");</code><br/>';
		
		$out .= '<h2>Smarty plugins</h2>';
		$out .= 'There are some builtin plugins for Smarty especially developped for Piwik. <br>
				You can find them on the <a href="http://dev.piwik.org/trac/browser/trunk/core/SmartyPlugins">SVN at /trunk/core/SmartyPlugins</a>. <br>
				More documentation to come about smarty plugins.<br/>';
		
		echo $out;
	}
예제 #8
0
 /** 
  * This method is called when the JS from startOverlaySession() detects that the target domain
  * is not configured for the current site.
  */
 public function showErrorWrongDomain()
 {
     $idSite = Piwik_Common::getRequestVar('idSite', 0, 'int');
     Piwik::checkUserHasViewAccess($idSite);
     $url = Piwik_Common::getRequestVar('url', '');
     $url = Piwik_Common::unsanitizeInputValue($url);
     $message = Piwik_Translate('Overlay_RedirectUrlError', array($url, "\n"));
     $message = nl2br(htmlentities($message));
     $view = Piwik_View::factory('error_wrong_domain');
     $view->message = $message;
     if (Piwik::isUserHasAdminAccess($idSite)) {
         // TODO use $idSite to link to the correct row. This is tricky because the #rowX ids don't match
         // the site ids when sites have been deleted.
         $url = 'index.php?module=SitesManager&action=index';
         $troubleshoot = htmlentities(Piwik_Translate('Overlay_RedirectUrlErrorAdmin'));
         $troubleshoot = sprintf($troubleshoot, '<a href="' . $url . '" target="_top">', '</a>');
         $view->troubleshoot = $troubleshoot;
     } else {
         $view->troubleshoot = htmlentities(Piwik_Translate('Overlay_RedirectUrlErrorUser'));
     }
     echo $view->render();
 }
예제 #9
0
 public function addNewGoal()
 {
     $view = Piwik_View::factory('add_new_goal');
     $this->setGeneralVariablesView($view);
     $view->userCanEditGoals = Piwik::isUserHasAdminAccess($this->idSite);
     $view->onlyShowAddNewGoal = true;
     echo $view->render();
 }
예제 #10
0
 function addNewGoal()
 {
     $view = new Piwik_View('Goals/templates/add_new_goal.tpl');
     $view->userCanEditGoals = Piwik::isUserHasAdminAccess($this->idSite);
     $view->currency = Piwik::getCurrency();
     $view->onlyShowAddNewGoal = true;
     echo $view->render();
 }