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

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

作者:brienomatt    项目:elmsl   
/**
  * Performs a batch insert into a specific table using either LOAD DATA INFILE or plain INSERTs,
  * as a fallback. On MySQL, LOAD DATA INFILE is 20x faster than a series of plain INSERTs.
  *
  * @param string $tableName PREFIXED table name! you must call Common::prefixTable() before passing the table name
  * @param array $fields array of unquoted field names
  * @param array $values array of data to be inserted
  * @param bool $throwException Whether to throw an exception that was caught while trying
  *                                LOAD DATA INFILE, or not.
  * @throws Exception
  * @return bool  True if the bulk LOAD was used, false if we fallback to plain INSERTs
  */
 public static function tableInsertBatch($tableName, $fields, $values, $throwException = false)
 {
     $filePath = PIWIK_USER_PATH . '/tmp/assets/' . $tableName . '-' . Common::generateUniqId() . '.csv';
     $filePath = SettingsPiwik::rewriteTmpPathWithInstanceId($filePath);
     $loadDataInfileEnabled = Config::getInstance()->General['enable_load_data_infile'];
     if ($loadDataInfileEnabled && Db::get()->hasBulkLoader()) {
         try {
             $fileSpec = array('delim' => "\t", 'quote' => '"', 'escape' => '\\\\', 'escapespecial_cb' => function ($str) {
                 return str_replace(array(chr(92), chr(34)), array(chr(92) . chr(92), chr(92) . chr(34)), $str);
             }, 'eol' => "\r\n", 'null' => 'NULL');
             // hack for charset mismatch
             if (!DbHelper::isDatabaseConnectionUTF8() && !isset(Config::getInstance()->database['charset'])) {
                 $fileSpec['charset'] = 'latin1';
             }
             self::createCSVFile($filePath, $fileSpec, $values);
             if (!is_readable($filePath)) {
                 throw new Exception("File {$filePath} could not be read.");
             }
             $rc = self::createTableFromCSVFile($tableName, $fields, $filePath, $fileSpec);
             if ($rc) {
                 unlink($filePath);
                 return true;
             }
         } catch (Exception $e) {
             Log::info("LOAD DATA INFILE failed or not supported, falling back to normal INSERTs... Error was: %s", $e->getMessage());
             if ($throwException) {
                 throw $e;
             }
         }
     }
     // if all else fails, fallback to a series of INSERTs
     @unlink($filePath);
     self::tableInsertBatchIterate($tableName, $fields, $values);
     return false;
 }

作者:FluentDevelopmen    项目:piwi   
public function isInstalled()
 {
     if (is_null($this->isInstalled)) {
         $this->isInstalled = SettingsPiwik::isPiwikInstalled();
     }
     return $this->isInstalled;
 }

作者:bnkem    项目:piwi   
/**
  * Generate hash on user info and password
  *
  * @param string $userInfo User name, email, etc
  * @param string $password
  * @return string
  */
 private function generateHash($userInfo, $password)
 {
     // mitigate rainbow table attack
     $passwordLen = strlen($password) / 2;
     $hash = Common::hash($userInfo . substr($password, 0, $passwordLen) . SettingsPiwik::getSalt() . substr($password, $passwordLen));
     return $hash;
 }

作者:KiwiJuice    项目:handball-dacha   
/**
  * Cache buster based on
  *  - Piwik version
  *  - Loaded plugins
  *  - Super user salt
  *  - Latest
  *
  * @param string[] $pluginNames
  * @return string
  */
 public function piwikVersionBasedCacheBuster($pluginNames = false)
 {
     $currentGitHash = @file_get_contents(PIWIK_INCLUDE_PATH . '/.git/refs/heads/master');
     $pluginList = md5(implode(",", !$pluginNames ? Manager::getInstance()->getLoadedPluginsName() : $pluginNames));
     $cacheBuster = md5(SettingsPiwik::getSalt() . $pluginList . PHP_VERSION . Version::VERSION . trim($currentGitHash));
     return $cacheBuster;
 }

