php Piwik-Url类(方法)实例源码

下面列出了php Piwik-Url 类(方法)源码代码实例,从而了解它的用法。

作者:a4tunad    项目:piwi   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $serverGlobal = $input->getOption('server-global');
     if ($serverGlobal) {
         $_SERVER = json_decode($serverGlobal, true);
     }
     $this->requireFixtureFiles($input);
     $this->setIncludePathAsInTestBootstrap();
     $host = Url::getHost();
     if (empty($host)) {
         Url::setHost('localhost');
     }
     $fixture = $this->createFixture($input);
     $this->setupDatabaseOverrides($input, $fixture);
     // perform setup and/or teardown
     if ($input->getOption('teardown')) {
         $fixture->getTestEnvironment()->save();
         $fixture->performTearDown();
     } else {
         $fixture->performSetUp();
     }
     if ($input->getOption('set-phantomjs-symlinks')) {
         $this->createSymbolicLinksForUITests();
     }
     $this->writeSuccessMessage($output, array("Fixture successfully setup!"));
     $sqlDumpPath = $input->getOption('sqldump');
     if ($sqlDumpPath) {
         $this->createSqlDump($sqlDumpPath, $output);
     }
 }

作者:KiwiJuice    项目:handball-dacha   
/**
  * Computes the output for the given data table
  *
  * @param DataTable $table
  * @return string
  * @throws Exception
  */
 protected function renderTable($table)
 {
     if (!$table instanceof DataTable\Map || $table->getKeyName() != 'date') {
         throw new Exception("RSS feeds can be generated for one specific website &idSite=X." . "\nPlease specify only one idSite or consider using &format=XML instead.");
     }
     $idSite = Common::getRequestVar('idSite', 1, 'int');
     $period = Common::getRequestVar('period');
     $piwikUrl = Url::getCurrentUrlWithoutFileName() . "?module=CoreHome&action=index&idSite=" . $idSite . "&period=" . $period;
     $out = "";
     $moreRecentFirst = array_reverse($table->getDataTables(), true);
     foreach ($moreRecentFirst as $date => $subtable) {
         /** @var DataTable $subtable */
         $timestamp = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->getTimestamp();
         $site = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_SITE_INDEX);
         $pudDate = date('r', $timestamp);
         $dateInSiteTimezone = Date::factory($timestamp)->setTimezone($site->getTimezone())->toString('Y-m-d');
         $thisPiwikUrl = Common::sanitizeInputValue($piwikUrl . "&date={$dateInSiteTimezone}");
         $siteName = $site->getName();
         $title = $siteName . " on " . $date;
         $out .= "\t<item>\n\t\t<pubDate>{$pudDate}</pubDate>\n\t\t<guid>{$thisPiwikUrl}</guid>\n\t\t<link>{$thisPiwikUrl}</link>\n\t\t<title>{$title}</title>\n\t\t<author>http://piwik.org</author>\n\t\t<description>";
         $out .= Common::sanitizeInputValue($this->renderDataTable($subtable));
         $out .= "</description>\n\t</item>\n";
     }
     $header = $this->getRssHeader();
     $footer = $this->getRssFooter();
     return $header . $out . $footer;
 }

作者:sgieh    项目:piwik-plugin-GoogleAuthenticato   
public function __construct($username)
 {
     $this->username = $username;
     $this->title = 'Piwik - ' . Url::getCurrentHost();
     $this->description = Piwik::getCurrentUserLogin();
     $this->load();
 }

作者:FluentDevelopmen    项目:piwi   
public function setUp()
 {
     parent::setup();
     File::reset();
     Url::setHost(false);
     $this->output = new Output('myid');
 }

