本文整理汇总了PHP中Piwik类的典型用法代码示例。如果您正苦于以下问题:PHP Piwik类的具体用法?PHP Piwik怎么用?PHP Piwik使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Piwik类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendFeedback
/**
* send email to Piwik team and display nice thanks
*/
function sendFeedback()
{
$body = Piwik_Common::getRequestVar('body', '', 'string');
$email = Piwik_Common::getRequestVar('email', '', 'string');
$view = new Piwik_View('Feedback/templates/sent.tpl');
try {
$minimumBodyLength = 35;
if (strlen($body) < $minimumBodyLength) {
throw new Exception(sprintf("Message must be at least %s characters long.", $minimumBodyLength));
}
if (!Piwik::isValidEmailString($email)) {
throw new Exception(Piwik_Translate('UsersManager_ExceptionInvalidEmail'));
}
if (strpos($body, 'http://') !== false) {
throw new Exception("The message cannot contain a URL, to avoid spams messages.");
}
$mail = new Piwik_Mail();
$mail->setFrom($email);
$mail->addTo('hello@piwik.org', 'Piwik Team');
$mail->setSubject('[ Feedback form - Piwik ]');
$mail->setBodyText($body);
@$mail->send();
} catch (Exception $e) {
$view->ErrorString = $e->getMessage();
$view->message = $body;
}
echo $view->render();
}
示例2: activate
function activate()
{
Piwik::checkUserIsSuperUser();
$pluginName = Piwik_Common::getRequestVar('pluginName', null, 'string');
Piwik_PluginsManager::getInstance()->activatePlugin($pluginName);
Piwik_Url::redirectToUrl('index.php?module=CorePluginsAdmin');
}
示例3: authenticate
public function authenticate()
{
$rootLogin = Zend_Registry::get('config')->superuser->login;
$rootPassword = Zend_Registry::get('config')->superuser->password;
$rootToken = Piwik_UsersManager_API::getTokenAuth($rootLogin, $rootPassword);
if($this->login == $rootLogin
&& $this->token_auth == $rootToken)
{
return new Piwik_Auth_Result(Piwik_Auth_Result::SUCCESS_SUPERUSER_AUTH_CODE, $this->login, $this->token_auth );
}
if($this->token_auth === $rootToken)
{
return new Piwik_Auth_Result(Piwik_Auth_Result::SUCCESS_SUPERUSER_AUTH_CODE, $rootLogin, $rootToken );
}
$login = Piwik_FetchOne(
'SELECT login FROM '.Piwik::prefixTable('user').' WHERE token_auth = ?',
array($this->token_auth)
);
if($login !== false)
{
if(is_null($this->login)
|| $this->login == $login)
{
return new Piwik_Auth_Result(Piwik_Auth_Result::SUCCESS, $login, $this->token_auth );
}
}
return new Piwik_Auth_Result( Piwik_Auth_Result::FAILURE, $this->login, $this->token_auth );
}
示例4: addMenu
function addMenu()
{
Piwik_AddAdminMenu('SitesManager_MenuSites',
array('module' => 'SitesManager', 'action' => 'index'),
Piwik::isUserHasSomeAdminAccess(),
$order = 5);
}
示例5: initAuthenticationObject
function initAuthenticationObject($notification)
{
$auth = new Piwik_Login_Auth();
Zend_Registry::set('auth', $auth);
$action = Piwik::getAction();
if(Piwik::getModule() === 'API'
&& (empty($action) || $action == 'index'))
{
return;
}
$authCookieName = Zend_Registry::get('config')->General->login_cookie_name;
$authCookieExpiry = time() + Zend_Registry::get('config')->General->login_cookie_expire;
$authCookie = new Piwik_Cookie($authCookieName, $authCookieExpiry);
$defaultLogin = 'anonymous';
$defaultTokenAuth = 'anonymous';
if($authCookie->isCookieFound())
{
$defaultLogin = $authCookie->get('login');
$defaultTokenAuth = $authCookie->get('token_auth');
}
$auth->setLogin($defaultLogin);
$auth->setTokenAuth($defaultTokenAuth);
}
示例6: checkTableExists
protected function checkTableExists()
{
if(is_null(self::$tablesAlreadyInstalled))
{
self::$tablesAlreadyInstalled = Piwik::getTablesInstalled($forceReload = false);
}
if(!in_array($this->generatedTableName, self::$tablesAlreadyInstalled))
{
$db = Zend_Registry::get('db');
$sql = Piwik::getTableCreateSql($this->tableName);
$config = Zend_Registry::get('config');
$prefixTables = $config->database->tables_prefix;
$sql = str_replace( $prefixTables . $this->tableName, $this->generatedTableName, $sql);
try {
$db->query( $sql );
} catch(Exception $e) {
// mysql error 1050: table already exists
if(! $db->isErrNo($e, '1050'))
{
// failed for some other reason
throw $e;
}
}
self::$tablesAlreadyInstalled[] = $this->generatedTableName;
}
}
示例7: check
/**
* Check for a newer version
*/
public static function check()
{
$lastTimeChecked = Piwik_GetOption(self::LAST_TIME_CHECKED);
if($lastTimeChecked === false
|| time() - self::CHECK_INTERVAL > $lastTimeChecked )
{
$parameters = array(
'piwik_version' => Piwik_Version::VERSION,
'php_version' => phpversion(),
'url' => Piwik_Url::getCurrentUrlWithoutQueryString(),
'trigger' => Piwik_Common::getRequestVar('module','','string'),
);
$url = self::PIWIK_HOST . "?" . http_build_query($parameters, '', '&');
$timeout = self::SOCKET_TIMEOUT;
try {
$latestVersion = Piwik::sendHttpRequest($url, $timeout);
Piwik_SetOption(self::LATEST_VERSION, $latestVersion);
} catch(Exception $e) {
// e.g., disable_functions = fsockopen; allow_url_open = Off
Piwik_SetOption(self::LATEST_VERSION, '');
}
Piwik_SetOption(self::LAST_TIME_CHECKED, time(), $autoload = 1);
}
}
示例8: setGeneralSettings
public function setGeneralSettings()
{
Piwik::checkUserIsSuperUser();
$response = new Piwik_API_ResponseBuilder(Piwik_Common::getRequestVar('format'));
try {
$this->checkTokenInUrl();
$enableBrowserTriggerArchiving = Piwik_Common::getRequestVar('enableBrowserTriggerArchiving');
$todayArchiveTimeToLive = Piwik_Common::getRequestVar('todayArchiveTimeToLive');
Piwik_ArchiveProcessing::setBrowserTriggerArchiving((bool) $enableBrowserTriggerArchiving);
Piwik_ArchiveProcessing::setTodayArchiveTimeToLive($todayArchiveTimeToLive);
// Update email settings
$mail = Zend_Registry::get('config')->mail;
$mail->transport = Piwik_Common::getRequestVar('mailUseSmtp') == '1' ? 'smtp' : '';
$mail->port = Piwik_Common::getRequestVar('mailPort', '');
$mail->host = Piwik_Common::getRequestVar('mailHost', '');
$mail->type = Piwik_Common::getRequestVar('mailType', '');
$mail->username = Piwik_Common::getRequestVar('mailUsername', '');
$mail->password = Piwik_Common::getRequestVar('mailPassword', '');
$mail->encryption = Piwik_Common::getRequestVar('mailEncryption', '');
Zend_Registry::get('config')->mail = $mail->toArray();
$toReturn = $response->getResponse();
} catch (Exception $e) {
$toReturn = $response->getResponseException($e);
}
echo $toReturn;
}
示例9: Piwik_ExitWithMessage
/**
* Displays info/warning/error message in a friendly UI and exits.
*
* @param string $message Main message
* @param string|false $optionalTrace Backtrace; will be displayed in lighter color
* @param bool $optionalLinks If true, will show links to the Piwik website for help
*/
function Piwik_ExitWithMessage($message, $optionalTrace = false, $optionalLinks = false)
{
@header('Content-Type: text/html; charset=utf-8');
if ($optionalTrace) {
$optionalTrace = '<font color="#888888">Backtrace:<br /><pre>' . $optionalTrace . '</pre></font>';
}
if ($optionalLinks) {
$optionalLinks = '<ul>
<li><a target="_blank" href="?module=Proxy&action=redirect&url=http://piwik.org">Piwik.org homepage</a></li>
<li><a target="_blank" href="?module=Proxy&action=redirect&url=http://piwik.org/faq/">Piwik Frequently Asked Questions</a></li>
<li><a target="_blank" href="?module=Proxy&action=redirect&url=http://piwik.org/docs/">Piwik Documentation</a></li>
<li><a target="_blank" href="?module=Proxy&action=redirect&url=http://forum.piwik.org/">Piwik Forums</a></li>
<li><a target="_blank" href="?module=Proxy&action=redirect&url=http://demo.piwik.org">Piwik Online Demo</a></li>
</ul>';
}
$headerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/themes/default/simple_structure_header.tpl');
$footerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/themes/default/simple_structure_footer.tpl');
try {
// This can fail
$loginName = Piwik::getLoginPluginName();
} catch (Exception $e) {
$loginName = 'Login';
}
$headerPage = str_replace('{$HTML_TITLE}', 'Piwik › Error', $headerPage);
$content = '<p>' . $message . '</p>
<p><a href="index.php">Go to Piwik</a><br/>
<a href="index.php?module=' . $loginName . '">Login</a></p>
' . $optionalTrace . ' ' . $optionalLinks;
echo $headerPage . $content . $footerPage;
exit;
}
示例10: addMenu
function addMenu()
{
Piwik_AddAdminMenu('CorePluginsAdmin_MenuPlugins',
array('module' => 'CorePluginsAdmin', 'action' => 'index'),
Piwik::isUserIsSuperUser(),
$order = 7);
}
示例11: update
static function update()
{
$config = Zend_Registry::get('config');
$dbInfos = $config->database->toArray();
if(!isset($dbInfos['schema']))
{
try {
if(is_writable( Piwik_Config::getDefaultUserConfigPath() ))
{
$dbInfos['schema'] = 'Myisam';
$config->database = $dbInfos;
$config->__destruct();
Piwik::createConfigObject();
}
else
{
throw new Exception('mandatory update failed');
}
} catch(Exception $e) {
throw new Piwik_Updater_UpdateErrorException("Please edit your config/config.ini.php file and add below <code>[database]</code> the following line: <br /><code>schema = Myisam</code>");
}
}
Piwik_Updater::updateDatabase(__FILE__, self::getSql());
}
示例12: get
/**
* Returns the list of metrics (pages, downloads, outlinks)
*
* @param int $idSite
* @param string $period
* @param string $date
* @param string $segment
*/
public function get($idSite, $period, $date, $segment = false, $columns = false)
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Piwik_Archive::build($idSite, $period, $date, $segment);
$metrics = array('Actions_nb_pageviews' => 'nb_pageviews', 'Actions_nb_uniq_pageviews' => 'nb_uniq_pageviews', 'Actions_nb_downloads' => 'nb_downloads', 'Actions_nb_uniq_downloads' => 'nb_uniq_downloads', 'Actions_nb_outlinks' => 'nb_outlinks', 'Actions_nb_uniq_outlinks' => 'nb_uniq_outlinks');
// get requested columns
$columns = Piwik::getArrayFromApiParameter($columns);
if (!empty($columns)) {
// get the columns that are available and requested
$columns = array_intersect($columns, array_values($metrics));
$columns = array_values($columns);
// make sure indexes are right
$nameReplace = array();
foreach ($columns as $i => $column) {
$fullColumn = array_search($column, $metrics);
$columns[$i] = $fullColumn;
$nameReplace[$fullColumn] = $column;
}
} else {
// get all columns
$columns = array_keys($metrics);
$nameReplace =& $metrics;
}
$table = $archive->getDataTableFromNumeric($columns);
// replace labels (remove Actions_)
$table->filter('ReplaceColumnNames', array($nameReplace));
return $table;
}
示例13: getNumeric
protected function getNumeric( $idSite, $period, $date, $toFetch )
{
Piwik::checkUserHasViewAccess( $idSite );
$archive = Piwik_Archive::build($idSite, $period, $date );
$dataTable = $archive->getNumeric($toFetch);
return $dataTable;
}
示例14: authenticate
public function authenticate()
{
// we first try if the user is the super user
$rootLogin = Zend_Registry::get('config')->superuser->login;
$rootPassword = Zend_Registry::get('config')->superuser->password;
$rootToken = Piwik_UsersManager_API::getTokenAuth($rootLogin, $rootPassword);
// echo $rootToken;
// echo "<br>". $this->_credential;exit;
if ($this->_identity == $rootLogin && $this->_credential == $rootToken) {
return new Piwik_Auth_Result(Piwik_Auth::SUCCESS_SUPERUSER_AUTH_CODE, $this->_identity, array());
}
// we then look if the user is API authenticated
// API authentication works without login name, but only with the token
// TODO the logic (sql select) should be in the Login plugin, not here
// this class should stay simple. Another Login plugin should only have to create an auth entry
// of this class in the zend_registry and it should work
if (is_null($this->_identity)) {
$authenticated = false;
if ($this->_credential === $rootToken) {
return new Piwik_Auth_Result(Piwik_Auth::SUCCESS_SUPERUSER_AUTH_CODE, $rootLogin, array());
}
$login = Zend_Registry::get('db')->fetchOne('SELECT login FROM ' . Piwik::prefixTable('user') . ' WHERE token_auth = ?', array($this->_credential));
if ($login !== false) {
return new Piwik_Auth_Result(Zend_Auth_Result::SUCCESS, $login, array());
} else {
return new Piwik_Auth_Result(Zend_Auth_Result::FAILURE, $this->_identity, array());
}
}
// if not then we return the result of the database authentification provided by zend
return parent::authenticate();
}
示例15: getDataTable
/** Get data table from archive
* @return Piwik_DataTable */
public static function getDataTable($name, $idsite, $period, $date, $numeric = false)
{
Piwik::checkUserHasViewAccess($idsite);
if (is_array($name)) {
foreach ($name as &$col) {
$col = 'SiteSearch_' . $col;
}
} else {
$name = 'SiteSearch_' . $name;
}
if (!is_string($period) && get_class($period) != 'Piwik_Period_Range') {
$periodMap = array('Piwik_Period_Day' => 'day', 'Piwik_Period_Week' => 'week', 'Piwik_Period_Month' => 'month', 'Piwik_Period_Year' => 'year');
$period = $periodMap[get_class($period)];
}
$archive = Piwik_Archive::build($idsite, $period, $date);
if ($numeric) {
// numeric archives are only used for search evolution
$dataTable = $archive->getDataTableFromNumeric($name);
$dataTable->queueFilter('ReplaceColumnNames', array(array('SiteSearch_totalSearches' => self::HITS, 'SiteSearch_visitsWithSearches' => self::UNIQUE_HITS)));
$dataTable->applyQueuedFilters();
} else {
$dataTable = $archive->getDataTable($name);
}
return $dataTable;
}