作者:diosmosi    项目:piwi   
protected function sendNotifications()
 {
     $latestVersion = $this->getLatestVersion();
     $host = SettingsPiwik::getPiwikUrl();
     $subject = Piwik::translate('CoreUpdater_NotificationSubjectAvailableCoreUpdate', $latestVersion);
     $message = Piwik::translate('ScheduledReports_EmailHello');
     $message .= "\n\n";
     $message .= Piwik::translate('CoreUpdater_ThereIsNewVersionAvailableForUpdate');
     $message .= "\n\n";
     $message .= Piwik::translate('CoreUpdater_YouCanUpgradeAutomaticallyOrDownloadPackage', $latestVersion);
     $message .= "\n";
     $message .= $host . 'index.php?module=CoreUpdater&action=newVersionAvailable';
     $message .= "\n\n";
     $version = new Version();
     if ($version->isStableVersion($latestVersion)) {
         $message .= Piwik::translate('CoreUpdater_ViewVersionChangelog');
         $message .= "\n";
         $message .= $this->getLinkToChangeLog($latestVersion);
         $message .= "\n\n";
     }
     $message .= Piwik::translate('CoreUpdater_FeedbackRequest');
     $message .= "\n";
     $message .= 'http://piwik.org/contact/';
     $this->sendEmailNotification($subject, $message);
 }

作者:KiwiJuice    项目:handball-dacha   
public function __construct()
 {
     $loader = $this->getDefaultThemeLoader();
     $this->addPluginNamespaces($loader);
     // If theme != default we need to chain
     $chainLoader = new Twig_Loader_Chain(array($loader));
     // Create new Twig Environment and set cache dir
     $templatesCompiledPath = PIWIK_USER_PATH . '/tmp/templates_c';
     $templatesCompiledPath = SettingsPiwik::rewriteTmpPathWithHostname($templatesCompiledPath);
     $this->twig = new Twig_Environment($chainLoader, array('debug' => true, 'strict_variables' => true, 'cache' => $templatesCompiledPath));
     $this->twig->addExtension(new Twig_Extension_Debug());
     $this->twig->clearTemplateCache();
     $this->addFilter_translate();
     $this->addFilter_urlRewriteWithParameters();
     $this->addFilter_sumTime();
     $this->addFilter_money();
     $this->addFilter_truncate();
     $this->addFilter_notificiation();
     $this->addFilter_percentage();
     $this->twig->addFilter(new Twig_SimpleFilter('implode', 'implode'));
     $this->twig->addFilter(new Twig_SimpleFilter('ucwords', 'ucwords'));
     $this->addFunction_includeAssets();
     $this->addFunction_linkTo();
     $this->addFunction_sparkline();
     $this->addFunction_postEvent();
     $this->addFunction_isPluginLoaded();
     $this->addFunction_getJavascriptTranslations();
 }

作者:diosmosi    项目:piwi   
/**
  * 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 = SettingsPiwik::getPiwikUrl() . "?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);
         if ($site) {
             $dateInSiteTimezone = $dateInSiteTimezone->setTimezone($site->getTimezone());
         }
         $dateInSiteTimezone = $dateInSiteTimezone->toString('Y-m-d');
         $thisPiwikUrl = Common::sanitizeInputValue($piwikUrl . "&date={$dateInSiteTimezone}");
         $siteName = $site ? $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;
 }

作者:carriercom    项目:piwi   
public function configureTopMenu(MenuTop $menu)
 {
     if (Piwik::isUserIsAnonymous() || !SettingsPiwik::isPiwikInstalled()) {
         $langManager = new LanguagesManager();
         $menu->addHtml('LanguageSelector', $langManager->getLanguagesSelector(), true, $order = 30, false);
     }
 }

作者:carriercom    项目:piwi   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $path = sprintf('%s/tmp/logs/', PIWIK_DOCUMENT_ROOT);
     $path = SettingsPiwik::rewriteTmpPathWithInstanceId($path);
     $cmd = sprintf('tail -f %s*.log', $path);
     $output->writeln('Executing command: ' . $cmd);
     passthru($cmd);
 }

作者:brienomatt    项目:elmsl   
/**
  * Returns a 64-bit hash of all the configuration settings
  * @param $os
  * @param $browserName
  * @param $browserVersion
  * @param $plugin_Flash
  * @param $plugin_Java
  * @param $plugin_Director
  * @param $plugin_Quicktime
  * @param $plugin_RealPlayer
  * @param $plugin_PDF
  * @param $plugin_WindowsMedia
  * @param $plugin_Gears
  * @param $plugin_Silverlight
  * @param $plugin_Cookie
  * @param $ip
  * @param $browserLang
  * @return string
  */
 protected function getConfigHash($os, $browserName, $browserVersion, $plugin_Flash, $plugin_Java, $plugin_Director, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF, $plugin_WindowsMedia, $plugin_Gears, $plugin_Silverlight, $plugin_Cookie, $ip, $browserLang)
 {
     // prevent the config hash from being the same, across different Piwik instances
     // (limits ability of different Piwik instances to cross-match users)
     $salt = SettingsPiwik::getSalt();
     $configString = $os . $browserName . $browserVersion . $plugin_Flash . $plugin_Java . $plugin_Director . $plugin_Quicktime . $plugin_RealPlayer . $plugin_PDF . $plugin_WindowsMedia . $plugin_Gears . $plugin_Silverlight . $plugin_Cookie . $ip . $browserLang . $salt;
     $hash = md5($configString, $raw_output = true);
     return substr($hash, 0, Tracker::LENGTH_BINARY_ID);
 }

