idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
52,800
public function getIsAuthenticated ( ) { if ( ! $ this -> authenticated ) { try { $ proxy = $ this -> getProxy ( ) ; $ this -> authenticated = $ proxy -> hasValidAccessToken ( ) ; } catch ( \ OAuth \ Common \ Exception \ Exception $ e ) { throw new ErrorException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , 1 , $ e -> getFile ( ) , $ e -> getLine ( ) , $ e ) ; } } return parent :: getIsAuthenticated ( ) ; }
For OAuth we can check existing access token . Useful for API calls .
52,801
protected function _fetchAttributes ( ) { if ( ! $ this -> fetched ) { $ this -> fetched = true ; $ result = $ this -> fetchAttributes ( ) ; if ( isset ( $ result ) ) { $ this -> fetched = $ result ; } } }
Fetch attributes array . This function is internally used to handle fetched state .
52,802
public function getAttribute ( $ key , $ default = null ) { $ this -> _fetchAttributes ( ) ; $ getter = 'get' . $ key ; if ( method_exists ( $ this , $ getter ) ) { return $ this -> $ getter ( ) ; } else { return isset ( $ this -> attributes [ $ key ] ) ? $ this -> attributes [ $ key ] : $ default ; } }
Returns the authorization attribute value .
52,803
protected function parseResponseInternal ( $ response ) { try { $ result = $ this -> parseResponse ( $ response ) ; if ( ! isset ( $ result ) ) { throw new ErrorException ( Yii :: t ( 'eauth' , 'Invalid response format.' ) , 500 ) ; } $ error = $ this -> fetchResponseError ( $ result ) ; if ( isset ( $ error ) && ! empty ( $ error [ 'message' ] ) ) { throw new ErrorException ( $ error [ 'message' ] , $ error [ 'code' ] ) ; } return $ result ; } catch ( \ Exception $ e ) { throw new ErrorException ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } }
Parse response and check for errors .
52,804
public function getAuthorizationUri ( array $ additionalParameters = [ ] ) { $ parameters = array_merge ( $ additionalParameters , [ 'type' => 'web_server' , 'client_id' => $ this -> credentials -> getConsumerId ( ) , 'redirect_uri' => $ this -> credentials -> getCallbackUrl ( ) , 'response_type' => 'code' , ] ) ; $ parameters [ 'scope' ] = implode ( $ this -> service -> getScopeSeparator ( ) , $ this -> scopes ) ; if ( $ this -> needsStateParameterInAuthUrl ( ) ) { if ( ! isset ( $ parameters [ 'state' ] ) ) { $ parameters [ 'state' ] = $ this -> generateAuthorizationState ( ) ; } $ this -> storeAuthorizationState ( $ parameters [ 'state' ] ) ; } $ url = clone $ this -> getAuthorizationEndpoint ( ) ; foreach ( $ parameters as $ key => $ val ) { $ url -> addToQuery ( $ key , $ val ) ; } return $ url ; }
Returns the url to redirect to for authorization purposes .
52,805
protected function checkError ( ) { if ( isset ( $ _GET [ $ this -> errorParam ] ) ) { $ error_code = $ _GET [ $ this -> errorParam ] ; if ( $ error_code === $ this -> errorAccessDeniedCode ) { $ this -> cancel ( ) ; } else { $ error = $ error_code ; if ( isset ( $ _GET [ $ this -> errorDescriptionParam ] ) ) { $ error = $ _GET [ $ this -> errorDescriptionParam ] . ' (' . $ error . ')' ; } throw new ErrorException ( $ error ) ; } return false ; } return true ; }
Check request params for error code and message .
52,806
public function connect ( $ host , $ user , $ password , $ database = '' , $ port = '' , $ socket = '' , $ connect = false ) { if ( ! extension_loaded ( 'memcache' ) || $ this -> caching_method == 'memcache' ) unset ( $ this -> warnings [ 'memcache' ] ) ; $ this -> credentials = array ( 'host' => $ host , 'user' => $ user , 'password' => $ password , 'database' => $ database , 'port' => $ port == '' ? ini_get ( 'mysqli.default_port' ) : $ port , 'socket' => $ socket == '' ? ini_get ( 'mysqli.default_socket' ) : $ socket , ) ; if ( $ connect ) $ this -> _connected ( ) ; }
Opens a connection to a MySQL Server and optionally selects a database .
52,807
public function dcount ( $ column , $ table , $ where = '' , $ replacements = '' , $ cache = false , $ highlight = false ) { $ this -> query ( ' SELECT COUNT(' . $ column . ') AS counted FROM ' . $ this -> _escape ( $ table ) . ( $ where != '' ? ' WHERE ' . $ where : '' ) . ' ' , $ replacements , $ cache , false , $ highlight ) ; if ( isset ( $ this -> last_result ) && $ this -> last_result !== false && $ this -> returned_rows > 0 ) { $ row = $ this -> fetch_assoc ( ) ; return $ row [ 'counted' ] ; } return false ; }
Counts the values in a column of a table .
52,808
public function delete ( $ table , $ where = '' , $ replacements = '' , $ highlight = false ) { $ this -> query ( ' DELETE FROM ' . $ this -> _escape ( $ table ) . ( $ where != '' ? ' WHERE ' . $ where : '' ) . ' ' , $ replacements , false , false , $ highlight ) ; return isset ( $ this -> last_result ) && $ this -> last_result !== false ; }
Deletes rows from a table .
52,809
public function dlookup ( $ column , $ table , $ where = '' , $ replacements = '' , $ cache = false , $ highlight = false ) { $ this -> query ( ' SELECT ' . $ column . ' FROM ' . $ this -> _escape ( $ table ) . ( $ where != '' ? ' WHERE ' . $ where : '' ) . ' LIMIT 1 ' , $ replacements , $ cache , false , $ highlight ) ; if ( isset ( $ this -> last_result ) && $ this -> last_result !== false && $ this -> returned_rows > 0 ) { $ row = $ this -> fetch_assoc ( ) ; if ( count ( $ row ) == 1 ) return array_pop ( $ row ) ; return $ row ; } return false ; }
Returns one or more columns from ONE row of a table .
52,810
public function dsum ( $ column , $ table , $ where = '' , $ replacements = '' , $ cache = false , $ highlight = false ) { $ this -> query ( ' SELECT SUM(' . $ column . ') AS total FROM ' . $ this -> _escape ( $ table ) . ( $ where != '' ? ' WHERE ' . $ where : '' ) . ' ' , $ replacements , $ cache , false , $ highlight ) ; if ( isset ( $ this -> last_result ) && $ this -> last_result !== false && $ this -> found_rows > 0 ) { $ row = $ this -> fetch_assoc ( ) ; return $ row [ 'total' ] ; } return false ; }
Sums the values in a column of a table .
52,811
public function escape ( $ string ) { if ( ! $ this -> _connected ( ) ) return false ; if ( get_magic_quotes_gpc ( ) ) $ string = stripslashes ( $ string ) ; return mysqli_real_escape_string ( $ this -> connection , $ string ) ; }
Escapes special characters in a string that s to be used in an SQL statement in order to prevent SQL injections .
52,812
public function fetch_assoc ( $ resource = '' ) { if ( ! $ this -> _connected ( ) ) return false ; if ( $ resource == '' && isset ( $ this -> last_result ) && $ this -> last_result !== false ) $ resource = & $ this -> last_result ; if ( $ this -> _is_result ( $ resource ) ) { $ result = mysqli_fetch_assoc ( $ resource ) ; if ( $ resource -> type == 1 ) $ this -> _manage_unbuffered_query_info ( $ resource , $ result ) ; return $ result ; } elseif ( is_integer ( $ resource ) && isset ( $ this -> cached_results [ $ resource ] ) ) { $ result = current ( $ this -> cached_results [ $ resource ] ) ; next ( $ this -> cached_results [ $ resource ] ) ; return $ result ; } return $ this -> _log ( 'errors' , array ( 'message' => $ this -> language [ 'not_a_valid_resource' ] , ) ) ; }
Returns an associative array that corresponds to the fetched row and moves the internal data pointer ahead . The data is taken from the resource created by the previous query or from the resource given as argument .
52,813
public function fetch_assoc_all ( $ index = '' , $ resource = '' ) { if ( ! $ this -> _connected ( ) ) return false ; if ( $ resource == '' && $ this -> _is_result ( $ index ) || ( is_integer ( $ index ) && isset ( $ this -> cached_results [ $ index ] ) ) ) { $ resource = $ index ; $ index = '' ; } if ( $ resource == '' && isset ( $ this -> last_result ) && $ this -> last_result !== false ) $ resource = & $ this -> last_result ; if ( $ this -> _is_result ( $ resource ) || ( is_integer ( $ resource ) && isset ( $ this -> cached_results [ $ resource ] ) ) ) { $ result = array ( ) ; if ( @ $ this -> seek ( 0 , $ resource ) ) { while ( $ row = $ this -> fetch_assoc ( $ resource ) ) { if ( trim ( $ index ) != '' && isset ( $ row [ $ index ] ) ) $ result [ $ row [ $ index ] ] = $ row ; else $ result [ ] = $ row ; } } return $ result ; } return $ this -> _log ( 'errors' , array ( 'message' => $ this -> language [ 'not_a_valid_resource' ] , ) ) ; }
Returns an associative array containing all the rows from the resource created by the previous query or from the resource given as argument and moves the internal pointer to the end .
52,814
public function fetch_obj ( $ resource = '' ) { if ( ! $ this -> _connected ( ) ) return false ; if ( $ resource == '' && isset ( $ this -> last_result ) && $ this -> last_result !== false ) $ resource = & $ this -> last_result ; if ( $ this -> _is_result ( $ resource ) ) { $ result = mysqli_fetch_object ( $ resource ) ; if ( $ resource -> type == 1 ) $ this -> _manage_unbuffered_query_info ( $ resource , $ result ) ; return $ result ; } elseif ( is_integer ( $ resource ) && isset ( $ this -> cached_results [ $ resource ] ) ) { $ result = current ( $ this -> cached_results [ $ resource ] ) ; next ( $ this -> cached_results [ $ resource ] ) ; if ( $ result !== false ) $ result = ( object ) $ result ; return $ result ; } return $ this -> _log ( 'errors' , array ( 'message' => $ this -> language [ 'not_a_valid_resource' ] , ) ) ; }
Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead . The data is taken from the resource created by the previous query or from the resource given as argument .
52,815
public function free_result ( $ resource = '' ) { if ( ! $ this -> _connected ( ) ) return false ; if ( $ resource == '' && isset ( $ this -> last_result ) && $ this -> last_result !== false ) $ resource = & $ this -> last_result ; if ( $ this -> _is_result ( $ resource ) ) @ mysqli_free_result ( $ resource ) ; }
Frees the memory associated with a result
52,816
public function get_columns ( $ resource = '' ) { if ( ! $ this -> _connected ( ) ) return false ; if ( $ resource == '' && isset ( $ this -> last_result ) && $ this -> last_result !== false ) $ resource = & $ this -> last_result ; if ( $ this -> _is_result ( $ resource ) ) { $ result = array ( ) ; while ( $ column_info = mysqli_fetch_field ( $ resource ) ) $ result [ $ column_info -> name ] = get_object_vars ( $ column_info ) ; return $ result ; } elseif ( is_integer ( $ resource ) && isset ( $ this -> cached_results [ $ resource ] ) ) return $ this -> column_info ; return $ this -> _log ( 'errors' , array ( 'message' => $ this -> language [ 'not_a_valid_resource' ] , ) ) ; }
Returns an array of associative arrays with information about the columns in the MySQL result associated with the specified result identifier .
52,817
public function get_table_status ( $ table = '' ) { if ( strpos ( $ table , '.' ) !== false ) list ( $ database , $ table ) = explode ( '.' , $ table , 2 ) ; $ this -> query ( ' SHOW TABLE STATUS ' . ( isset ( $ database ) ? ' IN ' . $ this -> _escape ( $ database ) : '' ) . ' ' . ( trim ( $ table ) != '' ? 'LIKE ?' : '' ) . ' ' , array ( $ table ) ) ; return $ this -> fetch_assoc_all ( 'Name' ) ; }
Returns an associative array with a lot of useful information on all or specific tables only .
52,818
public function get_tables ( $ database = '' ) { $ result = $ this -> fetch_assoc_all ( '' , $ this -> query ( ' SHOW TABLES' . ( $ database != '' ? ' IN ' . $ this -> _escape ( $ database ) : '' ) ) ) ; $ tables = array ( ) ; foreach ( $ result as $ tableName ) $ tables [ ] = array_pop ( $ tableName ) ; return $ tables ; }
Returns an array with all the tables in a database .
52,819
public function insert_id ( ) { if ( ! $ this -> _connected ( ) ) return false ; if ( isset ( $ this -> last_result ) && $ this -> last_result !== false ) return mysqli_insert_id ( $ this -> connection ) ; return $ this -> _log ( 'errors' , array ( 'message' => $ this -> language [ 'not_a_valid_resource' ] , ) ) ; }
Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query .
52,820
public function option ( $ option , $ value = '' ) { if ( $ this -> connection ) return $ this -> _log ( 'errors' , array ( 'message' => $ this -> language [ 'options_before_connect' ] , ) ) ; if ( is_array ( $ option ) ) foreach ( $ option as $ property => $ value ) $ this -> options [ $ property ] = $ value ; else $ this -> options [ $ option ] = $ value ; }
Sets one or more options that affect the behavior of a connection .
52,821
public function seek ( $ row , $ resource = '' ) { if ( ! $ this -> _connected ( ) ) return false ; if ( $ resource == '' && isset ( $ this -> last_result ) && $ this -> last_result !== false ) $ resource = & $ this -> last_result ; if ( $ this -> _is_result ( $ resource ) ) { if ( $ resource -> type == 1 ) { $ debug = debug_backtrace ( ) ; if ( isset ( $ debug [ 1 ] ) && isset ( $ debug [ 1 ] [ 'function' ] ) && $ debug [ 1 ] [ 'class' ] == 'Zebra_Database' ) $ method = $ debug [ 1 ] [ 'function' ] ; else $ method = $ debug [ 0 ] [ 'function' ] ; return $ this -> _log ( 'errors' , array ( 'message' => sprintf ( $ this -> language [ 'unusable_method_unbuffered_queries' ] , $ method ) , ) ) ; } if ( mysqli_num_rows ( $ resource ) == 0 || mysqli_data_seek ( $ resource , $ row ) ) return true ; elseif ( error_reporting ( ) != 0 ) return $ this -> _log ( 'errors' , array ( 'message' => $ this -> language [ 'could_not_seek' ] , ) ) ; } elseif ( is_integer ( $ resource ) && isset ( $ this -> cached_results [ $ resource ] ) ) { reset ( $ this -> cached_results [ $ resource ] ) ; if ( $ row == 0 ) return true ; elseif ( $ row > 0 ) { while ( next ( $ this -> cached_results [ $ resource ] ) ) if ( $ row == key ( $ this -> cached_results [ $ resource ] ) ) return true ; return $ this -> _log ( 'errors' , array ( 'message' => $ this -> language [ 'could_not_seek' ] , ) ) ; } } return $ this -> _log ( 'errors' , array ( 'message' => $ this -> language [ 'not_a_valid_resource' ] , ) ) ; }
Moves the internal row pointer of the MySQL result associated with the specified result identifier to the specified row number .
52,822
public function select ( $ columns , $ table , $ where = '' , $ replacements = '' , $ order = '' , $ limit = '' , $ cache = false , $ calc_rows = false , $ highlight = false ) { if ( ! is_array ( $ columns ) ) $ columns = array_map ( 'trim' , explode ( ',' , $ columns ) ) ; foreach ( $ columns as $ key => $ value ) if ( trim ( $ value ) != '*' ) $ columns [ $ key ] = $ this -> _escape ( $ value ) ; return $ this -> query ( ' SELECT ' . implode ( ', ' , $ columns ) . ' FROM ' . $ this -> _escape ( $ table ) . ( $ where != '' ? ' WHERE ' . $ where : '' ) . ( $ order != '' ? ' ORDER BY ' . $ order : '' ) . ( $ limit != '' ? ' LIMIT ' . $ limit : '' ) . ' ' , $ replacements , $ cache , $ calc_rows , $ highlight ) ; }
Shorthand for simple SELECT queries .
52,823
public function select_database ( $ database ) { if ( ! $ this -> _connected ( ) ) return false ; $ this -> credentials [ 'database' ] = $ database ; return mysqli_select_db ( $ this -> connection , $ database ) ; }
Selects the default database for queries .
52,824
public function set_charset ( $ charset = 'utf8' , $ collation = 'utf8_general_ci' ) { unset ( $ this -> warnings [ 'charset' ] ) ; $ this -> query ( 'SET NAMES "' . $ this -> escape ( $ charset ) . '" COLLATE "' . $ this -> escape ( $ collation ) . '"' ) ; }
Sets MySQL character set and collation .
52,825
public function transaction_start ( $ test_only = false ) { $ sql = 'START TRANSACTION' ; if ( $ this -> transaction_status === 0 ) { $ this -> transaction_status = ( $ test_only ? 3 : 1 ) ; $ this -> query ( $ sql ) ; return isset ( $ this -> last_result ) && $ this -> last_result !== false ; } return $ this -> _log ( 'unsuccessful-queries' , array ( 'query' => $ sql , 'error' => $ this -> language [ 'transaction_in_progress' ] , ) , false ) ; }
Starts the transaction system .
52,826
public function table_exists ( $ table ) { if ( strpos ( $ table , '.' ) !== false ) list ( $ database , $ table ) = explode ( '.' , $ table ) ; return is_array ( $ this -> fetch_assoc ( $ this -> query ( 'SHOW TABLES' . ( isset ( $ database ) ? ' IN ' . $ database : '' ) . ' LIKE ?' , array ( $ table ) ) ) ) ; }
Checks whether a table exists in the current database .
52,827
public function truncate ( $ table , $ highlight = false ) { $ this -> query ( ' TRUNCATE ' . $ this -> _escape ( $ table ) . ' ' , '' , false , false , $ highlight ) ; return isset ( $ this -> last_result ) && $ this -> last_result !== false ; }
Shorthand for truncating tables .
52,828
public function update ( $ table , $ columns , $ where = '' , $ replacements = '' , $ highlight = false ) { if ( $ replacements != '' && ! is_array ( $ replacements ) ) return $ this -> _log ( 'unsuccessful-queries' , array ( 'query' => '' , 'error' => $ this -> language [ 'warning_replacements_not_array' ] ) ) ; $ cols = $ this -> _build_sql ( $ columns ) ; $ this -> query ( ' UPDATE ' . $ this -> _escape ( $ table ) . ' SET ' . $ cols . ( $ where != '' ? ' WHERE ' . $ where : '' ) . ' ' , array_merge ( array_values ( $ columns ) , $ replacements == '' ? array ( ) : $ replacements ) , false , false , $ highlight ) ; return isset ( $ this -> last_result ) && $ this -> last_result !== false ; }
Shorthand for UPDATE queries .
52,829
private function _escape ( $ entries ) { $ entries = ( array ) $ entries ; $ result = array ( ) ; foreach ( $ entries as $ entry ) { $ entry = explode ( '.' , $ entry ) ; $ entry = array_map ( function ( $ value ) { $ value = trim ( trim ( $ value , '`' ) ) ; if ( $ value !== '*' && ! $ this -> _is_mysql_function ( $ value ) ) { if ( stripos ( $ value , ' as ' ) !== false ) list ( $ value , $ alias ) = array_map ( 'trim' , preg_split ( '/ as /i' , $ value ) ) ; return '`' . $ value . '`' . ( isset ( $ alias ) ? ' AS ' . $ alias : '' ) ; } return $ value ; } , $ entry ) ; $ result [ ] = implode ( '.' , $ entry ) ; } return implode ( ', ' , $ result ) ; }
Encloses segments of a database . table . column construction in grave accents .
52,830
public function getNamedAssetUrl ( $ assetName , $ type = null ) { $ manifestEntry = $ this -> getManifestEntry ( $ assetName , $ assetName , 'This is probably a commons chunk - is it configured by this name in webpack.config.js?' ) ; if ( $ type === null ) { $ type = self :: TYPE_JS ; } return isset ( $ manifestEntry [ $ type ] ) ? $ manifestEntry [ $ type ] : null ; }
Gets URL for specified named asset - should be used for commons chunks .
52,831
public function locateAsset ( $ asset ) { if ( substr ( $ asset , 0 , strlen ( $ this -> prefix ) ) === $ this -> prefix ) { $ locatedAsset = $ this -> resolveAlias ( $ asset ) ; } else { $ locatedAsset = $ asset ; } if ( ! file_exists ( $ locatedAsset ) ) { throw new AssetNotFoundException ( sprintf ( 'Asset not found (%s, resolved to %s)' , $ asset , $ locatedAsset ) ) ; } return $ locatedAsset ; }
Locates asset - resolves alias if provided . Does not support assets with loaders .
52,832
public function query ( $ sql ) { LogMaster :: log ( $ sql ) ; $ res = sasql_query ( $ this -> connection , $ sql ) ; if ( $ res === false ) throw new Exception ( "SaSQL operation failed\n" . sasql_error ( $ this -> connection ) ) ; $ this -> last_result = $ res ; return $ res ; }
!< ID of previously inserted record
52,833
public function query ( $ sql ) { LogMaster :: log ( $ sql ) ; $ stm = oci_parse ( $ this -> connection , $ sql ) ; if ( $ stm === false ) throw new Exception ( "Oracle - sql parsing failed\n" . oci_error ( $ this -> connection ) ) ; $ out = array ( 0 => null ) ; if ( $ this -> insert_operation ) { oci_bind_by_name ( $ stm , ":outID" , $ out [ 0 ] , 999 ) ; $ this -> insert_operation = false ; } $ mode = ( $ this -> is_record_transaction ( ) || $ this -> is_global_transaction ( ) ) ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS ; $ res = @ oci_execute ( $ stm , $ mode ) ; if ( $ res === false ) throw new Exception ( oci_error ( $ this -> connection ) ) ; $ this -> last_id = $ out [ 0 ] ; return $ stm ; }
flag of insert operation
52,834
public function select ( $ source ) { $ relation = $ this -> getFileName ( $ source -> get_relation ( ) ) ; if ( $ relation == '0' ) { $ relation = '' ; } else { $ path = $ source -> get_source ( ) ; } $ path = $ source -> get_source ( ) ; $ path = $ this -> getFileName ( $ path ) ; $ path = realpath ( $ path ) ; if ( $ path == false ) { return new FileSystemResult ( ) ; } if ( strpos ( realpath ( $ path . '/' . $ relation ) , $ path ) !== 0 ) { return new FileSystemResult ( ) ; } $ res = $ this -> getFilesList ( $ path , $ relation ) ; $ res = $ res -> sort ( $ source -> get_sort_by ( ) , $ this -> config -> data ) ; return $ res ; }
returns list of files and directories
52,835
private function getFilesList ( $ path , $ relation ) { $ fileSystemTypes = FileSystemTypes :: getInstance ( ) ; LogMaster :: log ( "Query filesystem: " . $ path ) ; $ dir = opendir ( $ path . '/' . $ relation ) ; $ result = new FileSystemResult ( ) ; for ( $ i = 0 ; $ i < count ( $ this -> config -> data ) ; $ i ++ ) { $ fields [ ] = $ this -> config -> data [ $ i ] [ 'db_name' ] ; } while ( $ file = readdir ( $ dir ) ) { if ( ( $ file == '.' ) || ( $ file == '..' ) ) { continue ; } $ newFile = array ( ) ; $ fileNameExt = $ this -> parseFileName ( $ path . '/' . $ relation , $ file ) ; if ( ! $ fileSystemTypes -> checkFile ( $ file , $ fileNameExt ) ) { continue ; } if ( ( in_array ( 'size' , $ fields ) ) || ( in_array ( 'date' , $ fields ) ) ) { $ fileInfo = stat ( $ path . '/' . $ file ) ; } for ( $ i = 0 ; $ i < count ( $ fields ) ; $ i ++ ) { $ field = $ fields [ $ i ] ; switch ( $ field ) { case 'filename' : $ newFile [ 'filename' ] = $ file ; break ; case 'full_filename' : $ newFile [ 'full_filename' ] = $ path . "/" . $ file ; break ; case 'size' : $ newFile [ 'size' ] = $ fileInfo [ 'size' ] ; break ; case 'extention' : $ newFile [ 'extention' ] = $ fileNameExt [ 'ext' ] ; break ; case 'name' : $ newFile [ 'name' ] = $ fileNameExt [ 'name' ] ; break ; case 'date' : $ newFile [ 'date' ] = date ( "Y-m-d H:i:s" , $ fileInfo [ 'ctime' ] ) ; break ; } $ newFile [ 'relation_id' ] = $ relation . '/' . $ file ; $ newFile [ 'safe_name' ] = $ this -> setFileName ( $ relation . '/' . $ file ) ; $ newFile [ 'is_folder' ] = $ fileNameExt [ 'is_dir' ] ; } $ result -> addFile ( $ newFile ) ; } return $ result ; }
gets files and directory list
52,836
private function parseFileName ( $ path , $ file ) { $ result = Array ( ) ; if ( is_dir ( $ path . '/' . $ file ) ) { $ result [ 'name' ] = $ file ; $ result [ 'ext' ] = 'dir' ; $ result [ 'is_dir' ] = 1 ; } else { $ pos = strrpos ( $ file , '.' ) ; $ result [ 'name' ] = substr ( $ file , 0 , $ pos ) ; $ result [ 'ext' ] = substr ( $ file , $ pos + 1 ) ; $ result [ 'is_dir' ] = 0 ; } return $ result ; }
parses file name and checks if is directory
52,837
function set_userdata ( $ name , $ value ) { if ( $ this -> userdata === false ) $ this -> userdata = array ( ) ; $ this -> userdata [ $ name ] = $ value ; }
set userdata for the item
52,838
public function pdf ( $ config = [ ] ) { if ( ! isset ( $ config [ 'url' ] ) && ! isset ( $ config [ 'html' ] ) ) { throw new \ Exception ( 'URL or HTML in configuration required' , 400 ) ; } $ tempFile = null ; if ( ! isset ( $ config [ 'pdf' ] [ 'path' ] ) ) { $ tempFile = tempnam ( sys_get_temp_dir ( ) , 'pdf-' ) ; $ this -> config [ 'pdf' ] [ 'path' ] = $ tempFile ; } $ this -> config [ 'pdf' ] [ 'format' ] = 'A4' ; $ this -> config [ 'pdf' ] [ 'printBackground' ] = true ; $ this -> config = self :: merge ( $ this -> config , $ config ) ; $ fullCommand = $ this -> path . ' ' . $ this -> nodePath . ' ' . $ this -> nodeBinary . ' ' . escapeshellarg ( $ this -> executable ) . ' ' . escapeshellarg ( json_encode ( $ this -> config ) ) ; if ( $ this -> isDebug ) { $ fullCommand .= " 2>&1" ; } exec ( $ fullCommand , $ output , $ returnVal ) ; $ result = [ 'ouput' => $ output , 'returnVal' => $ returnVal ] ; if ( $ returnVal == 0 && isset ( $ tempFile ) ) { $ data = file_get_contents ( $ this -> config [ 'pdf' ] [ 'path' ] ) ; unlink ( $ this -> config [ 'pdf' ] [ 'path' ] ) ; return $ data ; } return $ result ; }
Generate PDF file based on configuration .
52,839
public function destroy ( $ id ) { try { $ this -> file -> destroy ( $ id ) ; return response ( ) -> json ( [ 'status' => 'success' ] ) ; } catch ( Exception $ e ) { return $ this -> handleError ( $ e ) ; } }
Delete the resource
52,840
public function call ( $ provider , $ method , array $ postParams = array ( ) , array $ queryParams = array ( ) , $ returnData = false ) { $ this -> code = - 1 ; $ this -> data = array ( ) ; $ this -> message = '' ; if ( empty ( $ provider ) ) { throw new Mobizon_Param_Required ( 'You must provide "provider" parameter to MobizonApi::call.' ) ; } if ( empty ( $ method ) ) { throw new Mobizon_Param_Required ( 'You must provide "method" parameter to MobizonApi::call.' ) ; } $ queryDefaults = array ( 'api' => $ this -> apiVersion , 'apiKey' => $ this -> apiKey , 'output' => $ this -> format ) ; $ queryParams = $ this -> applyParams ( $ queryDefaults , $ queryParams ) ; $ url = ( $ this -> forceHTTP ? 'http' : 'https' ) . '://' . $ this -> apiServer . '/service/' . strtolower ( $ provider ) . '/' . strtolower ( $ method ) . '?' ; curl_setopt ( $ this -> curl , CURLOPT_URL , $ url . http_build_query ( $ queryParams ) ) ; if ( ! empty ( $ postParams ) ) { curl_setopt ( $ this -> curl , CURLOPT_POST , true ) ; curl_setopt ( $ this -> curl , CURLOPT_POSTFIELDS , http_build_query ( $ postParams ) ) ; } else { curl_setopt ( $ this -> curl , CURLOPT_POST , false ) ; } $ result = curl_exec ( $ this -> curl ) ; $ error = curl_error ( $ this -> curl ) ; if ( $ error ) { throw new Mobizon_Http_Error ( 'API call failed: ' . $ error . '.' ) ; } $ result = $ this -> decode ( $ result ) ; if ( ! is_object ( $ result ) ) { throw new Mobizon_Http_Error ( 'Bad API result: server returned unexpected result.' ) ; } $ this -> code = $ result -> code ; $ this -> data = $ result -> data ; $ this -> message = $ result -> message ; return $ returnData ? $ this -> getData ( ) : ( in_array ( $ this -> getCode ( ) , array ( 0 , 100 ) ) ) ; }
Main method to call Mobizon API .
52,841
public function decode ( $ responseData ) { switch ( $ this -> format ) { case 'json' : return $ this -> jsonDecode ( $ responseData ) ; case 'xml' : return $ this -> xmlDecode ( $ responseData ) ; default : return false ; } }
Returns parsed API response depending on requested format
52,842
private function findNumberOfSentMails ( ) { $ sendCount = 0 ; if ( $ this -> messageFormat -> getVersion ( ) === 'v3.1' ) { $ messages = $ this -> resultApi -> getBody ( ) [ 'Messages' ] ; foreach ( $ messages as $ message ) { if ( isset ( $ message [ 'To' ] ) ) { $ sendCount += count ( $ message [ 'To' ] ) ; } if ( isset ( $ message [ 'Bcc' ] ) && ( ! empty ( $ message [ 'Bcc' ] ) ) ) { $ sendCount += count ( $ message [ 'Bcc' ] ) ; } if ( isset ( $ message [ 'Cc' ] ) && ( ! empty ( $ message [ 'Cc' ] ) ) ) { $ sendCount += count ( $ message [ 'Cc' ] ) ; } } return $ sendCount ; } if ( $ this -> messageFormat -> getVersion ( ) === 'v3' ) { if ( isset ( $ this -> resultApi -> getBody ( ) [ 'Sent' ] ) ) { $ sendCount += count ( $ this -> resultApi -> getBody ( ) [ 'Sent' ] ) ; } return $ sendCount ; } return $ sendCount ; }
Finds the number of sent emails by last send call
52,843
protected static function prepareHeaders ( Swift_Mime_Message $ message , $ mailjetHeaders ) { $ messageHeaders = $ message -> getHeaders ( ) ; $ mailjetData = [ ] ; foreach ( array_keys ( $ mailjetHeaders ) as $ headerName ) { if ( null !== $ value = $ messageHeaders -> get ( $ headerName ) ) { if ( $ headerName == "X-MJ-Vars" && is_string ( $ value -> getValue ( ) ) ) { $ mailjetData [ $ mailjetHeaders [ $ headerName ] ] = json_decode ( $ value -> getValue ( ) ) ; } else { $ mailjetData [ $ mailjetHeaders [ $ headerName ] ] = $ value -> getValue ( ) ; } $ messageHeaders -> removeAll ( $ headerName ) ; } } return $ mailjetData ; }
Extract Mailjet specific header return an array of formatted data for Mailjet send API
52,844
public function getHeaders ( $ source , $ continue = true ) { if ( false !== ( $ separator_pos = strpos ( $ source , "\r\n\r\n" ) ) ) { if ( $ continue && false !== strpos ( $ source , 'HTTP/1.1 100 Continue' ) ) { $ source = trim ( substr ( $ source , $ separator_pos + 4 ) ) ; $ source = $ this -> getHeaders ( $ source , false ) ; } else { $ source = trim ( substr ( $ source , 0 , $ separator_pos ) ) ; } return $ source ; } return '' ; }
Return mail headers
52,845
public function exportCookies ( $ source ) { $ cookies = array ( ) ; if ( preg_match_all ( '#Set-Cookie:\s*([^=]+)=([^;]+)#i' , $ source , $ matches ) ) { for ( $ i = 0 , $ cnt = count ( $ matches [ 1 ] ) ; $ i < $ cnt ; ++ $ i ) { $ cookies [ trim ( $ matches [ 1 ] [ $ i ] ) ] = trim ( $ matches [ 2 ] [ $ i ] ) ; } } return $ cookies ; }
If cookies were sent save them
52,846
protected function tagSearch ( $ needle , array $ haystack ) { foreach ( $ haystack as $ actual ) { if ( 0 === strcasecmp ( $ needle , $ actual ) ) { return $ actual ; } } return null ; }
Searchs for the actual name of a tag .
52,847
private function determineCase ( $ word ) { $ ret = - 1 ; $ trimmedword = trim ( $ word ) ; if ( \ is_string ( $ word ) && ( mb_strlen ( $ trimmedword ) > 0 ) ) { $ i = 0 ; $ found = false ; $ openbrace = 0 ; while ( ! $ found && ( $ i <= mb_strlen ( $ word ) ) ) { $ letter = mb_substr ( $ trimmedword , $ i , 1 ) ; $ ord = \ ord ( $ letter ) ; if ( 123 === $ ord ) { ++ $ openbrace ; } if ( 125 === $ ord ) { -- $ openbrace ; } if ( ( $ ord >= 65 ) && ( $ ord <= 90 ) && ( 0 === $ openbrace ) ) { $ ret = 1 ; $ found = true ; } elseif ( ( $ ord >= 97 ) && ( $ ord <= 122 ) && ( 0 === $ openbrace ) ) { $ ret = 0 ; $ found = true ; } else { ++ $ i ; } } } else { throw new ProcessorException ( 'Could not determine case on word: ' . $ word ) ; } return $ ret ; }
Case Determination according to the needs of BibTex .
52,848
protected function getCoveredTags ( array $ tags ) { $ matched = [ ] ; foreach ( $ this -> tagCoverageList as $ original ) { $ actual = $ this -> tagSearch ( $ original , $ tags ) ; if ( null !== $ actual ) { $ matched [ ] = $ actual ; } } if ( 'whitelist' === $ this -> tagCoverageStrategy ) { return $ matched ; } return array_values ( array_diff ( $ tags , $ matched ) ) ; }
Calculates which tags are covered .
52,849
protected function renderPageButtons ( ) { $ pageCount = $ this -> pagination -> getPageCount ( ) ; if ( $ pageCount < 2 && $ this -> hideOnSinglePage ) { return '' ; } $ buttons = [ ] ; $ currentPage = $ this -> pagination -> getPage ( ) ; if ( $ this -> nextPageLabel !== false ) { if ( ( $ page = $ currentPage + 1 ) >= $ pageCount - 1 ) { $ page = $ pageCount - 1 ; } $ buttons [ ] = $ this -> renderPageButton ( $ this -> nextPageLabel , $ page , $ this -> nextPageCssClass , $ currentPage >= $ pageCount - 1 ) ; } return Html :: tag ( 'ul' , implode ( "\n" , $ buttons ) , $ this -> options ) ; }
Renders the page buttons .
52,850
private static function updateResponseContentType ( ResponseInterface $ response , Run $ whoops ) : ResponseInterface { if ( 1 !== count ( $ whoops -> getHandlers ( ) ) ) { return $ response ; } $ handler = current ( $ whoops -> getHandlers ( ) ) ; if ( $ handler instanceof PrettyPageHandler ) { return $ response -> withHeader ( 'Content-Type' , 'text/html' ) ; } if ( $ handler instanceof JsonResponseHandler ) { return $ response -> withHeader ( 'Content-Type' , 'application/json' ) ; } if ( $ handler instanceof XmlResponseHandler ) { return $ response -> withHeader ( 'Content-Type' , 'text/xml' ) ; } if ( $ handler instanceof PlainTextHandler ) { return $ response -> withHeader ( 'Content-Type' , 'text/plain' ) ; } return $ response ; }
Returns the content - type for the whoops instance
52,851
protected static function getPreferredFormat ( string $ accept ) : string { if ( static :: isCli ( ) ) { return 'plain' ; } $ formats = [ 'json' => [ 'application/json' ] , 'html' => [ 'text/html' ] , 'xml' => [ 'text/xml' ] , 'plain' => [ 'text/plain' , 'text/css' , 'text/javascript' ] , ] ; foreach ( $ formats as $ format => $ mimes ) { foreach ( $ mimes as $ mime ) { if ( stripos ( $ accept , $ mime ) !== false ) { return $ format ; } } } return 'unknown' ; }
Returns the preferred format used by whoops .
52,852
public function upload ( array $ options ) { if ( substr ( $ options [ 'FileName' ] , 0 , 1 ) === '/' ) { $ options [ 'FileName' ] = ltrim ( $ options [ 'FileName' ] , '/' ) ; } if ( ! isset ( $ options [ 'BucketId' ] ) && isset ( $ options [ 'BucketName' ] ) ) { $ options [ 'BucketId' ] = $ this -> getBucketIdFromName ( $ options [ 'BucketName' ] ) ; } $ response = $ this -> client -> request ( 'POST' , $ this -> apiUrl . '/b2_get_upload_url' , [ 'headers' => [ 'Authorization' => $ this -> authToken ] , 'json' => [ 'bucketId' => $ options [ 'BucketId' ] ] ] ) ; $ uploadEndpoint = $ response [ 'uploadUrl' ] ; $ uploadAuthToken = $ response [ 'authorizationToken' ] ; if ( is_resource ( $ options [ 'Body' ] ) ) { $ context = hash_init ( 'sha1' ) ; hash_update_stream ( $ context , $ options [ 'Body' ] ) ; $ hash = hash_final ( $ context ) ; $ size = fstat ( $ options [ 'Body' ] ) [ 'size' ] ; rewind ( $ options [ 'Body' ] ) ; } else { $ hash = sha1 ( $ options [ 'Body' ] ) ; $ size = mb_strlen ( $ options [ 'Body' ] ) ; } if ( ! isset ( $ options [ 'FileLastModified' ] ) ) { $ options [ 'FileLastModified' ] = round ( microtime ( true ) * 1000 ) ; } if ( ! isset ( $ options [ 'FileContentType' ] ) ) { $ options [ 'FileContentType' ] = 'b2/x-auto' ; } $ response = $ this -> client -> request ( 'POST' , $ uploadEndpoint , [ 'headers' => [ 'Authorization' => $ uploadAuthToken , 'Content-Type' => $ options [ 'FileContentType' ] , 'Content-Length' => $ size , 'X-Bz-File-Name' => $ options [ 'FileName' ] , 'X-Bz-Content-Sha1' => $ hash , 'X-Bz-Info-src_last_modified_millis' => $ options [ 'FileLastModified' ] ] , 'body' => $ options [ 'Body' ] ] ) ; return new File ( $ response [ 'fileId' ] , $ response [ 'fileName' ] , $ response [ 'contentSha1' ] , $ response [ 'contentLength' ] , $ response [ 'contentType' ] , $ response [ 'fileInfo' ] ) ; }
Uploads a file to a bucket and returns a File object .
52,853
protected function getBucketIdFromName ( $ name ) { $ buckets = $ this -> listBuckets ( ) ; foreach ( $ buckets as $ bucket ) { if ( $ bucket -> getName ( ) === $ name ) { return $ bucket -> getId ( ) ; } } return null ; }
Maps the provided bucket name to the appropriate bucket ID .
52,854
protected function getBucketNameFromId ( $ id ) { $ buckets = $ this -> listBuckets ( ) ; foreach ( $ buckets as $ bucket ) { if ( $ bucket -> getId ( ) === $ id ) { return $ bucket -> getName ( ) ; } } return null ; }
Maps the provided bucket ID to the appropriate bucket name .
52,855
function setClientCert ( $ crtFile , $ keyFile ) { if ( ! file_exists ( $ crtFile ) ) { $ this -> debugMessage ( "Client certificate not found" ) ; return ; } if ( ! file_exists ( $ keyFile ) ) { $ this -> debugMessage ( "Client key not found" ) ; return ; } $ this -> clientCrt = $ crtFile ; $ this -> clientKey = $ keyFile ; }
Sets client crt and key files for client - side authentication
52,856
function eventLoop ( ) { if ( $ this -> socket == null ) { return ; } if ( feof ( $ this -> socket ) ) { stream_socket_shutdown ( $ this -> socket , STREAM_SHUT_RDWR ) ; $ this -> socket = null ; return ; } $ byte = $ this -> readBytes ( 1 , true ) ; if ( strlen ( $ byte ) > 0 ) { $ cmd = ord ( $ byte ) ; $ bytes = 0 ; $ multiplier = 1 ; do { $ t_byte = ord ( $ this -> readBytes ( 1 , true ) ) ; $ bytes += ( $ t_byte & 127 ) * $ multiplier ; $ multiplier *= 128 ; if ( $ multiplier > 128 * 128 * 128 ) { break ; } } while ( ( $ t_byte & 128 ) != 0 ) ; $ payload = "" ; if ( $ bytes > 0 ) $ payload = $ this -> readBytes ( $ bytes , false ) ; switch ( $ cmd & 0xf0 ) { case 0xd0 : $ this -> debugMessage ( "Ping response received" ) ; break ; case 0x30 : $ msg_qos = ( $ cmd & 0x06 ) >> 1 ; $ this -> processMessage ( $ payload , $ msg_qos ) ; break ; case 0x40 : $ msg_qos = ( $ cmd & 0x06 ) >> 1 ; $ this -> processPubAck ( $ payload , $ msg_qos ) ; break ; } $ this -> timeSincePingReq = time ( ) ; $ this -> timeSincePingResp = time ( ) ; } if ( $ this -> timeSincePingReq < ( time ( ) - $ this -> keepAlive ) ) { $ this -> debugMessage ( "Nothing received for a while, pinging.." ) ; $ this -> sendPing ( ) ; } if ( $ this -> timeSincePingResp < ( time ( ) - ( $ this -> keepAlive * 2 ) ) ) { $ this -> debugMessage ( "Not seen a package in a while, reconnecting.." ) ; stream_socket_shutdown ( $ this -> socket , STREAM_SHUT_RDWR ) ; $ this -> socket = null ; } }
Loop to process data packets
52,857
function subscribe ( $ topics ) { if ( ! $ this -> socket ) { $ this -> debugMessage ( "Subscribe failed, because socket is not connected" ) ; return false ; } $ cnt = 2 ; $ payload = chr ( $ this -> packet >> 8 ) . chr ( $ this -> packet & 0xff ) ; if ( ! is_array ( $ topics ) && is_string ( $ topics ) ) { $ topics = [ $ topics => [ 'qos' => 1 ] ] ; } elseif ( ! is_array ( $ topics ) ) { return false ; } $ numOfTopics = 0 ; foreach ( $ topics as $ topic => $ data ) { if ( ! is_array ( $ data ) || ! isset ( $ data [ 'qos' ] ) ) { continue ; } $ payload .= $ this -> convertString ( $ topic , $ cnt ) ; $ payload .= chr ( $ data [ 'qos' ] ) ; $ cnt ++ ; $ this -> topics [ $ topic ] = $ data ; $ numOfTopics ++ ; } if ( $ numOfTopics == 0 ) { return false ; } $ header = chr ( 0x82 ) . chr ( $ cnt ) ; fwrite ( $ this -> socket , $ header , 2 ) ; fwrite ( $ this -> socket , $ payload , $ cnt ) ; $ resp_head = $ this -> readBytes ( 2 , false ) ; if ( strlen ( $ resp_head ) != 2 || ord ( $ resp_head { 0 } ) != 0x90 ) { $ this -> debugMessage ( "Invalid SUBACK packet received (stage 1)" ) ; return false ; } $ bytes = ord ( $ resp_head { 1 } ) ; $ resp_body = $ this -> readBytes ( $ bytes , false ) ; if ( strlen ( $ resp_body ) < 2 ) { $ this -> debugMessage ( "Invalid SUBACK packet received (stage 2)" ) ; return false ; } $ package_id = ( ord ( $ resp_body { 0 } ) << 8 ) + ord ( $ resp_body { 1 } ) ; if ( $ this -> packet != $ package_id ) { $ this -> debugMessage ( "SUBACK packet received for wrong message" ) ; return false ; } $ this -> packet ++ ; return true ; }
Subscribe to given MQTT topics
52,858
function close ( ) { if ( ! $ this -> socket ) { return ; } $ this -> sendDisconnect ( ) ; stream_socket_shutdown ( $ this -> socket , STREAM_SHUT_RDWR ) ; $ this -> socket = null ; }
Closes connection to server by first sending DISCONNECT packet and then closing the stream socket
52,859
function publish ( $ topic , $ message , $ qos , $ retain = 0 ) { if ( ! $ this -> socket ) { $ this -> debugMessage ( "Packet NOT sent, socket not connected! (QoS: " . $ qos . " ; topic: " . $ topic . " ; msg: " . $ message . ")" , 2 ) ; return false ; } if ( ( $ qos != 0 && $ qos != 1 ) || ( $ retain != 0 && $ retain != 1 ) ) { $ this -> debugMessage ( "Packet NOT sent, invalid qos/retain value (QoS: " . $ qos . " ; topic: " . $ topic . " ; msg: " . $ message . ")" , 2 ) ; return false ; } $ bytes = 0 ; $ payload = $ this -> convertString ( $ topic , $ bytes ) ; if ( $ qos > 0 ) { $ payload .= chr ( $ this -> packet >> 8 ) . chr ( $ this -> packet & 0xff ) ; $ bytes += 2 ; } $ payload .= $ message ; $ bytes += strlen ( $ message ) ; $ header = $ this -> createHeader ( 0x30 + ( $ qos << 1 ) + $ retain , $ bytes ) ; fwrite ( $ this -> socket , $ header , strlen ( $ header ) ) ; fwrite ( $ this -> socket , $ payload , $ bytes ) ; if ( $ qos == 1 ) { $ this -> messageQueue [ $ this -> packet ] = [ "topic" => $ topic , "message" => $ message , "qos" => $ qos , "retain" => $ retain , "time" => time ( ) , "attempt" => 1 ] ; } $ this -> debugMessage ( "Packet sent (QoS: " . $ qos . " ; topic: " . $ topic . " ; bytes: " . $ bytes . " ; msg: " . $ message . ")" , 2 ) ; $ this -> packet ++ ; return true ; }
Publish message to server
52,860
private function processPubAck ( $ payload , $ qos ) { if ( strlen ( $ payload ) < 2 ) { $ this -> debugMessage ( "Malformed PUBACK package received" ) ; return false ; } $ package_id = ( ord ( $ payload { 0 } ) << 8 ) + ord ( $ payload { 1 } ) ; if ( ! isset ( $ this -> messageQueue [ $ package_id ] ) ) { $ this -> debugMessage ( "Received PUBACK for package we didn't sent?" ) ; return false ; } unset ( $ this -> messageQueue [ $ package_id ] ) ; }
Process puback messages sent by server
52,861
private function processMessage ( $ msg , $ qos ) { $ tlen = ( ord ( $ msg { 0 } ) << 8 ) + ord ( $ msg { 1 } ) ; $ msg_topic = substr ( $ msg , 2 , $ tlen ) ; $ msg_id = null ; if ( $ qos == 0 ) { $ msg = substr ( $ msg , $ tlen + 2 ) ; } else { $ msg_id = substr ( $ msg , $ tlen + 2 , 2 ) ; $ msg = substr ( $ msg , $ tlen + 4 ) ; } $ found = false ; foreach ( $ this -> topics as $ topic => $ data ) { $ t_topic = str_replace ( "+" , "[^/]*" , $ topic ) ; $ t_topic = str_replace ( "/" , "\/" , $ t_topic ) ; $ t_topic = str_replace ( "$" , "\$" , $ t_topic ) ; $ t_topic = str_replace ( "#" , ".*" , $ t_topic ) ; if ( ! preg_match ( "/^" . $ t_topic . "$/" , $ msg_topic ) ) { continue ; } $ found = true ; $ this -> debugMessage ( "Packet received (QoS: " . $ qos . " ; topic: " . $ msg_topic . " ; msg: " . $ msg . ")" , 2 ) ; if ( isset ( $ data [ "function" ] ) && is_callable ( $ data [ "function" ] ) ) { call_user_func ( $ data [ "function" ] , $ msg_topic , $ msg , $ qos ) ; } } if ( ! $ found ) { $ this -> debugMessage ( "Package received, but it doesn't match subscriptions" ) ; } if ( $ qos == 1 ) { $ this -> debugMessage ( "Packet with QoS 1 received, sending PUBACK" ) ; $ payload = chr ( 0x40 ) . chr ( 0x02 ) . $ msg_id ; fwrite ( $ this -> socket , $ payload , 4 ) ; } if ( $ qos == 2 ) { $ this -> debugMessage ( "Packet with QoS 2 received, but feature is not implemented" ) ; } }
Process publish messages sent by server
52,862
private function createHeader ( $ cmd , $ bytes ) { $ retval = chr ( $ cmd ) ; $ bytes_left = $ bytes ; do { $ byte = $ bytes_left % 128 ; $ bytes_left >>= 7 ; if ( $ bytes_left > 0 ) { $ byte = $ byte | 0x80 ; } $ retval .= chr ( $ byte ) ; } while ( $ bytes_left > 0 ) ; return $ retval ; }
Create MQTT header with command and length
52,863
private function convertString ( $ data , & $ cnt ) { $ len = strlen ( $ data ) ; $ cnt += $ len + 2 ; $ retval = chr ( $ len >> 8 ) . chr ( $ len & 0xff ) . $ data ; return $ retval ; }
Writes given string to MQTT string format
52,864
private function readBytes ( $ bytes , $ noBuffer ) { if ( ! $ this -> socket ) { return "" ; } if ( $ noBuffer ) { return fread ( $ this -> socket , $ bytes ) ; } $ bytes_left = $ bytes ; $ retval = "" ; while ( ! feof ( $ this -> socket ) && $ bytes_left > 0 ) { $ res = fread ( $ this -> socket , $ bytes_left ) ; $ retval .= $ res ; $ bytes_left -= strlen ( $ res ) ; } return $ retval ; }
Read x bytes from socket
52,865
private function sendPing ( ) { $ this -> timeSincePingReq = time ( ) ; $ payload = chr ( 0xc0 ) . chr ( 0x00 ) ; fwrite ( $ this -> socket , $ payload , 2 ) ; $ this -> debugMessage ( "PING sent" ) ; }
Sends PINGREQ packet to server
52,866
private function sendDisconnect ( ) { if ( ! $ this -> socket || feof ( $ this -> socket ) ) return ; $ payload = chr ( 0xe0 ) . chr ( 0x00 ) ; fwrite ( $ this -> socket , $ payload , 2 ) ; $ this -> debugMessage ( "DISCONNECT sent" ) ; }
Sends DISCONNECT packet to server
52,867
public function backoff ( ) { $ this -> currentDelayIncrement ++ ; $ this -> currentDelay = $ this -> fibanocci ( $ this -> currentDelayIncrement ) ; if ( $ this -> currentDelay > $ this -> maxDelay ) { $ this -> currentDelay = $ this -> maxDelay ; } Utils :: debug ( [ 'operation' => 'backoff' , 'seconds' => $ this -> currentDelay ] ) ; sleep ( $ this -> currentDelay ) ; }
Perform the backoff . Sleep the number of seconds for the current delay .
52,868
private function fibanocci ( $ n , $ a = null , $ b = null ) { $ a = ( $ a !== null ) ? $ a : $ this -> initialDelay ; $ b = ( $ b !== null ) ? $ b : $ this -> initialDelay ; if ( $ n ) { return $ this -> fibanocci ( $ n - 1 , $ b , $ a + $ b ) ; } else { return $ a ; } }
Run Fibanocci from our initial delay
52,869
public function view ( UserPolicy $ user , Task $ task ) { if ( $ user -> canDo ( 'task.task.view' ) && $ user -> isAdmin ( ) ) { return true ; } return $ user -> id == $ task -> user_id && get_class ( $ user ) === $ task -> user_type ; }
Determine if the given user can view the task .
52,870
public function verify ( UserPolicy $ user , Task $ task ) { if ( $ user -> canDo ( 'task.task.verify' ) && $ user -> isAdmin ( ) ) { return true ; } return false ; }
Determine if the given user can verify the given task .
52,871
public function index ( TaskRequest $ request ) { if ( $ this -> response -> typeIs ( 'json' ) ) { $ pageLimit = $ request -> input ( 'pageLimit' ) ; $ data = $ this -> repository -> setPresenter ( \ Litepie \ Task \ Repositories \ Presenter \ TaskListPresenter :: class ) -> getDataTable ( $ pageLimit ) ; return $ this -> response -> data ( $ data ) -> output ( ) ; } $ tasks = $ this -> repository -> paginate ( ) ; return $ this -> response -> title ( trans ( 'task::task.names' ) ) -> view ( 'task::task.index' , true ) -> data ( compact ( 'tasks' ) ) -> output ( ) ; }
Display a list of task .
52,872
public function show ( TaskRequest $ request , Task $ task ) { if ( $ task -> exists ) { $ view = 'task::task.show' ; } else { $ view = 'task::task.new' ; } return $ this -> response -> title ( trans ( 'app.view' ) . ' ' . trans ( 'task::task.name' ) ) -> data ( compact ( 'task' ) ) -> view ( $ view , true ) -> output ( ) ; }
Display task .
52,873
public function edit ( TaskRequest $ request , Task $ task ) { return $ this -> response -> title ( trans ( 'app.edit' ) . ' ' . trans ( 'task::task.name' ) ) -> view ( 'task::task.edit' , true ) -> data ( compact ( 'task' ) ) -> output ( ) ; }
Show task for editing .
52,874
public function update ( TaskRequest $ request , Task $ task ) { try { $ attributes = $ request -> all ( ) ; $ task -> update ( $ attributes ) ; return $ this -> response -> message ( trans ( 'messages.success.updated' , [ 'Module' => trans ( 'task::task.name' ) ] ) ) -> code ( 204 ) -> status ( 'success' ) -> url ( guard_url ( 'task/task/status?search[status]=' . $ task -> status ) ) -> redirect ( ) ; } catch ( Exception $ e ) { return $ this -> response -> message ( $ e -> getMessage ( ) ) -> code ( 400 ) -> status ( 'error' ) -> url ( guard_url ( 'task/task/status?search[status]=' . $ task -> status ) ) -> redirect ( ) ; } }
Update the task .
52,875
public function destroy ( TaskRequest $ request , Task $ task ) { try { $ task -> delete ( ) ; return $ this -> response -> message ( trans ( 'messages.success.deleted' , [ 'Module' => trans ( 'task::task.name' ) ] ) ) -> code ( 202 ) -> status ( 'success' ) -> url ( guard_url ( 'task/task' ) ) -> redirect ( ) ; } catch ( Exception $ e ) { return $ this -> response -> message ( $ e -> getMessage ( ) ) -> code ( 400 ) -> status ( 'error' ) -> url ( guard_url ( 'task/task/' . $ task -> getRouteKey ( ) ) ) -> redirect ( ) ; } }
Remove the task .
52,876
public function count ( $ type = 'admin.web' ) { return $ this -> task -> scopeQuery ( function ( $ query ) use ( $ type ) { return $ query -> whereUserId ( user_id ( $ type ) ) -> whereUserType ( user_type ( $ type ) ) ; } ) -> count ( ) ; }
Returns count of tasks .
52,877
public function prependText ( $ text ) { $ this -> owner -> PrependedText = $ text ; $ this -> owner -> addExtraClass ( 'form-control' ) ; return $ this -> owner ; }
Adds text immediately to the left abut the form field
52,878
public function appendText ( $ text ) { $ this -> owner -> AppendedText = $ text ; $ this -> owner -> addExtraClass ( 'form-control' ) ; return $ this -> owner ; }
Adds text immediately to the right abut the form field
52,879
public function ColumnClasses ( ) { $ classes = array ( ) ; foreach ( $ this -> columnCounts as $ colName => $ val ) { $ classes [ ] = "col-{$colName}-{$val}" ; } return implode ( " " , $ classes ) ; }
A list of classes for the column divs
52,880
public function FieldHolder ( $ attributes = array ( ) ) { Requirements :: javascript ( BOOTSTRAP_FORMS_DIR . "/javascript/tinymce/jscripts/tiny_mce/jquery.tinymce.js" ) ; Requirements :: javascript ( BOOTSTRAP_FORMS_DIR . "/javascript/tinymce/jscripts/tiny_mce/tiny_mce.js" ) ; if ( ! $ this -> getAttribute ( 'data-buttons' ) ) { $ this -> setButtons ( self :: $ default_buttons ) ; } if ( ! $ this -> getAttribute ( 'data-blockformats' ) ) { $ this -> setBlockFormats ( self :: $ default_blockformats ) ; } $ this -> addExtraClass ( 'wysiwyg' ) ; return parent :: FieldHolder ( $ attributes ) ; }
Builds the form field includes JavaScript and sets defaults
52,881
public function HolderAttributes ( ) { $ ret = "" ; foreach ( $ this -> holderAttributes as $ k => $ v ) { $ ret .= "$k=\"" . Convert :: raw2att ( $ v ) . "\" " ; } return $ ret ; }
Returns the list of attributes suitable for an HTML tag
52,882
public function GridLabelClass ( ) { return ( trim ( $ this -> gridLabelClass ) != '' ) ? $ this -> gridLabelClass : $ this -> owner -> form -> gridLabelClass ; }
returns Grid label class to be used in templates
52,883
public function GridInputClass ( ) { return ( trim ( $ this -> gridInputClass ) != '' ) ? $ this -> gridInputClass : $ this -> owner -> form -> gridInputClass ; }
returns Grid input class to be used in templates
52,884
private function loadErrorMessage ( ) { if ( $ this -> owner -> message ) { $ this -> addHolderClass ( "error" ) ; $ this -> addHelpText ( $ this -> owner -> message ) ; } }
checks for error messages in owner form field adds error class to holder and loads error message as helptext
52,885
public function bootstrapify ( ) { foreach ( $ this -> owner as $ f ) { $ sng = Injector :: inst ( ) -> get ( $ f -> class , true , [ 'dummy' , '' ] ) ; if ( isset ( $ this -> ignores [ $ f -> getName ( ) ] ) ) continue ; if ( $ f instanceof CompositeField ) { $ f -> getChildren ( ) -> bootstrapify ( ) ; continue ; } if ( $ f instanceof TabSet ) { $ f -> Tabs ( ) -> bootstrapify ( ) ; } if ( $ f instanceof Tab ) { $ f -> Fields ( ) -> bootstrapify ( ) ; } if ( $ sng -> getFieldHolderTemplate ( ) == $ f -> getFieldHolderTemplate ( ) ) { $ template = "Bootstrap{$f->class}_holder" ; if ( SSViewer :: hasTemplate ( $ template ) ) { $ f -> setFieldHolderTemplate ( $ template ) ; } else { $ f -> setFieldHolderTemplate ( "BootstrapFieldHolder" ) ; } } if ( $ sng -> getTemplate ( ) == $ f -> getTemplate ( ) ) { foreach ( array_reverse ( ClassInfo :: ancestry ( $ f ) ) as $ className ) { $ bootstrapCandidate = "Bootstrap{$className}" ; $ nativeCandidate = $ className ; if ( SSViewer :: hasTemplate ( $ bootstrapCandidate ) ) { $ f -> setTemplate ( $ bootstrapCandidate ) ; break ; } elseif ( SSViewer :: hasTemplate ( $ nativeCandidate ) ) { $ f -> setTemplate ( $ nativeCandidate ) ; break ; } } } } return $ this -> owner ; }
Transforms all fields in the FieldList to use Bootstrap templates
52,886
public function fetchConversationWith ( $ gamertag , $ region , $ sender ) { $ gamertag = trim ( $ gamertag ) ; $ url = 'https://account.xbox.com/' . $ region . '/Messages/UserConversation?senderGamerTag=' . $ sender ; $ key = $ this -> version . ':getMessages.' . $ gamertag ; $ data = $ this -> fetch_url ( $ url ) ; $ doc = new DOMDocument ( ) ; if ( ! empty ( $ sender ) && ! empty ( $ gamertag ) ) { $ doc -> loadHtml ( $ data ) ; $ xpath = new DOMXPath ( $ doc ) ; $ postThumbLinks = $ xpath -> query ( "//div[@class='messageContent']" ) ; $ i = 0 ; $ array = array ( ) ; $ last_sender = "" ; foreach ( $ postThumbLinks as $ link ) { $ body = $ this -> find ( $ link -> ownerDocument -> saveHTML ( $ link ) , '<div class="messageBody">' , '</div>' ) ; $ time = $ this -> find ( $ link -> ownerDocument -> saveHTML ( $ link ) , '<div class="sentDate localTime">' , '</div>' ) ; $ sender = $ this -> find ( $ link -> ownerDocument -> saveHTML ( $ link ) , '<div class="senderGamertag">' , '</div>' ) ; $ array [ $ i ] [ 'message' ] = $ body ; $ array [ $ i ] [ 'time' ] = $ time ; if ( $ sender ) { $ array [ $ i ] [ 'sender' ] = $ sender ; $ last_sender = $ sender ; } else { $ array [ $ i ] [ 'sender' ] = $ last_sender ; } $ i ++ ; } } else { return false ; } return $ array ; }
Fetch conversation with
52,887
public function fetch_friends ( $ gamertag , $ region ) { $ gamertag = trim ( $ gamertag ) ; $ url = 'https://live.xbox.com/' . $ region . '/Friends' ; $ key = $ this -> version . ':friends.' . $ gamertag ; $ data = $ this -> __cache -> fetch ( $ key ) ; $ freshness = 'from cache' ; if ( ! $ data ) { $ data = $ this -> fetch_url ( $ url ) ; $ post_data = '__RequestVerificationToken=' . urlencode ( trim ( $ this -> find ( $ data , '<input name="__RequestVerificationToken" type="hidden" value="' , '" />' ) ) ) ; $ headers = array ( 'X-Requested-With: XMLHttpRequest' , 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' ) ; $ data = $ this -> fetch_url ( 'https://live.xbox.com/' . $ region . '/Friends/List?Gamertag=' . urlencode ( $ gamertag ) , $ url , 10 , $ post_data , $ headers ) ; $ freshness = 'new' ; $ this -> __cache -> store ( $ key , $ data , 3600 ) ; } $ json = json_decode ( $ data , true ) ; if ( ! empty ( $ json [ 'Data' ] ) && $ json [ 'Data' ] [ 'Friends' ] != null ) { $ friends = array ( ) ; $ friends [ 'total' ] = 0 ; $ friends [ 'totalonline' ] = 0 ; $ friends [ 'totaloffline' ] = 0 ; $ i = 0 ; foreach ( $ json [ 'Data' ] [ 'Friends' ] as $ friend ) { $ friends [ 'friends' ] [ $ i ] [ 'gamertag' ] = $ friend [ 'GamerTag' ] ; $ friends [ 'friends' ] [ $ i ] [ 'gamerpic' ] [ 'small' ] = $ friend [ 'GamerTileUrl' ] ; $ friends [ 'friends' ] [ $ i ] [ 'gamerpic' ] [ 'large' ] = $ friend [ 'LargeGamerTileUrl' ] ; $ friends [ 'friends' ] [ $ i ] [ 'gamerscore' ] = $ friend [ 'GamerScore' ] ; $ friends [ 'friends' ] [ $ i ] [ 'online' ] = ( bool ) $ friend [ 'IsOnline' ] ; $ friends [ 'friends' ] [ $ i ] [ 'status' ] = $ friend [ 'Presence' ] ; $ friends [ 'friends' ] [ $ i ] [ 'lastseen' ] = ( int ) substr ( $ friend [ 'LastSeen' ] , 6 , 10 ) ; $ friends [ 'total' ] ++ ; if ( $ friend [ 'IsOnline' ] ) { $ friends [ 'totalonline' ] ++ ; } else { $ friends [ 'totaloffline' ] ++ ; } $ i ++ ; } $ friends [ 'freshness' ] = $ freshness ; return $ friends ; } else { $ this -> error = 503 ; $ this -> __cache -> remove ( $ key ) ; $ this -> force_new_login ( ) ; return false ; } }
Fetch data about a players friends list
52,888
public function fetch_search ( $ query , $ region ) { $ query = trim ( $ query ) ; $ url = 'http://marketplace.xbox.com/' . $ region . '/SiteSearch/xbox/?query=' . urlencode ( $ query ) ; $ key = $ this -> version . ':friends.' . $ query ; $ data = $ this -> __cache -> fetch ( $ key ) ; $ freshness = 'from cache' ; if ( ! $ data ) { $ data = $ this -> fetch_url ( $ url ) ; $ freshness = 'new' ; $ this -> __cache -> store ( $ key , $ data , 3600 ) ; } $ json = json_decode ( $ data , true ) ; if ( $ json [ 'totalEntries' ] >= 1 ) { $ search = array ( ) ; $ search [ 'totalresults' ] = $ json [ 'totalEntries' ] ; $ search [ 'resultslink' ] = 'http://marketplace.xbox.com' . $ json [ 'allResultsUrl' ] ; $ i = 0 ; foreach ( $ json [ 'entries' ] as $ entry ) { $ search [ 'results' ] [ $ i ] [ 'title' ] = $ entry [ 'title' ] ; $ search [ 'results' ] [ $ i ] [ 'parent' ] = $ entry [ 'parentTitle' ] ; $ search [ 'results' ] [ $ i ] [ 'link' ] = 'http://marketplace.xbox.com' . $ entry [ 'detailsUrl' ] ; $ search [ 'results' ] [ $ i ] [ 'image' ] = $ entry [ 'image' ] ; $ search [ 'results' ] [ $ i ] [ 'downloadtype' ] [ 'class' ] = $ entry [ 'downloadTypeClass' ] ; $ search [ 'results' ] [ $ i ] [ 'downloadtype' ] [ 'title' ] = $ entry [ 'downloadTypeText' ] ; $ search [ 'results' ] [ $ i ] [ 'prices' ] [ 'silver' ] = $ entry [ 'prices' ] [ 'silver' ] ; $ search [ 'results' ] [ $ i ] [ 'prices' ] [ 'gold' ] = $ entry [ 'prices' ] [ 'gold' ] ; $ i ++ ; } $ search [ 'freshness' ] = $ freshness ; return $ search ; } else { $ this -> error = 504 ; $ this -> __cache -> remove ( $ key ) ; return false ; } }
Fetch data for a search query
52,889
public function getModifier ( $ key ) { return isset ( $ this -> modifiers [ $ key ] ) ? $ this -> modifiers [ $ key ] : null ; }
Gets a modifier if it is set .
52,890
public function fields ( $ fields ) { if ( ! is_array ( $ fields ) ) { $ fields = func_get_args ( ) ; } $ this -> fields = array_merge ( $ this -> fields , $ fields ) ; return $ this ; }
Set the fields for this node .
52,891
public function asUrl ( $ appSecret = null ) { $ this -> resetCompiledValues ( ) ; if ( $ appSecret ) { $ this -> addAppSecretProofModifier ( $ appSecret ) ; } $ this -> compileModifiers ( ) ; $ this -> compileFields ( ) ; return $ this -> compileUrl ( ) ; }
Compile the final URL as a string .
52,892
private function addAppSecretProofModifier ( $ appSecret ) { $ accessToken = $ this -> getModifier ( static :: PARAM_ACCESS_TOKEN ) ; if ( ! $ accessToken ) { return ; } $ this -> modifiers ( [ static :: PARAM_APP_SECRET_PROOF => hash_hmac ( 'sha256' , $ accessToken , $ appSecret ) , ] ) ; }
Generate an app secret proof modifier based on the app secret & access token .
52,893
public function toEndpoints ( ) { $ endpoints = [ ] ; $ children = $ this -> getChildEdges ( ) ; foreach ( $ children as $ child ) { $ endpoints [ ] = '/' . implode ( '/' , $ child ) ; } return $ endpoints ; }
Convert the nested query into an array of endpoints .
52,894
public function getChildEdges ( ) { $ edges = [ ] ; $ hasChildren = false ; foreach ( $ this -> fields as $ v ) { if ( $ v instanceof GraphEdge ) { $ hasChildren = true ; $ children = $ v -> getChildEdges ( ) ; foreach ( $ children as $ childEdges ) { $ edges [ ] = array_merge ( [ $ this -> name ] , $ childEdges ) ; } } } if ( ! $ hasChildren ) { $ edges [ ] = [ $ this -> name ] ; } return $ edges ; }
Arrange the child edge nodes into a multidimensional array .
52,895
public function compileModifiers ( ) { if ( count ( $ this -> modifiers ) === 0 ) { return ; } $ processed_modifiers = [ ] ; foreach ( $ this -> modifiers as $ k => $ v ) { $ processed_modifiers [ ] = urlencode ( $ k ) . '(' . urlencode ( $ v ) . ')' ; } $ this -> compiledValues [ ] = '.' . implode ( '.' , $ processed_modifiers ) ; }
Compile the modifier values .
52,896
public function compileUrl ( ) { $ append = '' ; if ( count ( $ this -> compiledValues ) > 0 ) { $ append = implode ( '' , $ this -> compiledValues ) ; } return $ this -> name . $ append ; }
Compile the the full URL .
52,897
public function fields ( $ fields ) { if ( ! is_array ( $ fields ) ) { $ fields = func_get_args ( ) ; } $ this -> graphNode -> fields ( $ fields ) ; return $ this ; }
Alias to method on GraphNode .
52,898
public function asEndpoint ( ) { $ graphVersionPrefix = '' ; if ( $ this -> graphVersion ) { $ graphVersionPrefix = '/' . $ this -> graphVersion ; } return $ graphVersionPrefix . $ this -> graphNode -> asUrl ( $ this -> appSecret ) ; }
Return the generated request as a URL endpoint sans the hostname .
52,899
public function prepareRequestPathForResourceMethod ( $ resourceMethod , $ id , array $ resourceMethodConfiguration ) : string { $ requestPathFormat = $ this -> calculateRequestPathFormat ( $ resourceMethod , $ resourceMethodConfiguration ) ; switch ( $ resourceMethod ) { case ResourceMethodEnum :: GET_ALL : case ResourceMethodEnum :: CREATE : case ResourceMethodEnum :: UPDATE_DEFAULT : IdValidator :: assertIsNull ( $ id ) ; $ path = $ requestPathFormat ; break ; case ResourceMethodEnum :: GET_BY_IDS : IdValidator :: assertIsValidIdArray ( $ id ) ; $ path = sprintf ( $ requestPathFormat , implode ( ',' , $ id ) ) ; break ; case ResourceMethodEnum :: GET_ALL_FOR_FOLDER : case ResourceMethodEnum :: GET_ALL_FOR_TASK : case ResourceMethodEnum :: GET_ALL_FOR_CONTACT : case ResourceMethodEnum :: GET_ALL_FOR_TIMELOG_CATEGORY : case ResourceMethodEnum :: CREATE_FOR_FOLDER : case ResourceMethodEnum :: CREATE_FOR_TASK : case ResourceMethodEnum :: GET_BY_ID : case ResourceMethodEnum :: UPDATE : case ResourceMethodEnum :: DELETE : case ResourceMethodEnum :: COPY : case ResourceMethodEnum :: DOWNLOAD : case ResourceMethodEnum :: DOWNLOAD_PREVIEW : case ResourceMethodEnum :: GET_PUBLIC_URL : case ResourceMethodEnum :: UPLOAD_FOR_FOLDER : case ResourceMethodEnum :: UPLOAD_FOR_TASK : IdValidator :: assertIsValidIdString ( $ id ) ; $ path = sprintf ( $ requestPathFormat , $ id ) ; break ; default : throw new \ InvalidArgumentException ( sprintf ( '"%s" resource method not yet supported' , $ resourceMethod ) ) ; } return $ path ; }
Combine ResourceMethodConfiguration ResourceMethod and optional Id to retrieve correct resource path for request .