作者:KiwiJuice    项目:handball-dacha   
/**
  * Check for a newer version
  *
  * @param bool $force Force check
  * @param int $interval Interval used for update checks
  */
 public static function check($force = false, $interval = null)
 {
     if (!self::isAutoUpdateEnabled()) {
         return;
     }
     if ($interval === null) {
         $interval = self::CHECK_INTERVAL;
     }
     $lastTimeChecked = Option::get(self::LAST_TIME_CHECKED);
     if ($force || $lastTimeChecked === false || time() - $interval > $lastTimeChecked) {
         // set the time checked first, so that parallel Piwik requests don't all trigger the http requests
         Option::set(self::LAST_TIME_CHECKED, time(), $autoLoad = 1);
         $parameters = array('piwik_version' => Version::VERSION, 'php_version' => PHP_VERSION, 'url' => Url::getCurrentUrlWithoutQueryString(), 'trigger' => Common::getRequestVar('module', '', 'string'), 'timezone' => API::getInstance()->getDefaultTimezone());
         $url = Config::getInstance()->General['api_service_url'] . '/1.0/getLatestVersion/' . '?' . http_build_query($parameters, '', '&');
         $timeout = self::SOCKET_TIMEOUT;
         if (@Config::getInstance()->Debug['allow_upgrades_to_beta']) {
             $url = 'http://builds.piwik.org/LATEST_BETA';
         }
         try {
             $latestVersion = Http::sendHttpRequest($url, $timeout);
             if (!preg_match('~^[0-9][0-9a-zA-Z_.-]*$~D', $latestVersion)) {
                 $latestVersion = '';
             }
         } catch (Exception $e) {
             // e.g., disable_functions = fsockopen; allow_url_open = Off
             $latestVersion = '';
         }
         Option::set(self::LATEST_VERSION, $latestVersion);
     }
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * Returns SEO statistics for a URL.
  *
  * @param string $url URL to request SEO stats for
  * @return DataTable
  */
 public function getRank($url)
 {
     Piwik::checkUserHasSomeViewAccess();
     $metricProvider = new ProviderCache(new Aggregator());
     $domain = Url::getHostFromUrl($url);
     $metrics = $metricProvider->getMetrics($domain);
     return $this->toDataTable($metrics);
 }

作者:dorelljame    项目:piwi   
public function test_getUrlToCheckForLatestAvailableVersion()
 {
     $version = Version::VERSION;
     $phpVersion = urlencode(PHP_VERSION);
     $url = urlencode(Url::getCurrentUrlWithoutQueryString());
     $urlToCheck = $this->channel->getUrlToCheckForLatestAvailableVersion();
     $this->assertStringStartsWith("http://api.piwik.org/1.0/getLatestVersion/?piwik_version={$version}&php_version={$phpVersion}&release_channel=my_channel&url={$url}&trigger=&timezone=", $urlToCheck);
 }

作者:carriercom    项目:piwi   
/**
  * Adds a report to the list of reports to display.
  *
  * @param string $category The report's category. Can be a i18n token.
  * @param string $title The report's title. Can be a i18n token.
  * @param string $action The controller action used to load the report, ie, Referrers.getAll
  * @param array $params The list of query parameters to use when loading the report.
  *                      This list overrides query parameters currently in use. For example,
  *                        array('idSite' => 2, 'viewDataTable' => 'goalsTable')
  *                      would mean the goals report for site w/ ID=2 will always be loaded.
  */
 public function addReport($category, $title, $action, $params = array())
 {
     list($module, $action) = explode('.', $action);
     $params = array('module' => $module, 'action' => $action) + $params;
     $categories = $this->dimensionCategories;
     $categories[$category][] = array('title' => $title, 'params' => $params, 'url' => Url::getCurrentQueryStringWithParametersModified($params));
     $this->dimensionCategories = $categories;
 }

作者:brienomatt    项目:elmsl   
/**
  * anonymous = in the session
  * authenticated user = in the session
  */
 public function saveLanguage()
 {
     $language = Common::getRequestVar('language');
     // Prevent CSRF only when piwik is not installed yet (During install user can change language)
     if (DbHelper::isInstalled()) {
         $this->checkTokenInUrl();
     }
     LanguagesManager::setLanguageForSession($language);
     Url::redirectToReferrer();
 }

作者:KiwiJuice    项目:handball-dacha   
/**
  * Returns the javascript tag for the given idSite.
  * This tag must be included on every page to be tracked by Piwik
  *
  * @param int $idSite
  * @param string $piwikUrl
  * @param bool $mergeSubdomains
  * @param bool $groupPageTitlesByDomain
  * @param bool $mergeAliasUrls
  * @param bool $visitorCustomVariables
  * @param bool $pageCustomVariables
  * @param bool $customCampaignNameQueryParam
  * @param bool $customCampaignKeywordParam
  * @param bool $doNotTrack
  * @internal param $
  * @return string The Javascript tag ready to be included on the HTML pages
  */
 public function getJavascriptTag($idSite, $piwikUrl = '', $mergeSubdomains = false, $groupPageTitlesByDomain = false, $mergeAliasUrls = false, $visitorCustomVariables = false, $pageCustomVariables = false, $customCampaignNameQueryParam = false, $customCampaignKeywordParam = false, $doNotTrack = false)
 {
     Piwik::checkUserHasViewAccess($idSite);
     if (empty($piwikUrl)) {
         $piwikUrl = Url::getCurrentUrlWithoutFileName();
     }
     $piwikUrl = Common::sanitizeInputValues($piwikUrl);
     $htmlEncoded = Piwik::getJavascriptCode($idSite, $piwikUrl, $mergeSubdomains, $groupPageTitlesByDomain, $mergeAliasUrls, $visitorCustomVariables, $pageCustomVariables, $customCampaignNameQueryParam, $customCampaignKeywordParam, $doNotTrack);
     $htmlEncoded = str_replace(array('<br>', '<br />', '<br/>'), '', $htmlEncoded);
     return $htmlEncoded;
 }

作者:KiwiJuice    项目:handball-dacha   
function __construct($id, $method = 'post', $attributes = null, $trackSubmit = false)
 {
     if (!isset($attributes['action'])) {
         $attributes['action'] = Url::getCurrentQueryString();
     }
     if (!isset($attributes['name'])) {
         $attributes['name'] = $id;
     }
     parent::__construct($id, $method, $attributes, $trackSubmit);
     $this->init();
 }

作者:carriercom    项目:piwi   
/**
  * @param InputInterface $input
  */
 protected function initHostAndQueryString(InputInterface $input)
 {
     $_GET = array();
     $hostname = $input->getOption('piwik-domain');
     Url::setHost($hostname);
     $query = $input->getArgument('url-query');
     $query = UrlHelper::getArrayFromQueryString($query);
     foreach ($query as $name => $value) {
         $_GET[$name] = $value;
     }
 }

作者:piwi    项目:piwi   
/**
  * @internal
  */
 public function setTrustedHosts($trustedHosts)
 {
     Piwik::checkUserHasSuperUserAccess();
     if (!Controller::isGeneralSettingsAdminEnabled()) {
         throw new Exception('General settings admin is ont enabled');
     }
     if (!empty($trustedHosts)) {
         Url::saveTrustedHostnameInConfig($trustedHosts);
         Config::getInstance()->forceSave();
     }
     return true;
 }

作者:brienomatt    项目:elmsl   
private function sendMail($subject, $body)
 {
     $feedbackEmailAddress = Config::getInstance()->General['feedback_email_address'];
     $subject = '[ Feedback Feature - Piwik ] ' . $subject;
     $body = Common::unsanitizeInputValue($body) . "\n" . 'Piwik ' . Version::VERSION . "\n" . 'IP: ' . IP::getIpFromHeader() . "\n" . 'URL: ' . Url::getReferrer() . "\n";
     $mail = new Mail();
     $mail->setFrom(Piwik::getCurrentUserEmail());
     $mail->addTo($feedbackEmailAddress, 'Piwik Team');
     $mail->setSubject($subject);
     $mail->setBodyText($body);
     @$mail->send();
 }

作者:KiwiJuice    项目:handball-dacha   
/**
  * Sets the sender.
  *
  * @param string $email Email address of the sender.
  * @param null|string $name Name of the sender.
  * @return Zend_Mail
  */
 public function setFrom($email, $name = null)
 {
     $hostname = Config::getInstance()->mail['defaultHostnameIfEmpty'];
     $piwikHost = Url::getCurrentHost($hostname);
     // If known Piwik URL, use it instead of "localhost"
     $piwikUrl = SettingsPiwik::getPiwikUrl();
     $url = parse_url($piwikUrl);
     if (isset($url['host']) && $url['host'] != 'localhost' && $url['host'] != '127.0.0.1') {
         $piwikHost = $url['host'];
     }
     $email = str_replace('{DOMAIN}', $piwikHost, $email);
     return parent::setFrom($email, $name);
 }

作者:FluentDevelopmen    项目:piwi   
private function isPageSpeedEnabled()
 {
     $url = Url::getCurrentUrlWithoutQueryString() . '?module=Installation&action=getEmptyPageForSystemCheck';
     try {
         $page = Http::sendHttpRequest($url, $timeout = 1, $userAgent = null, $destinationPath = null, $followDepth = 0, $acceptLanguage = false, $byteRange = false, $getExtendedInfo = true);
     } catch (\Exception $e) {
         $this->logger->info('Unable to test if mod_pagespeed is enabled: the request to {url} failed', array('url' => $url));
         // If the test failed, we assume Page speed is not enabled
         return false;
     }
     $headers = $page['headers'];
     return isset($headers['X-Mod-Pagespeed']) || isset($headers['X-Page-Speed']);
 }

作者:dorelljame    项目:piwi   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!defined('PIWIK_TEST_MODE')) {
         define('PIWIK_TEST_MODE', true);
     }
     Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables()));
     $serverGlobal = $input->getOption('server-global');
     if ($serverGlobal) {
         $_SERVER = json_decode($serverGlobal, true);
     }
     if (Config::getInstance()->database_tests['tables_prefix'] !== '') {
         throw new \Exception("To generate OmniFixture for the UI tests, you must set an empty tables_prefix in [database_tests]");
     }
     $this->requireFixtureFiles($input);
     $this->setIncludePathAsInTestBootstrap();
     $host = Url::getHost();
     if (empty($host)) {
         $host = 'localhost';
         Url::setHost('localhost');
     }
     $configDomainToSave = $input->getOption('save-config');
     if (!empty($configDomainToSave)) {
         $pathToDomainConfig = PIWIK_INCLUDE_PATH . '/config/' . $host . '.config.ini.php';
         if (!file_exists($pathToDomainConfig)) {
             link(PIWIK_INCLUDE_PATH . '/config/config.ini.php', $pathToDomainConfig);
         }
     }
     if ($input->getOption('set-phantomjs-symlinks')) {
         $this->createSymbolicLinksForUITests();
     }
     $fixture = $this->createFixture($input, $allowSave = !empty($configDomainToSave));
     $this->setupDatabaseOverrides($input, $fixture);
     // perform setup and/or teardown
     if ($input->getOption('teardown')) {
         $fixture->getTestEnvironment()->save();
         $fixture->performTearDown();
     } else {
         $fixture->performSetUp();
     }
     $this->writeSuccessMessage($output, array("Fixture successfully setup!"));
     $sqlDumpPath = $input->getOption('sqldump');
     if ($sqlDumpPath) {
         $this->createSqlDump($sqlDumpPath, $output);
     }
     if (!empty($configDomainToSave)) {
         Config::getInstance()->forceSave();
     }
 }