作者:KiwiJuice    项目:handball-dacha   
/**
  * @param string $directory directory to use
  * @param int $timeToLiveInSeconds TTL
  */
 public function __construct($directory, $timeToLiveInSeconds = 300)
 {
     $cachePath = PIWIK_USER_PATH . '/tmp/cache/' . $directory . '/';
     $this->cachePath = SettingsPiwik::rewriteTmpPathWithHostname($cachePath);
     if ($timeToLiveInSeconds < self::MINIMUM_TTL) {
         $timeToLiveInSeconds = self::MINIMUM_TTL;
     }
     $this->ttl = $timeToLiveInSeconds;
 }

作者:TensorWrenchOS    项目:piwi   
function checkPiwikSetupForTests()
{
    if (empty($_SERVER['REQUEST_URI']) || $_SERVER['REQUEST_URI'] == '@REQUEST_URI@') {
        echo "WARNING: for tests to pass, you must first:\n1) Install webserver on localhost, eg. apache\n2) Make these Piwik files available on the webserver, at eg. http://localhost/dev/piwik/\n3) Install Piwik by going through the installation process\n4) Copy phpunit.xml.dist to phpunit.xml\n5) Edit in phpunit.xml the @REQUEST_URI@ and replace with the webserver path to Piwik, eg. '/dev/piwik/'\n\nTry again.\n-> If you still get this message, you can work around it by specifying Host + Request_Uri at the top of this file tests/PHPUnit/bootstrap.php. <-";
        exit(1);
    }
    $baseUrl = \Piwik\Tests\Framework\Fixture::getRootUrl();
    \Piwik\SettingsPiwik::checkPiwikServerWorking($baseUrl, $acceptInvalidSSLCertificates = true);
}

作者:diosmosi    项目:piwi   
/**
  * @param $idSites
  * @return array
  */
 private static function getSegmentsToProcess($idSites)
 {
     $knownSegmentsToArchiveAllSites = SettingsPiwik::getKnownSegmentsToArchive();
     $segmentsToProcess = $knownSegmentsToArchiveAllSites;
     foreach ($idSites as $idSite) {
         $segmentForThisWebsite = SettingsPiwik::getKnownSegmentsToArchiveForSite($idSite);
         $segmentsToProcess = array_merge($segmentsToProcess, $segmentForThisWebsite);
     }
     $segmentsToProcess = array_unique($segmentsToProcess);
     return $segmentsToProcess;
 }

作者:KiwiJuice    项目:handball-dacha   
/**
  * Adds Referrer widgets
  */
 function addWidgets()
 {
     WidgetsList::add('Referrers_Referrers', 'Referrers_WidgetKeywords', 'Referrers', 'getKeywords');
     WidgetsList::add('Referrers_Referrers', 'Referrers_WidgetExternalWebsites', 'Referrers', 'getWebsites');
     WidgetsList::add('Referrers_Referrers', 'Referrers_WidgetSocials', 'Referrers', 'getSocials');
     WidgetsList::add('Referrers_Referrers', 'Referrers_SearchEngines', 'Referrers', 'getSearchEngines');
     WidgetsList::add('Referrers_Referrers', 'Referrers_Campaigns', 'Referrers', 'getCampaigns');
     WidgetsList::add('Referrers_Referrers', 'General_Overview', 'Referrers', 'getReferrerType');
     WidgetsList::add('Referrers_Referrers', 'Referrers_WidgetGetAll', 'Referrers', 'getAll');
     if (SettingsPiwik::isSegmentationEnabled()) {
         WidgetsList::add('SEO', 'Referrers_WidgetTopKeywordsForPages', 'Referrers', 'getKeywordsForPage');
     }
 }

