idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
24,800
public function update ( $ idSite , $ idNote , $ date = null , $ note = null , $ starred = null ) { $ this -> checkIdSiteIsLoaded ( $ idSite ) ; $ this -> checkNoteExists ( $ idSite , $ idNote ) ; $ annotation = & $ this -> annotations [ $ idSite ] [ $ idNote ] ; if ( $ date !== null ) { $ annotation [ 'date' ] = Date ...
Modifies an annotation in this instance s collection of annotations .
24,801
public function remove ( $ idSite , $ idNote ) { $ this -> checkIdSiteIsLoaded ( $ idSite ) ; $ this -> checkNoteExists ( $ idSite , $ idNote ) ; unset ( $ this -> annotations [ $ idSite ] [ $ idNote ] ) ; }
Removes a note from a site s collection of annotations .
24,802
public function get ( $ idSite , $ idNote ) { $ this -> checkIdSiteIsLoaded ( $ idSite ) ; $ this -> checkNoteExists ( $ idSite , $ idNote ) ; $ annotation = $ this -> annotations [ $ idSite ] [ $ idNote ] ; $ this -> augmentAnnotationData ( $ idSite , $ idNote , $ annotation ) ; return $ annotation ; }
Retrieves an annotation by ID .
24,803
public function search ( $ startDate , $ endDate , $ idSite = false ) { if ( $ idSite ) { $ idSites = Site :: getIdSitesFromIdSitesString ( $ idSite ) ; } else { $ idSites = array_keys ( $ this -> annotations ) ; } $ result = array ( ) ; foreach ( $ idSites as $ idSite ) { if ( ! isset ( $ this -> annotations [ $ idSit...
Returns all annotations within a specific date range . The result is an array that maps site IDs with arrays of annotations within the range .
24,804
public function count ( $ idSite , $ startDate , $ endDate ) { $ this -> checkIdSiteIsLoaded ( $ idSite ) ; $ annotations = $ this -> search ( $ startDate , Date :: factory ( $ endDate -> getTimestamp ( ) - 1 ) ) ; $ count = $ starred = 0 ; if ( ! empty ( $ annotations [ $ idSite ] ) ) { $ count = count ( $ annotations...
Counts annotations & starred annotations within a date range and returns the counts . The date range includes the start date but not the end date .
24,805
private function makeAnnotation ( $ date , $ note , $ starred = 0 ) { return array ( 'date' => $ date , 'note' => $ note , 'starred' => ( int ) $ starred , 'user' => Piwik :: getCurrentUserLogin ( ) ) ; }
Utility function . Creates a new annotation .
24,806
private function getAnnotationsForSite ( ) { $ result = array ( ) ; foreach ( $ this -> idSites as $ id ) { $ optionName = self :: getAnnotationCollectionOptionName ( $ id ) ; $ serialized = Option :: get ( $ optionName ) ; if ( $ serialized !== false ) { $ result [ $ id ] = Common :: safe_unserialize ( $ serialized ) ...
Retrieves annotations from the database for the sites supplied to the constructor .
24,807
public static function canUserModifyOrDelete ( $ idSite , $ annotation ) { $ canEdit = Piwik :: isUserHasWriteAccess ( $ idSite ) || ( ! Piwik :: isUserIsAnonymous ( ) && Piwik :: getCurrentUserLogin ( ) == $ annotation [ 'user' ] ) ; return $ canEdit ; }
Returns true if the current user can modify or delete a specific annotation .
24,808
private function augmentAnnotationData ( $ idSite , $ idNote , & $ annotation ) { $ annotation [ 'idNote' ] = $ idNote ; $ annotation [ 'canEditOrDelete' ] = self :: canUserModifyOrDelete ( $ idSite , $ annotation ) ; if ( Piwik :: isUserIsAnonymous ( ) ) { unset ( $ annotation [ 'user' ] ) ; } }
Adds extra data to an annotation including the annotation s ID and whether the current user can edit or delete it .
24,809
public function areSMSAPICredentialProvided ( ) { Piwik :: checkUserHasSomeViewAccess ( ) ; $ credential = $ this -> getSMSAPICredential ( ) ; return isset ( $ credential [ MobileMessaging :: API_KEY_OPTION ] ) ; }
determine if SMS API credential are available for the current user
24,810
public function setSMSAPICredential ( $ provider , $ credentials = array ( ) ) { $ this -> checkCredentialManagementRights ( ) ; $ smsProviderInstance = SMSProvider :: factory ( $ provider ) ; $ smsProviderInstance -> verifyCredential ( $ credentials ) ; $ settings = $ this -> getCredentialManagerSettings ( ) ; $ setti...
set the SMS API credential
24,811
public function addPhoneNumber ( $ phoneNumber ) { Piwik :: checkUserIsNotAnonymous ( ) ; $ phoneNumber = self :: sanitizePhoneNumber ( $ phoneNumber ) ; $ verificationCode = "" ; for ( $ i = 0 ; $ i < self :: VERIFICATION_CODE_LENGTH ; $ i ++ ) { $ verificationCode .= mt_rand ( 0 , 9 ) ; } $ smsText = Piwik :: transla...
add phone number
24,812
public function sendSMS ( $ content , $ phoneNumber , $ from ) { Piwik :: checkUserIsNotAnonymous ( ) ; $ credential = $ this -> getSMSAPICredential ( ) ; $ SMSProvider = SMSProvider :: factory ( $ credential [ MobileMessaging :: PROVIDER_OPTION ] ) ; $ SMSProvider -> sendSMS ( $ credential [ MobileMessaging :: API_KEY...
send a SMS
24,813
public function getCreditLeft ( ) { $ this -> checkCredentialManagementRights ( ) ; $ credential = $ this -> getSMSAPICredential ( ) ; $ SMSProvider = SMSProvider :: factory ( $ credential [ MobileMessaging :: PROVIDER_OPTION ] ) ; return $ SMSProvider -> getCreditLeft ( $ credential [ MobileMessaging :: API_KEY_OPTION...
get remaining credit
24,814
public function removePhoneNumber ( $ phoneNumber ) { Piwik :: checkUserIsNotAnonymous ( ) ; $ phoneNumbers = $ this -> retrievePhoneNumbers ( ) ; unset ( $ phoneNumbers [ $ phoneNumber ] ) ; $ this -> savePhoneNumbers ( $ phoneNumbers ) ; Piwik :: postEvent ( 'MobileMessaging.deletePhoneNumber' , array ( $ phoneNumber...
remove phone number
24,815
public function validatePhoneNumber ( $ phoneNumber , $ verificationCode ) { Piwik :: checkUserIsNotAnonymous ( ) ; $ phoneNumbers = $ this -> retrievePhoneNumbers ( ) ; if ( isset ( $ phoneNumbers [ $ phoneNumber ] ) ) { if ( $ verificationCode == $ phoneNumbers [ $ phoneNumber ] ) { $ phoneNumbers [ $ phoneNumber ] =...
validate phone number
24,816
public function getPhoneNumbers ( ) { Piwik :: checkUserIsNotAnonymous ( ) ; $ rawPhoneNumbers = $ this -> retrievePhoneNumbers ( ) ; $ phoneNumbers = array ( ) ; foreach ( $ rawPhoneNumbers as $ phoneNumber => $ verificationCode ) { $ phoneNumbers [ $ phoneNumber ] = self :: isActivated ( $ verificationCode ) ; } retu...
get phone number list
24,817
public function getActivatedPhoneNumbers ( ) { Piwik :: checkUserIsNotAnonymous ( ) ; $ phoneNumbers = $ this -> retrievePhoneNumbers ( ) ; $ activatedPhoneNumbers = array ( ) ; foreach ( $ phoneNumbers as $ phoneNumber => $ verificationCode ) { if ( self :: isActivated ( $ verificationCode ) ) { $ activatedPhoneNumber...
get activated phone number list
24,818
public function deleteSMSAPICredential ( ) { $ this -> checkCredentialManagementRights ( ) ; $ settings = $ this -> getCredentialManagerSettings ( ) ; $ settings [ MobileMessaging :: API_KEY_OPTION ] = null ; $ this -> setCredentialManagerSettings ( $ settings ) ; return true ; }
delete the SMS API credential
24,819
protected function validateOwner ( ) { $ rule = clone $ this -> getConfig ( ) ; foreach ( $ this -> owner -> getRecursiveIterator ( RecursiveIteratorIterator :: LEAVES_ONLY ) as $ child ) { $ rule -> setOwner ( $ child ) ; if ( ! $ rule -> validateOwner ( ) ) { return false ; } } return true ; }
Validates the owner s children using the template Rule
24,820
public function setConfig ( $ config ) { if ( ! $ config instanceof HTML_QuickForm2_Rule ) { throw new HTML_QuickForm2_InvalidArgumentException ( 'Each Rule requires a template Rule to validate with, ' . preg_replace ( '/\s+/' , ' ' , var_export ( $ config , true ) ) . ' given' ) ; } elseif ( $ config instanceof HTML_Q...
Sets the template Rule to use for actual validation
24,821
protected function isTimestampValid ( $ time , $ now = null ) { if ( empty ( $ now ) ) { $ now = $ this -> getCurrentTimestamp ( ) ; } return $ time <= $ now && $ time > $ now - 20 * 365 * 86400 ; }
Returns true if the timestamp is valid ie . timestamp is sometime in the last 10 years and is not in the future .
24,822
public function setThirdPartyCookie ( $ idVisitor ) { if ( ! $ this -> shouldUseThirdPartyCookie ( ) ) { return ; } $ cookie = $ this -> makeThirdPartyCookieUID ( ) ; $ idVisitor = bin2hex ( $ idVisitor ) ; $ cookie -> set ( 0 , $ idVisitor ) ; $ cookie -> save ( ) ; Common :: printDebug ( sprintf ( "We set the visitor...
Update the cookie information .
24,823
public function getVisitorIdForThirdPartyCookie ( ) { $ found = false ; if ( ! $ found ) { $ useThirdPartyCookie = $ this -> shouldUseThirdPartyCookie ( ) ; if ( $ useThirdPartyCookie ) { $ idVisitor = $ this -> getThirdPartyCookieVisitorId ( ) ; if ( ! empty ( $ idVisitor ) ) { $ found = true ; } } } if ( ! $ found ) ...
When creating a third party cookie we want to ensure that the original value set in this 3rd party cookie sticks and is not overwritten later .
24,824
public function getMetadata ( $ pluginName , $ key ) { return isset ( $ this -> requestMetadata [ $ pluginName ] [ $ key ] ) ? $ this -> requestMetadata [ $ pluginName ] [ $ key ] : null ; }
Get a request metadata value . Returns null if none exists .
24,825
protected function _checkRequiredOptions ( array $ config ) { if ( ! array_key_exists ( 'dbname' , $ config ) ) { throw new Zend_Db_Adapter_Exception ( "Configuration array must have a key for 'dbname' that names the database instance" ) ; } if ( ! array_key_exists ( 'password' , $ config ) && array_key_exists ( 'usern...
Check for config options that are mandatory . Throw exceptions if any are missing .
24,826
public function setTransactionIsolationLevel ( $ level = null ) { $ this -> _connect ( ) ; $ sql = null ; if ( $ level === null ) { $ level = SQLSRV_TXN_READ_COMMITTED ; } switch ( $ level ) { case SQLSRV_TXN_READ_UNCOMMITTED : $ sql = "READ UNCOMMITTED" ; break ; case SQLSRV_TXN_READ_COMMITTED : $ sql = "READ COMMITTE...
Set the transaction isoltion level .
24,827
public function setMasterFiles ( array $ masterFiles ) { $ this -> _specificOptions [ 'master_file' ] = null ; $ this -> _specificOptions [ 'master_files' ] = null ; $ this -> _masterFile_mtimes = array ( ) ; clearstatcache ( ) ; $ i = 0 ; foreach ( $ masterFiles as $ masterFile ) { if ( file_exists ( $ masterFile ) ) ...
Change the master_files option
24,828
protected function formatValue ( $ value , $ divisor ) { $ quotient = 0 ; if ( $ divisor > 0 && $ value > 0 ) { $ quotient = round ( $ value / $ divisor , $ this -> quotientPrecision ) ; } return $ quotient ; }
Formats the given value
24,829
protected function getDivisor ( $ row ) { if ( ! is_null ( $ this -> totalValueUsedAsDivisor ) ) { return $ this -> totalValueUsedAsDivisor ; } elseif ( $ this -> getDivisorFromSummaryRow ) { $ summaryRow = $ this -> table -> getRowFromId ( DataTable :: ID_SUMMARY_ROW ) ; return $ summaryRow -> getColumn ( $ this -> co...
Returns the divisor to use when calculating the new column value . Can be overridden by descendent classes to customize behavior .
24,830
public function getCountryList ( $ includeInternalCodes = false ) { if ( $ this -> countryList === null ) { $ this -> countryList = require __DIR__ . '/../Resources/countries.php' ; } if ( $ this -> countryExtraList === null ) { $ this -> countryExtraList = require __DIR__ . '/../Resources/countries-extra.php' ; } if (...
Returns the list of valid country codes .
24,831
public function checkServerVersion ( ) { $ databaseVersion = $ this -> getServerVersion ( ) ; $ requiredVersion = Config :: getInstance ( ) -> General [ 'minimum_pgsql_version' ] ; if ( version_compare ( $ databaseVersion , $ requiredVersion ) === - 1 ) { throw new Exception ( Piwik :: translate ( 'General_ExceptionDat...
Check PostgreSQL version
24,832
private function getDeleteIdVisitOffset ( $ deleteLogsOlderThan ) { $ logVisit = Common :: prefixTable ( "log_visit" ) ; $ maxIdVisit = Db :: fetchOne ( "SELECT MAX(idvisit) FROM $logVisit" ) ; if ( empty ( $ maxIdVisit ) ) { return false ; } $ dateStart = Date :: factory ( "today" ) -> subDay ( $ deleteLogsOlderThan )...
get highest idVisit to delete rows from
24,833
public static function getDeleteTableLogTables ( ) { $ provider = StaticContainer :: get ( 'Piwik\Plugin\LogTablesProvider' ) ; $ result = array ( ) ; foreach ( $ provider -> getAllLogTables ( ) as $ logTable ) { if ( $ logTable -> getColumnToJoinOnIdVisit ( ) ) { $ result [ ] = Common :: prefixTable ( $ logTable -> ge...
let s hardcode since these are not dynamically created tables
24,834
public static function hasReportBeenPurged ( $ dataTable ) { $ strPeriod = Common :: getRequestVar ( 'period' , false ) ; $ strDate = Common :: getRequestVar ( 'date' , false ) ; if ( false !== $ strPeriod && false !== $ strDate && ( is_null ( $ dataTable ) || ( ! empty ( $ dataTable ) && $ dataTable -> getRowsCount ( ...
Returns true if it is likely that the data for this report has been purged and if the user should be told about that .
24,835
public function installationFormInit ( FormDefaultSettings $ form ) { $ form -> addElement ( 'checkbox' , 'do_not_track' , null , array ( 'content' => '<div class="form-help">' . Piwik :: translate ( 'PrivacyManager_DoNotTrack_EnabledMoreInfo' ) . '</div> &nbsp;&nbsp;' . Piwik :: translate ( 'PrivacyManager_DoNotTrack_...
Customize the Installation default settings form .
24,836
public function installationFormSubmit ( FormDefaultSettings $ form ) { $ doNotTrack = ( bool ) $ form -> getSubmitValue ( 'do_not_track' ) ; $ dntChecker = new DoNotTrackHeaderChecker ( ) ; if ( $ doNotTrack ) { $ dntChecker -> activate ( ) ; } else { $ dntChecker -> deactivate ( ) ; } $ anonymiseIp = ( bool ) $ form ...
Process the submit on the Installation default settings form .
24,837
public static function getPurgeDataSettings ( ) { $ settings = array ( ) ; $ config = PiwikConfig :: getInstance ( ) ; foreach ( self :: $ purgeDataOptions as $ configKey => $ configSection ) { $ values = $ config -> $ configSection ; $ settings [ $ configKey ] = $ values [ $ configKey ] ; } if ( ! Controller :: isData...
Returns the settings for the data purging feature .
24,838
public static function savePurgeDataSettings ( $ settings ) { foreach ( self :: $ purgeDataOptions as $ configName => $ configSection ) { if ( isset ( $ settings [ $ configName ] ) ) { Option :: set ( $ configName , $ settings [ $ configName ] ) ; } } }
Saves the supplied data purging settings .
24,839
public function deleteLogData ( ) { $ settings = self :: getPurgeDataSettings ( ) ; if ( $ settings [ 'delete_logs_enable' ] == 0 ) { return false ; } if ( ! $ this -> shouldPurgeData ( $ settings , self :: OPTION_LAST_DELETE_PIWIK_LOGS , 'delete_logs_schedule_lowest_interval' ) ) { return false ; } $ lastDeleteDate = ...
Deletes old raw data based on the options set in the Deletelogs config section . This is a scheduled task and will only execute every N days . The number of days is determined by the delete_logs_schedule_lowest_interval config option .
24,840
public static function getPurgeEstimate ( $ settings = null ) { if ( is_null ( $ settings ) ) { $ settings = self :: getPurgeDataSettings ( ) ; } $ result = array ( ) ; if ( $ settings [ 'delete_logs_enable' ] ) { $ logDataPurger = StaticContainer :: get ( 'Piwik\Plugins\PrivacyManager\LogDataPurger' ) ; $ result = arr...
Returns an array describing what data would be purged if both raw data & report purging is invoked .
24,841
public static function getAllMetricsToKeep ( ) { $ metricsToKeep = self :: getMetricsToKeep ( ) ; if ( Common :: isGoalPluginEnabled ( ) ) { $ goalMetricsToKeep = self :: getGoalMetricsToKeep ( ) ; $ maxGoalId = self :: getMaxGoalId ( ) ; foreach ( $ goalMetricsToKeep as $ metric ) { for ( $ i = 1 ; $ i <= $ maxGoalId ...
Returns the names of metrics that should be kept when purging as they appear in archive tables .
24,842
private function shouldPurgeData ( $ settings , $ lastRanOption , $ setting ) { $ initialDelete = Option :: get ( self :: OPTION_LAST_DELETE_PIWIK_LOGS_INITIAL ) ; if ( empty ( $ initialDelete ) ) { Option :: set ( self :: OPTION_LAST_DELETE_PIWIK_LOGS_INITIAL , 1 ) ; return false ; } $ lastDelete = Option :: get ( $ l...
Returns true if one of the purge data tasks should run now false if it shouldn t .
24,843
public static function getUserIdSalt ( ) { $ salt = Option :: get ( self :: OPTION_USERID_SALT ) ; if ( empty ( $ salt ) ) { $ salt = Common :: getRandomString ( $ len = 40 , $ alphabet = "abcdefghijklmnoprstuvwxyzABCDEFGHIJKLMNOPRSTUVWXYZ0123456789_-$" ) ; Option :: set ( self :: OPTION_USERID_SALT , $ salt , 1 ) ; } ...
Returns a unique salt used for pseudonimisation of user id only
24,844
public function getByDayOfWeek ( $ idSite , $ period , $ date , $ segment = false ) { Piwik :: checkUserHasViewAccess ( $ idSite ) ; $ metrics = Metrics :: getVisitsMetricNames ( ) ; unset ( $ metrics [ Metrics :: INDEX_MAX_ACTIONS ] ) ; if ( Period :: isMultiplePeriod ( $ date , $ period ) ) { throw new Exception ( "V...
Returns datatable describing the number of visits for each day of the week .
24,845
protected static function getSecondsGap ( ) { $ secondsGap = array ( ) ; foreach ( self :: $ timeGap as $ gap ) { if ( count ( $ gap ) == 3 && $ gap [ 2 ] == 's' ) { $ secondsGap [ ] = array ( $ gap [ 0 ] , $ gap [ 1 ] ) ; } else if ( count ( $ gap ) == 2 ) { $ secondsGap [ ] = array ( $ gap [ 0 ] * 60 , $ gap [ 1 ] * ...
Transforms and returns the set of ranges used to calculate the visits by total time report from ranges in minutes to equivalent ranges in seconds .
24,846
public static function getMemoryUsage ( ) { $ memory = false ; if ( function_exists ( 'xdebug_memory_usage' ) ) { $ memory = xdebug_memory_usage ( ) ; } elseif ( function_exists ( 'memory_get_usage' ) ) { $ memory = memory_get_usage ( ) ; } if ( $ memory === false ) { return "Memory usage function not found." ; } $ usa...
Returns memory usage
24,847
public static function displayDbProfileReport ( ) { $ profiler = Db :: get ( ) -> getProfiler ( ) ; if ( ! $ profiler -> getEnabled ( ) ) { return ; } $ infoIndexedByQuery = array ( ) ; foreach ( $ profiler -> getQueryProfiles ( ) as $ query ) { if ( isset ( $ infoIndexedByQuery [ $ query -> getQuery ( ) ] ) ) { $ exis...
Outputs SQL Profiling reports from Zend
24,848
public static function displayDbTrackerProfile ( $ db = null ) { if ( is_null ( $ db ) ) { $ db = Tracker :: getDatabase ( ) ; } $ tableName = Common :: prefixTable ( 'log_profiling' ) ; $ all = $ db -> fetchAll ( 'SELECT * FROM ' . $ tableName ) ; if ( $ all === false ) { return ; } uasort ( $ all , 'self::maxSumMsFir...
Print profiling report for the tracker
24,849
public static function printQueryCount ( ) { $ totalTime = self :: getDbElapsedSecs ( ) ; $ queryCount = Profiler :: getQueryCount ( ) ; if ( $ queryCount > 0 ) { Log :: debug ( sprintf ( "Total queries = %d (total sql time = %.2fs)" , $ queryCount , $ totalTime ) ) ; } }
Print number of queries and elapsed time
24,850
private static function getSqlProfilingQueryBreakdownOutput ( $ infoIndexedByQuery ) { $ output = '<hr /><strong>Breakdown by query</strong><br/>' ; foreach ( $ infoIndexedByQuery as $ query => $ queryInfo ) { $ timeMs = round ( $ queryInfo [ 'sumTimeMs' ] , 1 ) ; $ count = $ queryInfo [ 'count' ] ; $ avgTimeString = '...
Log a breakdown by query
24,851
public function setPattern ( $ pattern ) { $ this -> _pattern = ( string ) $ pattern ; $ status = @ preg_match ( $ this -> _pattern , "Test" ) ; if ( false === $ status ) { throw new Zend_Validate_Exception ( "Internal error while using the pattern '$this->_pattern'" ) ; } return $ this ; }
Sets the pattern option
24,852
public static function canBeEnabled ( ) { $ isEnabled = ( bool ) Config :: getInstance ( ) -> General [ 'enable_update_communication' ] ; if ( $ isEnabled === true && Marketplace :: isMarketplaceEnabled ( ) === true && SettingsPiwik :: isInternetEnabled ( ) === true ) { return true ; } return false ; }
Checks whether a plugin update notification can be enabled or not . It cannot be enabled if for instance the Marketplace is disabled or if update notifications are disabled in general .
24,853
public function sendNotificationIfUpdatesAvailable ( ) { $ pluginsHavingUpdate = $ this -> getPluginsHavingUpdate ( ) ; if ( empty ( $ pluginsHavingUpdate ) ) { return ; } $ pluginsToBeNotified = array ( ) ; foreach ( $ pluginsHavingUpdate as $ plugin ) { if ( $ this -> hasNotificationAlreadyReceived ( $ plugin ) ) { c...
Sends an email to all super users if there is an update available for any plugins from the Marketplace . For each update we send an email only once .
24,854
public function request ( $ request , $ multiline = false ) { $ this -> sendRequest ( $ request ) ; return $ this -> readResponse ( $ multiline ) ; }
Send request and get resposne
24,855
public function status ( & $ messages , & $ octets ) { $ messages = 0 ; $ octets = 0 ; $ result = $ this -> request ( 'STAT' ) ; list ( $ messages , $ octets ) = explode ( ' ' , $ result ) ; }
Make STAT call for message count and size sum
24,856
public function uniqueid ( $ msgno = null ) { if ( $ msgno !== null ) { $ result = $ this -> request ( "UIDL $msgno" ) ; list ( , $ result ) = explode ( ' ' , $ result ) ; return $ result ; } $ result = $ this -> request ( 'UIDL' , true ) ; $ result = explode ( "\n" , $ result ) ; $ messages = array ( ) ; foreach ( $ r...
Make UIDL call for getting a uniqueid
24,857
public function top ( $ msgno , $ lines = 0 , $ fallback = false ) { if ( $ this -> hasTop === false ) { if ( $ fallback ) { return $ this -> retrieve ( $ msgno ) ; } else { throw new Zend_Mail_Protocol_Exception ( 'top not supported and no fallback wanted' ) ; } } $ this -> hasTop = true ; $ lines = ( ! $ lines || $ l...
Make TOP call for getting headers and maybe some body lines This method also sets hasTop - before it it s not known if top is supported
24,858
protected function getConfigHash ( Request $ request , $ 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 ) { $ sal...
Returns a 64 - bit hash that attemps to identify a user . Maintaining some privacy by default eg . prevents the merging of several Piwik serve together for matching across instances ..
24,859
protected static function _normalizeName ( $ name ) { $ name = ucfirst ( strtolower ( $ name ) ) ; $ name = str_replace ( array ( '-' , '_' , '.' ) , ' ' , $ name ) ; $ name = ucwords ( $ name ) ; $ name = str_replace ( ' ' , '' , $ name ) ; if ( stripos ( $ name , 'ZendServer' ) === 0 ) { $ name = 'ZendServer_' . subs...
Normalize frontend and backend names to allow multiple words TitleCased
24,860
public function connect ( $ host , $ port = null , $ ssl = false ) { if ( $ ssl == 'SSL' ) { $ host = 'ssl://' . $ host ; } if ( $ port === null ) { $ port = $ ssl === 'SSL' ? 993 : 143 ; } $ errno = 0 ; $ errstr = '' ; $ this -> _socket = @ fsockopen ( $ host , $ port , $ errno , $ errstr , self :: TIMEOUT_CONNECTION ...
Open connection to IMAP server
24,861
protected function _nextTaggedLine ( & $ tag ) { $ line = $ this -> _nextLine ( ) ; list ( $ tag , $ line ) = explode ( ' ' , $ line , 2 ) ; return $ line ; }
get next line and split the tag . that s the normal case for a response line
24,862
public function sendRequest ( $ command , $ tokens = array ( ) , & $ tag = null ) { if ( ! $ tag ) { ++ $ this -> _tagCount ; $ tag = 'TAG' . $ this -> _tagCount ; } $ line = $ tag . ' ' . $ command ; foreach ( $ tokens as $ token ) { if ( is_array ( $ token ) ) { if ( @ fputs ( $ this -> _socket , $ line . ' ' . $ tok...
send a request
24,863
public function requestAndResponse ( $ command , $ tokens = array ( ) , $ dontParse = false ) { $ this -> sendRequest ( $ command , $ tokens , $ tag ) ; $ response = $ this -> readResponse ( $ tag , $ dontParse ) ; return $ response ; }
send a request and get response at once
24,864
public function escapeString ( $ string ) { if ( func_num_args ( ) < 2 ) { if ( strpos ( $ string , "\n" ) !== false ) { return array ( '{' . strlen ( $ string ) . '}' , $ string ) ; } else { return '"' . str_replace ( array ( '\\' , '"' ) , array ( '\\\\' , '\\"' ) , $ string ) . '"' ; } } $ result = array ( ) ; forea...
escape one or more literals i . e . for sendRequest
24,865
public function login ( $ user , $ password ) { return $ this -> requestAndResponse ( 'LOGIN' , $ this -> escapeString ( $ user , $ password ) , true ) ; }
Login to IMAP server .
24,866
public function capability ( ) { $ response = $ this -> requestAndResponse ( 'CAPABILITY' ) ; if ( ! $ response ) { return $ response ; } $ capabilities = array ( ) ; foreach ( $ response as $ line ) { $ capabilities = array_merge ( $ capabilities , $ line ) ; } return $ capabilities ; }
Get capabilities from IMAP server
24,867
public function examineOrSelect ( $ command = 'EXAMINE' , $ box = 'INBOX' ) { $ this -> sendRequest ( $ command , array ( $ this -> escapeString ( $ box ) ) , $ tag ) ; $ result = array ( ) ; while ( ! $ this -> readLine ( $ tokens , $ tag ) ) { if ( $ tokens [ 0 ] == 'FLAGS' ) { array_shift ( $ tokens ) ; $ result [ '...
Examine and select have the same response . The common code for both is in this method
24,868
public function fetch ( $ items , $ from , $ to = null ) { if ( is_array ( $ from ) ) { $ set = implode ( ',' , $ from ) ; } else if ( $ to === null ) { $ set = ( int ) $ from ; } else if ( $ to === INF ) { $ set = ( int ) $ from . ':*' ; } else { $ set = ( int ) $ from . ':' . ( int ) $ to ; } $ items = ( array ) $ it...
fetch one or more items of one or more messages
24,869
public function listMailbox ( $ reference = '' , $ mailbox = '*' ) { $ result = array ( ) ; $ list = $ this -> requestAndResponse ( 'LIST' , $ this -> escapeString ( $ reference , $ mailbox ) ) ; if ( ! $ list || $ list === true ) { return $ result ; } foreach ( $ list as $ item ) { if ( count ( $ item ) != 4 || $ item...
get mailbox list
24,870
public function append ( $ folder , $ message , $ flags = null , $ date = null ) { $ tokens = array ( ) ; $ tokens [ ] = $ this -> escapeString ( $ folder ) ; if ( $ flags !== null ) { $ tokens [ ] = $ this -> escapeList ( $ flags ) ; } if ( $ date !== null ) { $ tokens [ ] = $ this -> escapeString ( $ date ) ; } $ tok...
append a new message to given folder
24,871
public function copy ( $ folder , $ from , $ to = null ) { $ set = ( int ) $ from ; if ( $ to != null ) { $ set .= ':' . ( $ to == INF ? '*' : ( int ) $ to ) ; } return $ this -> requestAndResponse ( 'COPY' , array ( $ set , $ this -> escapeString ( $ folder ) ) , true ) ; }
copy message set from current folder to other folder
24,872
public function search ( array $ params ) { $ response = $ this -> requestAndResponse ( 'SEARCH' , $ params ) ; if ( ! $ response ) { return $ response ; } foreach ( $ response as $ ids ) { if ( $ ids [ 0 ] == 'SEARCH' ) { array_shift ( $ ids ) ; return $ ids ; } } return array ( ) ; }
do a search request
24,873
public function reloadAccess ( Auth $ auth = null ) { $ this -> resetSites ( ) ; if ( isset ( $ auth ) ) { $ this -> auth = $ auth ; } if ( $ this -> hasSuperUserAccess ( ) ) { $ this -> makeSureLoginNameIsSet ( ) ; return true ; } $ this -> token_auth = null ; $ this -> login = null ; if ( ! isset ( $ this -> auth ) )...
Loads the access levels for the current user .
24,874
public static function getSqlAccessSite ( $ select ) { $ access = Common :: prefixTable ( 'access' ) ; $ siteTable = Common :: prefixTable ( 'site' ) ; return "SELECT " . $ select . " FROM " . $ access . " as t1 JOIN " . $ siteTable . " as t2 USING (idsite) WHERE login = ?" ; }
Returns the SQL query joining sites and access table for a given login
24,875
public function setSuperUserAccess ( $ bool = true ) { $ this -> hasSuperUserAccess = ( bool ) $ bool ; if ( $ bool ) { $ this -> makeSureLoginNameIsSet ( ) ; } else { $ this -> resetSites ( ) ; } }
We bypass the normal auth method and give the current user Super User rights . This should be very carefully used .
24,876
public function getSitesIdWithAtLeastViewAccess ( ) { $ this -> loadSitesIfNeeded ( ) ; return array_unique ( array_merge ( $ this -> idsitesByAccess [ 'view' ] , $ this -> idsitesByAccess [ 'write' ] , $ this -> idsitesByAccess [ 'admin' ] , $ this -> idsitesByAccess [ 'superuser' ] ) ) ; }
Returns an array of ID sites for which the user has at least a VIEW access . Which means VIEW OR WRITE or ADMIN or SUPERUSER .
24,877
public function getSitesIdWithAtLeastWriteAccess ( ) { $ this -> loadSitesIfNeeded ( ) ; return array_unique ( array_merge ( $ this -> idsitesByAccess [ 'write' ] , $ this -> idsitesByAccess [ 'admin' ] , $ this -> idsitesByAccess [ 'superuser' ] ) ) ; }
Returns an array of ID sites for which the user has at least a WRITE access . Which means WRITE or ADMIN or SUPERUSER .
24,878
public function checkUserHasSomeViewAccess ( ) { if ( $ this -> hasSuperUserAccess ( ) ) { return ; } $ idSitesAccessible = $ this -> getSitesIdWithAtLeastViewAccess ( ) ; if ( count ( $ idSitesAccessible ) == 0 ) { throw new NoAccessException ( Piwik :: translate ( 'General_ExceptionPrivilegeAtLeastOneWebsite' , array...
If the user doesn t have any view permission throw exception
24,879
public function checkUserHasAdminAccess ( $ idSites ) { if ( $ this -> hasSuperUserAccess ( ) ) { return ; } $ idSites = $ this -> getIdSites ( $ idSites ) ; $ idSitesAccessible = $ this -> getSitesIdWithAdminAccess ( ) ; foreach ( $ idSites as $ idsite ) { if ( ! in_array ( $ idsite , $ idSitesAccessible ) ) { throw n...
This method checks that the user has ADMIN access for the given list of websites . If the user doesn t have ADMIN access for at least one website of the list we throw an exception .
24,880
public static function doAsSuperUser ( $ function ) { $ isSuperUser = self :: getInstance ( ) -> hasSuperUserAccess ( ) ; $ access = self :: getInstance ( ) ; $ login = $ access -> getLogin ( ) ; $ shouldResetLogin = empty ( $ login ) ; $ access -> setSuperUserAccess ( true ) ; try { $ result = $ function ( ) ; } catch...
Executes a callback with superuser privileges making sure those privileges are rescinded before this method exits . Privileges will be rescinded even if an exception is thrown .
24,881
public function getRoleForSite ( $ idSite ) { if ( $ this -> hasSuperUserAccess || in_array ( $ idSite , $ this -> getSitesIdWithAdminAccess ( ) ) ) { return 'admin' ; } if ( in_array ( $ idSite , $ this -> getSitesIdWithWriteAccess ( ) ) ) { return 'write' ; } if ( in_array ( $ idSite , $ this -> getSitesIdWithViewAcc...
Returns the level of access the current user has to the given site .
24,882
public function getCapabilitiesForSite ( $ idSite ) { $ result = [ ] ; foreach ( $ this -> capabilityProvider -> getAllCapabilityIds ( ) as $ capabilityId ) { if ( empty ( $ this -> idsitesByAccess [ $ capabilityId ] ) ) { continue ; } if ( in_array ( $ idSite , $ this -> idsitesByAccess [ $ capabilityId ] ) ) { $ resu...
Returns the capabilities the current user has for a given site .
24,883
final public static function factory ( $ type ) { $ type = strtolower ( $ type ) ; if ( ! isset ( self :: $ _types [ $ type ] ) ) { throw new HTML_QuickForm2_InvalidArgumentException ( "Renderer type '$type' is not known" ) ; } list ( $ className , $ includeFile ) = self :: $ _types [ $ type ] ; if ( ! class_exists ( $...
Creates a new renderer instance of the given type
24,884
final public static function register ( $ type , $ className , $ includeFile = null ) { $ type = strtolower ( $ type ) ; if ( ! empty ( self :: $ _types [ $ type ] ) ) { throw new HTML_QuickForm2_InvalidArgumentException ( "Renderer type '$type' is already registered" ) ; } self :: $ _types [ $ type ] = array ( $ class...
Registers a new renderer type
24,885
final public static function registerPlugin ( $ type , $ className , $ includeFile = null ) { $ type = strtolower ( $ type ) ; if ( empty ( self :: $ _pluginClasses [ $ type ] ) ) { self :: $ _pluginClasses [ $ type ] = array ( array ( $ className , $ includeFile ) ) ; } else { foreach ( self :: $ _pluginClasses [ $ ty...
Registers a plugin for a renderer type
24,886
public function getJavascriptBuilder ( ) { if ( empty ( $ this -> jsBuilder ) ) { if ( ! class_exists ( 'HTML_QuickForm2_JavascriptBuilder' ) ) { HTML_QuickForm2_Loader :: loadClass ( 'HTML_QuickForm2_JavascriptBuilder' ) ; } $ this -> jsBuilder = new HTML_QuickForm2_JavascriptBuilder ( ) ; } return $ this -> jsBuilder...
Returns the javascript builder object
24,887
protected function _setup ( ) { parent :: _setup ( ) ; $ this -> _setupPrimaryAssignment ( ) ; $ this -> setLifetime ( $ this -> _lifetime ) ; $ this -> _checkRequiredColumns ( ) ; }
Calls other protected methods for individual setup tasks and requirement checks
24,888
protected function _setupTableName ( ) { if ( empty ( $ this -> _name ) && basename ( ( $ this -> _name = session_save_path ( ) ) ) != $ this -> _name ) { throw new Zend_Session_SaveHandler_Exception ( 'session.save_path is a path and not a table name.' ) ; } if ( strpos ( $ this -> _name , '.' ) ) { list ( $ this -> _...
Initialize table and schema names
24,889
protected function _checkRequiredColumns ( ) { if ( $ this -> _modifiedColumn === null ) { throw new Zend_Session_SaveHandler_Exception ( "Configuration must define '" . self :: MODIFIED_COLUMN . "' which names the " . "session table last modification time column." ) ; } else if ( $ this -> _lifetimeColumn === null ) {...
Check for required session table columns
24,890
protected function _getPrimary ( $ id , $ type = null ) { $ this -> _setupPrimaryKey ( ) ; if ( $ type === null ) { $ type = self :: PRIMARY_TYPE_NUM ; } $ primaryArray = array ( ) ; foreach ( $ this -> _primary as $ index => $ primary ) { switch ( $ this -> _primaryAssignment [ $ index ] ) { case self :: PRIMARY_ASSIG...
Retrieve session table primary key values
24,891
private function _prepareData ( $ data , $ lifetime , $ priority ) { $ lt = $ lifetime ; if ( $ lt === null ) { $ lt = 9999999999 ; } return serialize ( array ( 'data' => $ data , 'lifetime' => $ lifetime , 'expire' => time ( ) + $ lt , 'priority' => $ priority ) ) ; }
Prepare a serialized array to store datas and metadatas informations
24,892
private function _getFastLifetime ( $ lifetime , $ priority , $ maxLifetime = null ) { if ( $ lifetime <= 0 ) { $ fastLifetime = ( int ) ( 2592000 / ( 11 - $ priority ) ) ; } else { $ fastLifetime = ( int ) ceil ( $ lifetime / ( 11 - $ priority ) ) ; } if ( $ maxLifetime >= 0 && $ fastLifetime > $ maxLifetime ) { retur...
Compute and return the lifetime for the fast backend
24,893
public function checkAtLeastOneUrl ( $ urls ) { $ urls = $ this -> cleanParameterUrls ( $ urls ) ; if ( ! is_array ( $ urls ) || count ( $ urls ) == 0 ) { throw new Exception ( Piwik :: translate ( 'SitesManager_ExceptionNoUrl' ) ) ; } }
Checks that the array has at least one element
24,894
public function checkUrls ( $ urls ) { $ urls = $ this -> cleanParameterUrls ( $ urls ) ; foreach ( $ urls as $ url ) { if ( ! UrlHelper :: isLookLikeUrl ( $ url ) ) { throw new Exception ( sprintf ( Piwik :: translate ( 'SitesManager_ExceptionInvalidUrl' ) , $ url ) ) ; } } }
Check that the array of URLs are valid URLs
24,895
public function getAllSegmentsAndIgnoreVisibility ( ) { $ cacheKey = 'SegmentEditor.getAllSegmentsAndIgnoreVisibility' ; if ( ! $ this -> transientCache -> contains ( $ cacheKey ) ) { $ result = $ this -> model -> getAllSegmentsAndIgnoreVisibility ( ) ; $ this -> transientCache -> save ( $ cacheKey , $ result ) ; } ret...
Returns all stored segments that haven t been deleted .
24,896
protected function aggregateByPlugin ( ) { $ selects = array ( ) ; $ columns = DevicePlugins :: getAllPluginColumns ( ) ; foreach ( $ columns as $ column ) { $ selects [ ] = sprintf ( "sum(case log_visit.%s when 1 then 1 else 0 end) as %s" , $ column -> getColumnName ( ) , substr ( $ column -> getColumnName ( ) , 7 ) )...
Archives reports for all available plugin columns
24,897
private function getGeoIpInstance ( $ key ) { if ( empty ( $ this -> readerCache [ $ key ] ) ) { $ pathToDb = self :: getPathToGeoIpDatabase ( $ this -> customDbNames [ $ key ] ) ; if ( $ pathToDb !== false ) { try { $ this -> readerCache [ $ key ] = new Reader ( $ pathToDb ) ; } catch ( InvalidDatabaseException $ e ) ...
Returns a GeoIP2 reader instance . Creates it if necessary .
24,898
public static function setBasicVariablesAdminView ( View $ view ) { self :: notifyWhenTrackingStatisticsDisabled ( ) ; self :: notifyIfEAcceleratorIsUsed ( ) ; self :: notifyIfURLIsNotSecure ( ) ; $ view -> topMenu = MenuTop :: getInstance ( ) -> getMenu ( ) ; $ view -> isDataPurgeSettingsEnabled = self :: isDataPurgeS...
Assigns view properties that would be useful to views that render admin pages .
24,899
public function getMetricsRequiredForReport ( $ allMetrics = null , $ restrictToColumns = null ) { if ( empty ( $ allMetrics ) ) { $ allMetrics = $ this -> metrics ; } if ( empty ( $ restrictToColumns ) ) { $ restrictToColumns = array_merge ( $ allMetrics , array_keys ( $ this -> getProcessedMetrics ( ) ) ) ; } $ restr...
Returns the list of metrics required at minimum for a report factoring in the columns requested by the report requester .