作者:KiwiJuice    项目:handball-dacha   
/**
  * anonymous = in the session
  * authenticated user = in the session and in DB
  */
 public function saveLanguage()
 {
     $language = Common::getRequestVar('language');
     // Prevent CSRF only when piwik is not installed yet (During install user can change language)
     if (DbHelper::isInstalled()) {
         $this->checkTokenInUrl();
     }
     LanguagesManager::setLanguageForSession($language);
     if (\Piwik\Registry::isRegistered('access')) {
         $currentUser = Piwik::getCurrentUserLogin();
         if ($currentUser && $currentUser !== 'anonymous') {
             API::getInstance()->setLanguageForUser($currentUser, $language);
         }
     }
     Url::redirectToReferrer();
 }

作者:piwi    项目:piwi   
/**
  * @param DataTable|DataTable\Map $dataTable
  * @param $visualization
  */
 protected function initChartObjectData($dataTable, $visualization)
 {
     // if the loaded datatable is a simple DataTable, it is most likely a plugin plotting some custom data
     // we don't expect plugin developers to return a well defined Set
     if ($dataTable instanceof DataTable) {
         parent::initChartObjectData($dataTable, $visualization);
         return;
     }
     // the X label is extracted from the 'period' object in the table's metadata
     $xLabels = array();
     foreach ($dataTable->getDataTables() as $metadataDataTable) {
         $xLabels[] = $metadataDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLocalizedShortString();
         // eg. "Aug 2009"
     }
     $units = $this->getUnitsForColumnsToDisplay();
     // if rows to display are not specified, default to all rows (TODO: perhaps this should be done elsewhere?)
     $rowsToDisplay = $this->properties['rows_to_display'] ?: array_unique($dataTable->getColumn('label')) ?: array(false);
     // collect series data to show. each row-to-display/column-to-display permutation creates a series.
     $allSeriesData = array();
     $seriesUnits = array();
     foreach ($rowsToDisplay as $rowLabel) {
         foreach ($this->properties['columns_to_display'] as $columnName) {
             $seriesLabel = $this->getSeriesLabel($rowLabel, $columnName);
             $seriesData = $this->getSeriesData($rowLabel, $columnName, $dataTable);
             $allSeriesData[$seriesLabel] = $seriesData;
             $seriesUnits[$seriesLabel] = $units[$columnName];
         }
     }
     $visualization->dataTable = $dataTable;
     $visualization->properties = $this->properties;
     $visualization->setAxisXLabels($xLabels);
     $visualization->setAxisYValues($allSeriesData);
     $visualization->setAxisYUnits($seriesUnits);
     $dataTables = $dataTable->getDataTables();
     if ($this->isLinkEnabled()) {
         $idSite = Common::getRequestVar('idSite', null, 'int');
         $periodLabel = reset($dataTables)->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLabel();
         $axisXOnClick = array();
         foreach ($dataTable->getDataTables() as $metadataDataTable) {
             $dateInUrl = $metadataDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart();
             $parameters = array('idSite' => $idSite, 'period' => $periodLabel, 'date' => $dateInUrl->toString(), 'segment' => \Piwik\API\Request::getRawSegmentFromRequest());
             $link = Url::getQueryStringFromParameters($parameters);
             $axisXOnClick[] = $link;
         }
         $visualization->setAxisXOnClick($axisXOnClick);
     }
 }

作者:piwi    项目:piwi   
public function render()
 {
     $idSite = Common::getRequestVar('idSite');
     $site = new Site($idSite);
     $url = urldecode(Common::getRequestVar('url', '', 'string'));
     if (!empty($url) && strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
         $url = 'http://' . $url;
     }
     if (empty($url) || !UrlHelper::isLookLikeUrl($url)) {
         $url = $site->getMainUrl();
     }
     $dataTable = API::getInstance()->getRank($url);
     /** @var \Piwik\DataTable\Renderer\Php $renderer */
     $renderer = Renderer::factory('php');
     $renderer->setSerialize(false);
     return $this->renderTemplate('getRank', array('urlToRank' => Url::getHostFromUrl($url), 'ranks' => $renderer->render($dataTable)));
 }


问题


面经


文章

微信
公众号

扫码关注公众号