作者: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   
/**
  * Constructor.
  *
  * @param string $segmentCondition The segment condition, eg, `'browserCode=ff;countryCode=CA'`.
  * @param array $idSites The list of sites the segment will be used with. Some segments are
  *                       dependent on the site, such as goal segments.
  * @throws
  */
 public function __construct($segmentCondition, $idSites)
 {
     $segmentCondition = trim($segmentCondition);
     if (!SettingsPiwik::isSegmentationEnabled() && !empty($segmentCondition)) {
         throw new Exception("The Super User has disabled the Segmentation feature.");
     }
     // First try with url decoded value. If that fails, try with raw value.
     // If that also fails, it will throw the exception
     try {
         $this->initializeSegment(urldecode($segmentCondition), $idSites);
     } catch (Exception $e) {
         $this->initializeSegment($segmentCondition, $idSites);
     }
 }

作者:FluentDevelopmen    项目:piwi   
public function setUp()
 {
     parent::setUp();
     Fixture::createWebsite('2014-02-04');
     $testingEnvironment = new \Piwik\Tests\Framework\TestingEnvironmentVariables();
     $testingEnvironment->testCaseClass = null;
     $testingEnvironment->addFailingScheduledTask = false;
     $testingEnvironment->addScheduledTask = false;
     $testingEnvironment->save();
     Option::delete(self::TASKS_STARTED_OPTION_NAME);
     Option::delete(self::TASKS_FINISHED_OPTION_NAME);
     Option::delete(Timetable::TIMETABLE_OPTION_STRING);
     SettingsPiwik::overwritePiwikUrl(self::$fixture->getRootUrl() . "tests/PHPUnit/proxy");
 }

作者:brienomatt    项目:elmsl   
public function configure(WidgetsList $widgetsList)
 {
     $category = 'Referrers_Referrers';
     $controller = 'Referrers';
     $widgetsList->add($category, 'Referrers_WidgetKeywords', $controller, 'getKeywords');
     $widgetsList->add($category, 'Referrers_WidgetExternalWebsites', $controller, 'getWebsites');
     $widgetsList->add($category, 'Referrers_WidgetSocials', $controller, 'getSocials');
     $widgetsList->add($category, 'Referrers_SearchEngines', $controller, 'getSearchEngines');
     $widgetsList->add($category, 'Referrers_Campaigns', $controller, 'getCampaigns');
     $widgetsList->add($category, 'General_Overview', $controller, 'getReferrerType');
     $widgetsList->add($category, 'Referrers_WidgetGetAll', $controller, 'getAll');
     if (SettingsPiwik::isSegmentationEnabled()) {
         $widgetsList->add('SEO', 'Referrers_WidgetTopKeywordsForPages', $controller, 'getKeywordsForPage');
     }
 }

作者:KiwiJuice    项目:handball-dacha   
public static function shouldProcessReportsAllPlugins(Segment $segment, $periodLabel)
 {
     if ($segment->isEmpty() && $periodLabel != 'range') {
         return true;
     }
     $segmentsToProcess = SettingsPiwik::getKnownSegmentsToArchive();
     if (!empty($segmentsToProcess)) {
         // If the requested segment is one of the segments to pre-process
         // we ensure that any call to the API will trigger archiving of all reports for this segment
         $segment = $segment->getString();
         if (in_array($segment, $segmentsToProcess)) {
             return true;
         }
     }
     return false;
 }

作者:brienomatt    项目:elmsl   
/**
  * Returns an existing nonce by ID. If none exists, a new nonce will be generated.
  *
  * @param string $id Unique id to avoid namespace conflicts, e.g., `'ModuleName.ActionName'`.
  * @param int $ttl Optional time-to-live in seconds; default is 5 minutes. (ie, in 5 minutes,
  *                 the nonce will no longer be valid).
  * @return string
  */
 public static function getNonce($id, $ttl = 600)
 {
     // save session-dependent nonce
     $ns = new SessionNamespace($id);
     $nonce = $ns->nonce;
     // re-use an unexpired nonce (a small deviation from the "used only once" principle, so long as we do not reset the expiration)
     // to handle browser pre-fetch or double fetch caused by some browser add-ons/extensions
     if (empty($nonce)) {
         // generate a new nonce
         $nonce = md5(SettingsPiwik::getSalt() . time() . Common::generateUniqId());
         $ns->nonce = $nonce;
     }
     // extend lifetime if nonce is requested again to prevent from early timeout if nonce is requested again
     // a few seconds before timeout
     $ns->setExpirationSeconds($ttl, 'nonce');
     return $nonce;
 }


问题


面经


文章

微信
公众号

扫码关注公众号