idx int64 0 60.3k | question stringlengths 99 4.85k | target stringlengths 5 718 |
|---|---|---|
2,600 | public function getApplication ( $ key ) { if ( empty ( $ key ) ) { return null ; } if ( array_key_exists ( $ key , $ this -> applications ) ) { return $ this -> applications [ $ key ] ; } return null ; } | Returns a server application . |
2,601 | protected function configureConnectionManager ( ) : void { if ( $ this -> options [ 'connection_manager' ] ) { $ this -> connectionManager = $ this -> options [ 'connection_manager' ] ; } else { $ class = $ this -> options [ 'connection_manager_class' ] ; $ options = $ this -> options [ 'connection_manager_options' ] ;... | Configures the connection manager |
2,602 | public function validateUri ( $ uri ) { $ uri = ( string ) $ uri ; if ( ! $ uri ) { throw new InvalidArgumentException ( 'Invalid URI' ) ; } $ scheme = parse_url ( $ uri , PHP_URL_SCHEME ) ; $ this -> validateScheme ( $ scheme ) ; $ host = parse_url ( $ uri , PHP_URL_HOST ) ; if ( ! $ host ) { throw new InvalidArgument... | Validates a WebSocket URI |
2,603 | protected function validateScheme ( $ scheme ) { if ( ! $ scheme ) { throw new InvalidArgumentException ( 'No scheme specified' ) ; } if ( ! in_array ( $ scheme , self :: $ schemes ) ) { throw new InvalidArgumentException ( 'Unknown socket scheme: ' . $ scheme ) ; } if ( $ scheme == self :: SCHEME_WEBSOCKET_SECURE ) { ... | Validates a scheme |
2,604 | protected function getPort ( $ scheme ) { if ( $ scheme == self :: SCHEME_WEBSOCKET ) { return 80 ; } elseif ( $ scheme == self :: SCHEME_WEBSOCKET_SECURE ) { return 443 ; } elseif ( $ scheme == self :: SCHEME_UNDERLYING ) { return 80 ; } elseif ( $ scheme == self :: SCHEME_UNDERLYING_SECURE ) { return 443 ; } else { t... | Gets the default port for a scheme By default the WebSocket Protocol uses port 80 for regular WebSocket connections and port 443 for WebSocket connections tunneled over Transport Layer Security |
2,605 | protected function getDefaultRequestHeaders ( $ host , $ key , $ origin ) { return [ self :: HEADER_HOST => $ host , self :: HEADER_UPGRADE => self :: UPGRADE_VALUE , self :: HEADER_CONNECTION => self :: CONNECTION_VALUE , self :: HEADER_KEY => $ key , self :: HEADER_ORIGIN => $ origin , self :: HEADER_VERSION => $ thi... | Gets the default request headers |
2,606 | public function getResponseHandshake ( $ key , array $ headers = [ ] ) { $ headers = array_merge ( $ this -> getSuccessResponseHeaders ( $ key ) , $ headers ) ; return $ this -> getHttpResponse ( self :: HTTP_SWITCHING_PROTOCOLS , $ headers ) ; } | Gets a handshake response body |
2,607 | protected function getSuccessResponseHeaders ( $ key ) { return [ self :: HEADER_UPGRADE => self :: UPGRADE_VALUE , self :: HEADER_CONNECTION => self :: CONNECTION_VALUE , self :: HEADER_ACCEPT => $ this -> getAcceptValue ( $ key ) , ] ; } | Gets the default response headers |
2,608 | protected function getHttpResponse ( $ status , array $ headers = [ ] ) { if ( array_key_exists ( $ status , self :: HTTP_RESPONSES ) ) { $ response = self :: HTTP_RESPONSES [ $ status ] ; } else { $ response = self :: HTTP_RESPONSES [ self :: HTTP_NOT_IMPLEMENTED ] ; } $ handshake = [ sprintf ( self :: RESPONSE_LINE_F... | Gets an HTTP response |
2,609 | public function getResponseError ( $ e , array $ headers = [ ] ) { $ code = false ; if ( $ e instanceof Exception ) { $ code = $ e -> getCode ( ) ; } elseif ( is_numeric ( $ e ) ) { $ code = ( int ) $ e ; } if ( ! $ code || $ code < 400 || $ code > 599 ) { $ code = self :: HTTP_SERVER_ERROR ; } return $ this -> getHttp... | Gets a response to an error in the handshake |
2,610 | protected function getHeaders ( $ response , & $ request_line = null ) { $ parts = explode ( "\r\n\r\n" , $ response , 2 ) ; if ( count ( $ parts ) < 2 ) { $ parts [ ] = '' ; } list ( $ headers , $ body ) = $ parts ; $ return = [ ] ; foreach ( explode ( "\r\n" , $ headers ) as $ header ) { $ parts = explode ( ': ' , $ ... | Gets the headers from a full response |
2,611 | protected function getRequestHeaders ( $ response ) { $ eol = stripos ( $ response , "\r\n" ) ; if ( $ eol === false ) { throw new InvalidArgumentException ( 'Invalid request line' ) ; } $ request = substr ( $ response , 0 , $ eol ) ; $ headers = $ this -> getHeaders ( substr ( $ response , $ eol + 2 ) ) ; return [ $ r... | Gets request headers |
2,612 | protected function validateRequestLine ( $ line ) { $ matches = [ 0 => null , 1 => null ] ; if ( ! preg_match ( self :: REQUEST_LINE_REGEX , $ line , $ matches ) || ! $ matches [ 1 ] ) { throw new BadRequestException ( 'Invalid request line' , 400 ) ; } return $ matches [ 1 ] ; } | Validates a request line |
2,613 | public function getClosePayload ( $ e , $ masked = true ) { $ code = false ; if ( $ e instanceof Exception ) { $ code = $ e -> getCode ( ) ; } elseif ( is_numeric ( $ e ) ) { $ code = ( int ) $ e ; } if ( ! $ code || ! key_exists ( $ code , self :: CLOSE_REASONS ) ) { $ code = self :: CLOSE_UNEXPECTED ; } $ body = pack... | Gets a suitable WebSocket close frame . Please set masked to false if you send a close frame from server side . |
2,614 | public function validateSocketUri ( $ uri ) { $ uri = ( string ) $ uri ; if ( ! $ uri ) { throw new InvalidArgumentException ( 'Invalid URI' ) ; } $ scheme = parse_url ( $ uri , PHP_URL_SCHEME ) ; $ scheme = $ this -> validateScheme ( $ scheme ) ; $ host = parse_url ( $ uri , PHP_URL_HOST ) ; if ( ! $ host ) { throw ne... | Validates a socket URI |
2,615 | public function validateOriginUri ( $ origin ) { $ origin = ( string ) $ origin ; if ( ! $ origin ) { throw new InvalidArgumentException ( 'Invalid URI' ) ; } $ scheme = parse_url ( $ origin , PHP_URL_SCHEME ) ; if ( ! $ scheme ) { throw new InvalidArgumentException ( 'Invalid scheme' ) ; } $ host = parse_url ( $ origi... | Validates an origin URI |
2,616 | protected function configureSocket ( ) { $ class = $ this -> options [ 'socket_class' ] ; $ options = $ this -> options [ 'socket_options' ] ; $ this -> socket = new $ class ( $ this -> uri , $ options ) ; } | Configures the client socket |
2,617 | public function sendData ( string $ data , int $ type = Protocol :: TYPE_TEXT , $ masked = true ) { if ( ! $ this -> isConnected ( ) ) { return false ; } $ payload = $ this -> protocol -> getPayload ( ) ; $ payload -> encode ( $ data , $ type , $ masked ) ; return $ payload -> sendToSocket ( $ this -> socket ) ; } | Sends data to the socket |
2,618 | public function isConnected ( ) { if ( $ this -> connected === false ) { return false ; } if ( $ this -> socket -> isConnected ( ) === false ) { $ this -> connected = false ; return false ; } return true ; } | Returns whether the client is currently connected Also checks the state of the underlying socket |
2,619 | public function receive ( ) : ? array { if ( ! $ this -> isConnected ( ) ) { return null ; } $ data = $ this -> socket -> receive ( ) ; if ( ! $ data ) { return [ ] ; } $ this -> payloadHandler -> handle ( $ data ) ; $ received = $ this -> received ; $ this -> received = [ ] ; return $ received ; } | Receives data sent by the server |
2,620 | public function connect ( ) : bool { if ( $ this -> isConnected ( ) ) { return false ; } try { $ this -> socket -> connect ( ) ; } catch ( \ Exception $ ex ) { return false ; } $ key = $ this -> protocol -> generateKey ( ) ; $ handshake = $ this -> protocol -> getRequestHandshake ( $ this -> uri , $ key , $ this -> ori... | Connect to the server |
2,621 | public function disconnect ( $ reason = Protocol :: CLOSE_NORMAL ) : bool { if ( $ this -> connected === false ) { return false ; } $ payload = $ this -> protocol -> getClosePayload ( $ reason ) ; if ( $ this -> socket ) { if ( ! $ payload -> sendToSocket ( $ this -> socket ) ) { throw new FrameException ( "Unexpected ... | Disconnects the underlying socket and marks the client as disconnected |
2,622 | public function encode ( $ payload , $ type = Protocol :: TYPE_TEXT , $ masked = false ) { if ( ! is_int ( $ type ) || ! in_array ( $ type , Protocol :: FRAME_TYPES ) ) { throw new InvalidArgumentException ( 'Invalid frame type' ) ; } $ this -> type = $ type ; $ this -> masked = $ masked ; $ this -> payload = $ payload... | Encode a frame |
2,623 | protected function generateMask ( ) { if ( extension_loaded ( 'openssl' ) ) { return openssl_random_pseudo_bytes ( 4 ) ; } else { return pack ( 'N' , sha1 ( spl_object_hash ( $ this ) . mt_rand ( 0 , PHP_INT_MAX ) . uniqid ( '' , true ) , true ) ) ; } } | Generates a suitable masking key |
2,624 | protected function getMask ( ) { if ( ! isset ( $ this -> mask ) ) { if ( ! $ this -> isMasked ( ) ) { throw new FrameException ( 'Cannot get mask: frame is not masked' ) ; } $ this -> mask = substr ( $ this -> buffer , $ this -> getMaskOffset ( ) , $ this -> getMaskSize ( ) ) ; } return $ this -> mask ; } | Gets the mask |
2,625 | public function isMasked ( ) { if ( ! isset ( $ this -> masked ) ) { if ( ! isset ( $ this -> buffer [ 1 ] ) ) { throw new FrameException ( 'Cannot tell if frame is masked: not enough frame data received' ) ; } $ this -> masked = ( boolean ) ( ord ( $ this -> buffer [ 1 ] ) & self :: BITFIELD_MASKED ) ; } return $ this... | Whether the frame is masked |
2,626 | protected function getMaskOffset ( ) { if ( ! isset ( $ this -> offset_mask ) ) { $ offset = self :: BYTE_INITIAL_LENGTH + 1 ; $ offset += $ this -> getLengthSize ( ) ; $ this -> offset_mask = $ offset ; } return $ this -> offset_mask ; } | Gets the offset in the frame to the masking bytes |
2,627 | protected function getInitialLength ( ) { if ( ! isset ( $ this -> buffer [ self :: BYTE_INITIAL_LENGTH ] ) ) { throw new FrameException ( 'Cannot yet tell expected length' ) ; } $ a = ( int ) ( ord ( $ this -> buffer [ self :: BYTE_INITIAL_LENGTH ] ) & self :: BITFIELD_INITIAL_LENGTH ) ; return ( int ) ( ord ( $ this ... | Gets the inital length value stored in the first length byte This determines how the rest of the length value is parsed out of the frame . |
2,628 | protected function getPayloadOffset ( ) { if ( ! isset ( $ this -> offset_payload ) ) { $ offset = $ this -> getMaskOffset ( ) ; $ offset += $ this -> getMaskSize ( ) ; $ this -> offset_payload = $ offset ; } return $ this -> offset_payload ; } | Gets the offset of the payload in the frame |
2,629 | public static function generatePemFile ( $ pem_file , $ pem_passphrase , $ country_name , $ state_or_province_name , $ locality_name , $ organization_name , $ organizational_unit_name , $ common_name , $ email_address ) : void { $ dn = [ 'countryName' => $ country_name , 'stateOrProvinceName' => $ state_or_province_nam... | Generates a new PEM File given the information |
2,630 | public function handle ( string $ data ) { if ( ! $ this -> payload ) { $ this -> payload = $ this -> protocol -> getPayload ( ) ; } while ( $ data ) { $ size = strlen ( $ data ) ; $ remaining = $ this -> payload -> getRemainingData ( ) ; if ( $ remaining === null ) { $ chunkSize = 2 ; } elseif ( $ remaining > 0 ) { $ ... | Handles the raw socket data given |
2,631 | public function getFramePayload ( ) { if ( ! $ this -> isComplete ( ) ) { throw new FrameException ( 'Cannot get payload: frame is not complete' ) ; } if ( ! $ this -> payload && $ this -> buffer ) { $ this -> decodeFramePayloadFromBuffer ( ) ; } return $ this -> payload ; } | Gets the contents of the frame payload The frame must be complete to call this method . |
2,632 | public function isComplete ( ) { if ( ! $ this -> buffer ) { return false ; } try { return $ this -> getBufferLength ( ) >= $ this -> getExpectedBufferLength ( ) ; } catch ( FrameException $ e ) { return false ; } } | Whether the frame is complete |
2,633 | public function connect ( ) : bool { if ( $ this -> isConnected ( ) ) { return true ; } $ errno = null ; $ errstr = null ; $ this -> socket = @ stream_socket_client ( $ this -> getUri ( ) , $ errno , $ errstr , $ this -> options [ 'timeout_connect' ] , STREAM_CLIENT_CONNECT , $ this -> getStreamContext ( ) ) ; if ( ! $... | Connects to the given socket |
2,634 | protected function configure ( array $ options ) : void { $ options = array_merge ( [ 'timeout_connect' => self :: TIMEOUT_CONNECT , 'ssl_verify_peer' => false , 'ssl_allow_self_signed' => true , ] , $ options ) ; parent :: configure ( $ options ) ; } | Configure the client socket |
2,635 | protected function limit ( $ connection , $ limit ) { $ this -> logger -> notice ( sprintf ( 'Limiting connection %s: %s' , $ connection -> getIp ( ) , $ limit ) ) ; $ connection -> close ( new RateLimiterException ( $ limit ) ) ; } | Limits the given connection |
2,636 | protected function checkConnectionsPerIp ( $ connection ) { $ ip = $ connection -> getIp ( ) ; if ( ! $ ip ) { $ this -> logger -> warning ( 'Cannot check connections per IP' ) ; return ; } if ( ! isset ( $ this -> ips [ $ ip ] ) ) { $ this -> ips [ $ ip ] = 1 ; } else { $ this -> ips [ $ ip ] = min ( $ this -> options... | NOT idempotent call once per connection |
2,637 | protected function releaseConnection ( Connection $ connection ) : void { $ ip = $ connection -> getIp ( ) ; if ( ! $ ip ) { $ this -> logger -> warning ( 'Cannot release connection' ) ; return ; } if ( ! isset ( $ this -> ips [ $ ip ] ) ) { $ this -> ips [ $ ip ] = 0 ; } else { $ this -> ips [ $ ip ] = max ( 0 , $ thi... | NOT idempotent call once per disconnection |
2,638 | protected function checkRequestsPerMinute ( Connection $ connection ) { $ id = $ connection -> getId ( ) ; if ( ! isset ( $ this -> requests [ $ id ] ) ) { $ this -> requests [ $ id ] = [ ] ; } $ this -> requests [ $ id ] [ ] = time ( ) ; while ( reset ( $ this -> requests [ $ id ] ) < time ( ) - 60 ) { array_shift ( $... | NOT idempotent call once per data |
2,639 | public function accept ( ) { $ new = stream_socket_accept ( $ this -> socket , $ this -> options [ 'timeout_accept' ] ) ; if ( ! $ new ) { throw new ConnectionException ( socket_strerror ( socket_last_error ( $ new ) ) ) ; } socket_set_option ( socket_import_stream ( $ new ) , SOL_TCP , TCP_NODELAY , 1 ) ; return $ new... | Accepts a new connection on the socket |
2,640 | protected function configure ( array $ options ) : void { $ options = array_merge ( [ 'backlog' => 50 , 'ssl_cert_file' => null , 'ssl_passphrase' => null , 'ssl_allow_self_signed' => false , 'timeout_accept' => self :: TIMEOUT_ACCEPT , ] , $ options ) ; parent :: configure ( $ options ) ; } | Configure the server socket |
2,641 | public function listen ( ) : void { $ this -> socket -> listen ( ) ; $ this -> resources [ $ this -> socket -> getResourceId ( ) ] = $ this -> socket -> getResource ( ) ; } | Listens on the main socket |
2,642 | public function selectAndProcess ( ) : void { $ read = $ this -> resources ; $ unused_write = null ; $ unsued_exception = null ; stream_select ( $ read , $ unused_write , $ unused_exception , $ this -> options [ 'timeout_select' ] , $ this -> options [ 'timeout_select_microsec' ] ) ; foreach ( $ read as $ socket ) { if... | Select and process an array of resources |
2,643 | protected function processClientSocket ( $ socket ) : void { $ connection = $ this -> getConnectionForClientSocket ( $ socket ) ; if ( ! $ connection ) { $ this -> logger -> warning ( 'No connection for client socket' ) ; return ; } try { $ this -> server -> notify ( Server :: EVENT_CLIENT_DATA , [ $ socket , $ connect... | Process events on a client socket |
2,644 | protected function getConnectionForClientSocket ( $ socket ) : ? Connection { if ( ! isset ( $ this -> connections [ $ this -> resourceId ( $ socket ) ] ) ) { return null ; } return $ this -> connections [ $ this -> resourceId ( $ socket ) ] ; } | Returns the Connection associated with the specified socket resource |
2,645 | public function removeConnection ( Connection $ connection ) : void { $ socket = $ connection -> getSocket ( ) ; if ( $ socket -> getResource ( ) ) { $ index = $ socket -> getResourceId ( ) ; } else { $ index = array_search ( $ connection , $ this -> connections ) ; } if ( ! $ index ) { $ this -> logger -> warning ( 'C... | Removes a connection |
2,646 | protected function configureMasterSocket ( ) : void { $ class = $ this -> options [ 'socket_master_class' ] ; $ options = $ this -> options [ 'socket_master_options' ] ; $ this -> socket = new $ class ( $ this -> server -> getUri ( ) , $ options ) ; } | Configures the main server socket |
2,647 | protected function getAllResources ( ) : array { return array_merge ( $ this -> resources , [ $ this -> socket -> getResourceId ( ) => $ this -> socket -> getResource ( ) , ] ) ; } | Gets all resources |
2,648 | protected function configureOriginPolicy ( ) : void { $ class = $ this -> options [ 'origin_policy_class' ] ; $ this -> originPolicy = new $ class ( $ this -> options [ 'allowed_origins' ] ) ; if ( $ this -> options [ 'check_origin' ] ) { $ this -> originPolicy -> listen ( $ this ) ; } } | Configures the origin policy |
2,649 | protected function configureProtocol ( ) : void { $ protocol = $ this -> options [ 'protocol' ] ; if ( ! $ protocol || ! ( $ protocol instanceof Protocol ) ) { throw new InvalidArgumentException ( 'Invalid protocol option' ) ; } $ this -> protocol = $ protocol ; } | Configures the protocol option |
2,650 | public function requestSetExpressCheckout ( $ amount , $ returnUrl , $ cancelUrl , array $ optionalParameters = array ( ) ) { return $ this -> sendApiRequest ( array_merge ( $ optionalParameters , array ( 'METHOD' => 'SetExpressCheckout' , 'PAYMENTREQUEST_0_AMT' => $ this -> convertAmountToPaypalFormat ( $ amount ) , '... | Initiates an ExpressCheckout payment process . |
2,651 | protected function urlEncodeArray ( array $ encode ) { $ encoded = '' ; foreach ( $ encode as $ name => $ value ) { $ encoded .= '&' . urlencode ( $ name ) . '=' . urlencode ( $ value ) ; } return substr ( $ encoded , 1 ) ; } | A small helper to url - encode an array . |
2,652 | public function request ( Request $ request ) { if ( ! extension_loaded ( 'curl' ) ) { throw new \ RuntimeException ( 'The cURL extension must be loaded.' ) ; } $ curl = curl_init ( ) ; curl_setopt ( $ curl , CURLOPT_SSL_VERIFYHOST , false ) ; curl_setopt ( $ curl , CURLOPT_SSL_VERIFYPEER , false ) ; curl_setopt_array ... | Performs a request to an external payment service . |
2,653 | public static function postInstall ( CommandEvent $ event ) { self :: setInstallPath ( self :: retrieveInstallPath ( ) ) ; require_once self :: getInstallPath ( ) . DIRECTORY_SEPARATOR . 'vendor/autoload.php' ; self :: setExtra ( $ event -> getComposer ( ) -> getPackage ( ) -> getExtra ( ) ) ; \ cli \ Colors :: enable ... | Installer process for project based on post install event hook on composer . |
2,654 | protected static function handleEvent ( CommandEvent $ event ) { $ valid = false ; $ menu1 = array ( 'install' => \ cli \ Colors :: colorize ( '%N%gInstall ' . self :: PROJECT_NAME_SHORT . '%N' ) , 'quit' => \ cli \ Colors :: colorize ( '%N%rQuit %N' ) , ) ; $ menu2 = \ cli \ Colors :: colorize ( '%NInstall to %g' . se... | Handles a received event - dispatcher . |
2,655 | protected static function showSuccess ( ) { \ cli \ line ( ) ; \ cli \ line ( \ cli \ Colors :: colorize ( '%N%n%gInstallation of %y' . self :: PROJECT_NAME_SHORT . '%g was successful.%N%n' ) ) ; return true ; } | Shows the success message after install was successful . |
2,656 | protected static function showFailed ( ) { \ cli \ line ( ) ; \ cli \ line ( \ cli \ Colors :: colorize ( '%N%n%1Installation of ' . self :: PROJECT_NAME_SHORT . ' failed.%N%n' ) ) ; } | Shows the failed message after install failed . |
2,657 | protected static function xcopy ( $ source , $ destination , $ permissions = 0755 ) { if ( is_link ( $ source ) ) { return symlink ( readlink ( $ source ) , $ destination ) ; } if ( is_file ( $ source ) ) { return copy ( $ source , $ destination ) ; } if ( ! is_dir ( $ destination ) ) { mkdir ( $ destination , $ permis... | Copy a file or recursively copy a folder and its contents |
2,658 | protected static function showVersion ( ) { \ cli \ line ( ) ; \ cli \ line ( \ cli \ Colors :: colorize ( '%y+----------------------------------------------------------------------+%N' ) ) ; \ cli \ line ( \ cli \ Colors :: colorize ( '%y| Installer |%N' ) ) ;... | Shows phpMemAdmin version banner . |
2,659 | protected static function initArguments ( CommandEvent $ event = null ) { if ( $ event !== null ) { $ arguments = $ event -> getArguments ( ) ; } else { $ arguments = $ _SERVER [ 'argv' ] ; } $ strict = in_array ( '--strict' , $ arguments ) ; $ arguments = new \ cli \ Arguments ( compact ( 'strict' ) , $ arguments ) ; ... | Retrieve arguments from global to prepare them for further use . |
2,660 | protected static function showHelp ( ) { \ cli \ line ( ) ; \ cli \ out ( self :: $ arguments -> getHelpScreen ( \ cli \ Colors :: colorize ( '%N%n%gAvailable commands:' ) ) ) ; \ cli \ line ( ) ; } | Shows help dialog . |
2,661 | private function localize_beacon ( ) { return array ( 'config' => $ this -> get_config ( $ this -> current_page ) , 'identify' => $ this -> get_identify ( ) , 'suggest' => $ this -> get_suggest ( $ this -> current_page ) , 'type' => $ this -> get_type ( ) , ) ; } | Loads the beacon translations |
2,662 | private function get_translations ( ) { return array ( 'searchLabel' => __ ( 'What can we help you with?' , 'wordpress-seo-premium' ) , 'searchErrorLabel' => __ ( 'Your search timed out. Please double-check your internet connection and try again.' , 'wordpress-seo-premium' ) , 'noResultsLabel' => __ ( 'No results found... | Translates the values for the beacon . The array keys are the names of the translateble strings in the beacon . |
2,663 | private function get_identify ( ) { $ products = $ this -> get_products ( $ this -> current_page ) ; $ cache_key = $ this -> get_cache_key ( $ products ) ; $ identify_data = get_transient ( $ cache_key ) ; if ( ! $ identify_data ) { $ identifier = new Yoast_HelpScout_Beacon_Identifier ( $ this -> get_products ( $ this ... | Retrieve data to populate the beacon email form |
2,664 | private function get_suggest ( $ page ) { $ suggestions = array ( ) ; foreach ( $ this -> settings as $ setting ) { $ suggestions = array_merge ( $ suggestions , $ setting -> get_suggestions ( $ page ) ) ; } return $ suggestions ; } | Returns the suggestions for a certain page or an empty array if there are no suggestions |
2,665 | private function get_products ( $ page ) { $ products = array ( ) ; foreach ( $ this -> settings as $ setting ) { $ products = array_merge ( $ products , $ setting -> get_products ( $ page ) ) ; } return $ products ; } | Returns the products for a certain page or an empty array if there are no products . |
2,666 | private function get_config ( $ page ) { $ config = array ( 'instructions' => $ this -> get_instructions ( ) , 'icon' => 'question' , 'color' => '#A4286A' , 'poweredBy' => false , 'translation' => $ this -> get_translations ( ) , 'showSubject' => true , 'zIndex' => 1000001 , ) ; foreach ( $ this -> settings as $ settin... | Returns the configuration for a certain page |
2,667 | public function get_data ( ) { $ data = array ( 'name' => $ this -> get_user_info ( ) , 'email' => $ this -> get_user_info ( 'email' ) , 'WordPress Version' => $ this -> get_wordpress_version ( ) , 'Server' => $ this -> get_server_info ( ) , '<a href="' . admin_url ( 'themes.php' ) . '">Theme</a>' => $ this -> get_them... | Build data to populate the beacon email form |
2,668 | private function get_server_info ( ) { $ out = '<table>' ; if ( $ ipaddress = filter_input ( INPUT_SERVER , 'SERVER_ADDR' , FILTER_VALIDATE_IP ) ) { $ out .= '<tr><td>IP</td><td>' . $ ipaddress . '</td></tr>' ; $ out .= '<tr><td>Hostname</td><td>' . gethostbyaddr ( $ ipaddress ) . '</td></tr>' ; } if ( function_exists ... | Returns basic info about the server software |
2,669 | private function get_product_info ( Yoast_Product $ product ) { if ( ! class_exists ( 'Yoast_Plugin_License_Manager' ) ) { return 'License manager could not be loaded' ; } $ license_manager = new Yoast_Plugin_License_Manager ( $ product ) ; $ out = '<table>' ; $ out .= '<tr><td>Version</td><td>' . WPSEO_VERSION . '</td... | Returns info about the Yoast SEO plugin version and license |
2,670 | private function get_user_info ( $ what = 'name' ) { $ current_user = wp_get_current_user ( ) ; switch ( $ what ) { case 'email' : $ out = $ current_user -> user_email ; break ; case 'name' : default : $ out = trim ( $ current_user -> user_firstname . ' ' . $ current_user -> user_lastname ) ; break ; } return $ out ; } | Returns info about the current user |
2,671 | private function get_curl_info ( ) { if ( function_exists ( 'curl_version' ) ) { $ curl = curl_version ( ) ; $ msg = $ curl [ 'version' ] ; if ( ! $ curl [ 'features' ] && CURL_VERSION_SSL ) { $ msg .= ' - NO SSL SUPPORT' ; } } else { $ msg = 'No CURL installed' ; } return $ msg ; } | Returns the curl version if curl is found |
2,672 | private function get_theme_info ( ) { $ theme = wp_get_theme ( ) ; $ msg = '<a href="' . $ theme -> display ( 'ThemeURI' ) . '">' . $ theme -> display ( 'Name' ) . '</a> v' . $ theme -> display ( 'Version' ) . ' by ' . $ theme -> display ( 'Author' ) ; if ( is_child_theme ( ) ) { $ msg .= '<br />' . 'Child theme of: ' ... | Returns a formatted HTML string for the current theme |
2,673 | private function get_current_plugins ( ) { $ updates_avail = get_site_transient ( 'update_plugins' ) ; $ msg = '' ; foreach ( wp_get_active_and_valid_plugins ( ) as $ plugin ) { $ plugin_data = get_plugin_data ( $ plugin ) ; $ plugin_file = str_replace ( trailingslashit ( WP_PLUGIN_DIR ) , '' , $ plugin ) ; if ( isset ... | Returns a formatted HTML list of all active plugins |
2,674 | public function write ( $ string , $ length = null ) { $ this -> assertWritable ( ) ; if ( null === $ length ) { $ ret = fwrite ( $ this -> stream , $ string ) ; } else { $ ret = fwrite ( $ this -> stream , $ string , $ length ) ; } if ( false === $ ret ) { throw new RuntimeException ( 'Cannot write on stream' ) ; } re... | Write data to the stream . Binary - safe . |
2,675 | public function setSenderEmailAddress ( $ email ) { if ( ! $ this -> validateHeaderFieldValue ( $ email ) ) { throw new EmailValidationException ( __ ( 'Sender Email Address can not contain carriage return or newlines.' ) ) ; } $ this -> _sender_email_address = $ email ; } | Sets the sender - email . |
2,676 | public function setSenderName ( $ name ) { if ( ! $ this -> validateHeaderFieldValue ( $ name ) ) { throw new EmailValidationException ( __ ( 'Sender Name can not contain carriage return or newlines.' ) ) ; } $ this -> _sender_name = $ name ; } | Sets the sender - name . |
2,677 | public function setRecipients ( $ email ) { if ( ! is_array ( $ email ) ) { $ email = explode ( ',' , $ email ) ; array_walk ( $ email , function ( & $ val ) { return $ val = trim ( $ val ) ; } ) ; $ email = array_filter ( $ email ) ; } foreach ( $ email as $ e ) { if ( ! $ this -> validateHeaderFieldValue ( $ e ) ) { ... | Sets the recipients . |
2,678 | public function setAttachments ( $ files ) { $ this -> _attachments = array ( ) ; if ( $ files == null ) { return ; } if ( ! is_array ( $ files ) ) { $ files = array ( $ files ) ; } foreach ( $ files as $ key => $ file ) { if ( is_numeric ( $ key ) ) { $ this -> appendAttachment ( $ file ) ; } else { $ this -> appendAt... | This function sets one or multiple attachment files to the email . |
2,679 | public function appendAttachment ( $ file ) { if ( ! is_array ( $ file ) ) { $ file = array ( 'file' => $ file , 'filename' => null , 'charset' => null , ) ; } elseif ( ! isset ( $ file [ 'file' ] ) ) { $ keys = array_keys ( $ file ) ; $ file = array ( 'file' => $ file [ $ keys [ 0 ] ] , 'filename' => is_numeric ( $ ke... | Appends one file attachment to the attachments array . |
2,680 | protected function prepareMessageBody ( ) { $ attachments = $ this -> getSectionAttachments ( ) ; if ( $ attachments ) { $ this -> appendHeaderFields ( $ this -> contentInfoArray ( 'multipart/mixed' ) ) ; if ( ! empty ( $ this -> _text_plain ) && ! empty ( $ this -> _text_html ) ) { $ this -> _body = $ this -> boundary... | Build the message body and the content - describing header fields |
2,681 | protected function getSectionMultipartAlternative ( ) { $ output = $ this -> boundaryDelimiterLine ( 'multipart/alternative' ) . $ this -> contentInfoString ( 'text/plain' ) . $ this -> getSectionTextPlain ( ) . $ this -> boundaryDelimiterLine ( 'multipart/alternative' ) . $ this -> contentInfoString ( 'text/html' ) . ... | Build multipart email section . Used by sendmail and smtp classes to send multipart email . |
2,682 | protected function getSectionAttachments ( ) { $ output = '' ; foreach ( $ this -> _attachments as $ key => $ file ) { $ tmp_file = false ; if ( filter_var ( $ file [ 'file' ] , FILTER_VALIDATE_URL ) ) { $ gateway = new Gateway ( ) ; $ gateway -> init ( $ file [ 'file' ] ) ; $ gateway -> setopt ( 'TIMEOUT' , 30 ) ; $ f... | Builds the attachment section of a multipart email . |
2,683 | protected function contentInfoString ( $ type = null , $ file = null , $ filename = null , $ charset = null ) { $ data = $ this -> contentInfoArray ( $ type , $ file , $ filename , $ charset ) ; $ fields = array ( ) ; foreach ( $ data as $ key => $ value ) { $ fields [ ] = EmailHelper :: fold ( sprintf ( '%s: %s' , $ k... | Creates the properly formatted InfoString based on the InfoArray . |
2,684 | public static function isConnected ( ) { try { $ connected = ( isset ( self :: $ _connection [ 'id' ] ) && ! is_null ( self :: $ _connection [ 'id' ] ) ) ; } catch ( Exception $ ex ) { return false ; } return $ connected ; } | Determines if a connection has been made to the MySQL server |
2,685 | public function connect ( $ host = null , $ user = null , $ password = null , $ port = '3306' , $ database = null ) { self :: $ _connection = array ( 'host' => $ host , 'user' => $ user , 'pass' => $ password , 'port' => $ port , 'database' => $ database ) ; try { self :: $ _connection [ 'id' ] = mysqli_connect ( self ... | Creates a connect to the database server given the credentials . If an error occurs a DatabaseException is thrown otherwise true is returned |
2,686 | public function setTimeZone ( $ timezone = null ) { if ( is_null ( $ timezone ) ) { return ; } $ symphony_date = new DateTime ( 'now' , new DateTimeZone ( $ timezone ) ) ; $ utc = new DateTime ( 'now ' . $ symphony_date -> getOffset ( ) . ' seconds' , new DateTimeZone ( "UTC" ) ) ; $ offset = $ symphony_date -> diff ( ... | Sets the MySQL connection to use this timezone instead of the default MySQL server timezone . |
2,687 | public static function cleanValue ( $ value ) { if ( function_exists ( 'mysqli_real_escape_string' ) && self :: isConnected ( ) ) { return mysqli_real_escape_string ( self :: $ _connection [ 'id' ] , $ value ) ; } else { return addslashes ( $ value ) ; } } | This function will clean a string using the mysqli_real_escape_string function taking into account the current database character encoding . Note that this function does not encode _ or % . If mysqli_real_escape_string doesn t exist addslashes will be used as a backup option |
2,688 | public static function cleanFields ( array & $ array ) { foreach ( $ array as $ key => $ val ) { if ( is_array ( $ val ) ) { self :: cleanFields ( $ val ) ; continue ; } elseif ( strlen ( $ val ) == 0 ) { $ array [ $ key ] = 'null' ; } else { $ array [ $ key ] = "'" . self :: cleanValue ( $ val ) . "'" ; } } } | This function will apply the cleanValue function to an associative array of data encoding only the value not the key . This function can handle recursive arrays . This function manipulates the given parameter by reference . |
2,689 | public function insert ( array $ fields , $ table , $ updateOnDuplicate = false ) { if ( is_array ( current ( $ fields ) ) ) { $ sql = "INSERT INTO `$table` (`" . implode ( '`, `' , array_keys ( current ( $ fields ) ) ) . '`) VALUES ' ; $ rows = array ( ) ; foreach ( $ fields as $ key => $ array ) { if ( ! is_array ( $... | A convenience method to insert data into the Database . This function takes an associative array of data to input with the keys being the column names and the table . An optional parameter exposes MySQL s ON DUPLICATE KEY UPDATE functionality which will update the values if a duplicate key is found . |
2,690 | public function update ( $ fields , $ table , $ where = null ) { self :: cleanFields ( $ fields ) ; $ sql = "UPDATE $table SET " ; $ rows = array ( ) ; foreach ( $ fields as $ key => $ val ) { $ rows [ ] = " `$key` = $val" ; } $ sql .= implode ( ', ' , $ rows ) . ( ! is_null ( $ where ) ? ' WHERE ' . $ where : null ) ;... | A convenience method to update data that exists in the Database . This function takes an associative array of data to input with the keys being the column names and the table . A WHERE statement can be provided to select the rows to update |
2,691 | public function delete ( $ table , $ where = null ) { $ sql = "DELETE FROM `$table`" ; if ( ! is_null ( $ where ) ) { $ sql .= " WHERE $where" ; } return $ this -> query ( $ sql ) ; } | Given a table name and a WHERE statement delete rows from the Database . |
2,692 | private function __error ( $ type = null ) { if ( $ type == 'connect' ) { $ msg = mysqli_connect_error ( ) ; $ errornum = mysqli_connect_errno ( ) ; } else { $ msg = mysqli_error ( self :: $ _connection [ 'id' ] ) ; $ errornum = mysqli_errno ( self :: $ _connection [ 'id' ] ) ; } if ( self :: $ _logging === true ) { if... | If an error occurs in a query this function is called which logs the last query and the error number and error message from MySQL before throwing a DatabaseException |
2,693 | public function debug ( $ type = null ) { if ( ! $ type ) { return self :: $ _log ; } return ( $ type == 'error' ? self :: $ _log [ 'error' ] : self :: $ _log [ 'query' ] ) ; } | Returns all the log entries by type . There are two valid types error and debug . If no type is given the entire log is returned otherwise only log messages for that type are returned |
2,694 | public function getStatistics ( ) { $ query_timer = 0.0 ; $ slow_queries = array ( ) ; foreach ( self :: $ _log as $ key => $ val ) { $ query_timer += $ val [ 'execution_time' ] ; if ( $ val [ 'execution_time' ] > 0.0999 ) { $ slow_queries [ ] = $ val ; } } return array ( 'queries' => self :: queryCount ( ) , 'slow-que... | Returns some basic statistics from the MySQL class about the number of queries the time it took to query and any slow queries . A slow query is defined as one that took longer than 0 . 0999 seconds This function is used by the Profile devkit |
2,695 | public function import ( $ sql , $ force_engine = false ) { if ( $ force_engine ) { $ this -> query ( 'SET default_storage_engine = MYISAM' ) ; } $ queries = preg_split ( '/;[\\r\\n]+/' , $ sql , - 1 , PREG_SPLIT_NO_EMPTY ) ; if ( ! is_array ( $ queries ) || empty ( $ queries ) || count ( $ queries ) <= 0 ) { throw new... | Convenience function to allow you to execute multiple SQL queries at once by providing a string with the queries delimited with a ; |
2,696 | public static function add ( array $ settings ) { $ defaults = array ( ) ; $ defaults [ 'creation_date' ] = $ defaults [ 'modification_date' ] = DateTimeObj :: get ( 'Y-m-d H:i:s' ) ; $ defaults [ 'creation_date_gmt' ] = $ defaults [ 'modification_date_gmt' ] = DateTimeObj :: getGMT ( 'Y-m-d H:i:s' ) ; $ defaults [ 'au... | Takes an associative array of Section settings and creates a new entry in the tbl_sections table returning the ID of the Section . The ID of the section is generated using auto_increment and returned as the Section ID . |
2,697 | public static function edit ( $ section_id , array $ settings ) { $ defaults = array ( ) ; $ defaults [ 'modification_date' ] = DateTimeObj :: get ( 'Y-m-d H:i:s' ) ; $ defaults [ 'modification_date_gmt' ] = DateTimeObj :: getGMT ( 'Y-m-d H:i:s' ) ; $ defaults [ 'author_id' ] = 1 ; $ defaults [ 'modification_author_id'... | Updates an existing Section given it s ID and an associative array of settings . The array does not have to contain all the settings for the Section as there is no deletion of settings prior to updating the Section |
2,698 | public static function delete ( $ section_id ) { $ details = Symphony :: Database ( ) -> fetchRow ( 0 , sprintf ( " SELECT `sortorder` FROM tbl_sections WHERE `id` = %d" , $ section_id ) ) ; $ entries = Symphony :: Database ( ) -> fetchCol ( 'id' , "SELECT `id` FROM `tbl_entries` WHERE `section_id` = '$secti... | Deletes a Section by Section ID removing all entries fields the Section and any Section Associations in that order |
2,699 | public static function fetch ( $ section_id = null , $ order = 'ASC' , $ sortfield = 'name' ) { $ returnSingle = false ; $ section_ids = array ( ) ; if ( ! is_null ( $ section_id ) ) { if ( ! is_array ( $ section_id ) ) { $ returnSingle = true ; $ section_ids = array ( $ section_id ) ; } else { $ section_ids = $ sectio... | Returns a Section object by ID or returns an array of Sections if the Section ID was omitted . If the Section ID is omitted it is possible to sort the Sections by providing a sort order and sort field . By default Sections will be order in ascending order by their name |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.