Dataset Viewer
Auto-converted to Parquet Duplicate
idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
0
function sendDownloadConfirmation ( $ ticket ) { $ sendDownloadConfirmationRequest = new sendDownloadConfirmation ( ) ; $ sendDownloadConfirmationRequest -> targetId = $ ticket ; return $ this -> targetService -> sendDownloadConfirmation ( $ sendDownloadConfirmationRequest ) -> return ; }
Sends confirmation that the target resources was downloaded successfully by the customer .
1
function uploadTranslatable ( $ document ) { if ( ! isset ( $ this -> submission ) || ! isset ( $ this -> submission -> ticket ) ) { throw new Exception ( "Submission not initialized." ) ; } $ this -> _validateDocument ( $ document ) ; $ documentInfo = $ document -> getDocumentInfo ( $ this -> submission ) ; $ resourceInfo = $ document -> getResourceInfo ( ) ; $ submitDocumentWithBinaryResourceRequest = new submitDocumentWithBinaryResource ( ) ; $ submitDocumentWithBinaryResourceRequest -> documentInfo = $ documentInfo ; $ submitDocumentWithBinaryResourceRequest -> resourceInfo = $ resourceInfo ; $ submitDocumentWithBinaryResourceRequest -> data = $ document -> data ; $ documentTicket = $ this -> documentService -> submitDocumentWithBinaryResource ( $ submitDocumentWithBinaryResourceRequest ) -> return ; if ( isset ( $ documentTicket ) ) { $ this -> submission -> ticket = $ documentTicket -> submissionTicket ; } return $ documentTicket -> ticketId ; }
Uploads the document to project director for translation
2
function uploadTranslationKit ( $ fileName , $ data ) { $ result = "" ; $ resourceInfo = new ResourceInfo ( ) ; $ resourceInfo -> name = $ fileName ; $ resourceInfo -> size = strlen ( $ data ) ; $ workflowRequestTicket = $ this -> workflowService -> upload ( $ resourceInfo , $ data ) -> return ; $ uploadFinished = false ; while ( ! $ uploadFinished ) { sleep ( DELAY_TIME ) ; $ uploadActionResult = $ this -> workflowService -> checkUploadAction ( $ workflowRequestTicket ) ; $ uploadFinished = $ uploadActionResult -> processingFinished -> booleanValue ; if ( $ uploadFinished && isset ( $ uploadActionResult -> messages ) ) { foreach ( $ uploadActionResult -> messages as & $ message ) { $ result = $ result + $ message + ";" ; } } } return $ result ; }
Uploads preliminary delivery file to project director
3
public function renderAsBreadcrumb ( $ menu , array $ options = [ ] ) { $ options = array_merge ( [ 'template' => $ this -> defaultTemplate ] , $ options ) ; if ( ( ! is_array ( $ menu ) ) && ( ! $ menu instanceof ItemInterface ) ) { $ path = [ ] ; if ( is_array ( $ menu ) ) { if ( empty ( $ menu ) ) { throw new \ InvalidArgumentException ( 'The array cannot be empty' ) ; } $ path = $ menu ; $ menu = array_shift ( $ path ) ; } $ menu = $ this -> menuHelper -> get ( $ menu , $ path ) ; } $ treeIterator = new \ RecursiveIteratorIterator ( new RecursiveItemIterator ( new \ ArrayIterator ( [ $ menu ] ) ) , \ RecursiveIteratorIterator :: SELF_FIRST ) ; $ itemFilterIterator = new CurrentItemFilterIterator ( $ treeIterator , $ this -> matcher ) ; $ itemFilterIterator -> rewind ( ) ; $ current = $ itemFilterIterator -> current ( ) ; $ manipulator = new MenuManipulator ( ) ; if ( $ current instanceof ItemInterface ) { $ breadcrumbs = $ manipulator -> getBreadcrumbsArray ( $ current ) ; } else { $ breadcrumbs = $ manipulator -> getBreadcrumbsArray ( $ menu ) ; } if ( ! $ options [ 'template' ] instanceof \ Twig_Template ) { $ options [ 'template' ] = $ this -> twig -> loadTemplate ( $ options [ 'template' ] ) ; } return $ options [ 'template' ] -> renderBlock ( 'root' , [ 'breadcrumbs' => $ breadcrumbs , 'options' => $ options ] ) ; }
Render an array or KNP menu as foundation breadcrumb .
4
protected function handleResponse ( $ response ) { $ ch = $ this -> ch ; if ( false !== $ response ) { $ curlInfo = curl_getinfo ( $ ch ) ; if ( $ this -> getCurlOption ( CURLOPT_HEADER ) ) { if ( false !== stripos ( $ response , "HTTP/1.1 200 Connection established\r\n\r\n" ) ) { $ response = str_ireplace ( "HTTP/1.1 200 Connection established\r\n\r\n" , '' , $ response ) ; } $ this -> responseHeader = trim ( substr ( $ response , 0 , $ curlInfo [ 'header_size' ] ) ) ; $ this -> responseText = substr ( $ response , $ curlInfo [ 'header_size' ] ) ; } else { $ this -> responseText = $ response ; } $ statusCode = $ curlInfo [ 'http_code' ] ; $ isSuccess = $ statusCode >= 200 && $ statusCode < 300 || $ statusCode === 304 ; if ( $ isSuccess ) { $ this -> response = $ this -> parseResponse ( $ this -> responseText , $ exception ) ; if ( ! $ exception ) { $ this -> result = true ; $ this -> success && call_user_func ( $ this -> success , $ this -> response , $ this ) ; } else { $ this -> triggerError ( 'parser' , $ exception ) ; } } else { if ( $ this -> responseHeader ) { preg_match ( '/[\d]{3} (.+?)\r/' , $ this -> responseHeader , $ matches ) ; $ statusText = $ matches [ 1 ] ; } else { $ statusText = 'HTTP request error' ; } $ exception = new \ ErrorException ( $ statusText , $ statusCode + 1000 ) ; $ this -> triggerError ( 'http' , $ exception ) ; } } else { $ exception = new \ ErrorException ( curl_error ( $ ch ) , curl_errno ( $ ch ) ) ; $ this -> triggerError ( 'curl' , $ exception ) ; } }
Parse response text
5
protected function triggerError ( $ status , \ ErrorException $ exception ) { $ this -> result = false ; $ this -> errorStatus = $ status ; $ this -> errorException = $ exception ; $ this -> error && call_user_func ( $ this -> error , $ this , $ status , $ exception ) ; }
Trigger error callback
6
protected function parseResponse ( $ data , & $ exception ) { switch ( $ this -> dataType ) { case 'json' : case 'jsonObject' : $ result = json_decode ( $ data , $ this -> dataType === 'json' ) ; if ( null === $ result && json_last_error ( ) != JSON_ERROR_NONE ) { $ exception = new \ ErrorException ( 'JSON parsing error, the data is ' . $ data , json_last_error ( ) ) ; } break ; case 'xml' : case 'serialize' : $ methods = array ( 'xml' => 'simplexml_load_string' , 'serialize' => 'unserialize' , ) ; $ result = @ $ methods [ $ this -> dataType ] ( $ data ) ; if ( false === $ result && $ e = error_get_last ( ) ) { $ exception = new \ ErrorException ( $ e [ 'message' ] , $ e [ 'type' ] , 0 , $ e [ 'file' ] , $ e [ 'line' ] ) ; } break ; case 'query' : parse_str ( $ data , $ result ) ; break ; case 'text' : default : $ result = $ data ; break ; } return $ result ; }
Parse response data by specified type
7
public function getCurlOption ( $ option ) { return isset ( $ this -> curlOptions [ $ option ] ) ? $ this -> curlOptions [ $ option ] : null ; }
Returns an option value of the current cURL handle
8
public function getResponseHeader ( $ name = null , $ first = true ) { if ( is_null ( $ name ) ) { return $ this -> responseHeader ; } $ name = strtoupper ( $ name ) ; $ headers = $ this -> getResponseHeaders ( ) ; if ( ! isset ( $ headers [ $ name ] ) ) { return $ first ? null : array ( ) ; } else { return $ first ? current ( $ headers [ $ name ] ) : $ headers [ $ name ] ; } }
Returns request header value
9
public function getResponseHeaders ( ) { if ( ! is_array ( $ this -> responseHeaders ) ) { $ this -> responseHeaders = array ( ) ; foreach ( explode ( "\n" , $ this -> responseHeader ) as $ line ) { $ line = explode ( ':' , $ line , 2 ) ; $ name = strtoupper ( $ line [ 0 ] ) ; $ value = isset ( $ line [ 1 ] ) ? trim ( $ line [ 1 ] ) : null ; $ this -> responseHeaders [ $ name ] [ ] = $ value ; } } return $ this -> responseHeaders ; }
Returns response headers array
10
public function getResponseCookie ( $ name ) { $ cookies = $ this -> getResponseCookies ( ) ; return isset ( $ cookies [ $ name ] ) ? $ cookies [ $ name ] : null ; }
Returns the cookie value by specified name
11
public function get ( $ url , $ data = array ( ) , $ dataType = null ) { return $ this -> processMethod ( $ url , $ data , $ dataType , 'GET' ) ; }
Execute a GET method request
12
public function post ( $ url , $ data = array ( ) , $ dataType = null ) { return $ this -> processMethod ( $ url , $ data , $ dataType , 'POST' ) ; }
Execute a POST method request
13
public function put ( $ url , $ data = array ( ) , $ dataType = null ) { return $ this -> processMethod ( $ url , $ data , $ dataType , 'PUT' ) ; }
Execute a PUT method request
14
public function delete ( $ url , $ data = array ( ) , $ dataType = null ) { return $ this -> processMethod ( $ url , $ data , $ dataType , 'DELETE' ) ; }
Execute a DELETE method request
15
public function patch ( $ url , $ data = array ( ) , $ dataType = null ) { return $ this -> processMethod ( $ url , $ data , $ dataType , 'PATCH' ) ; }
Execute a PATCH method request
16
protected function processMethod ( $ url , $ data , $ dataType , $ method ) { return $ this -> __invoke ( array ( 'url' => $ url , 'method' => $ method , 'dataType' => $ dataType , 'data' => $ data ) ) ; }
Execute a specified method request
17
public function getCurlInfo ( $ option = null ) { return $ option ? curl_getinfo ( $ this -> ch , $ option ) : curl_getinfo ( $ this -> ch ) ; }
Get information from curl
18
public function setOption ( $ name , $ value = null ) { if ( is_array ( $ name ) ) { foreach ( $ name as $ k => $ v ) { $ this -> setOption ( $ k , $ v ) ; } return $ this ; } if ( method_exists ( $ this , $ method = 'set' . $ name ) ) { return $ this -> $ method ( $ value ) ; } else { $ this -> $ name = $ value ; return $ this ; } }
Set option property value
19
public function setColsCount ( $ numCols , $ toCreate = true , $ width = NULL ) { if ( $ toCreate == true ) { $ count = $ this -> count ( ) ; if ( $ count == 0 || $ this -> hasOnlyCols ( $ count ) ) { for ( $ i = $ count ; $ i < $ numCols ; $ i ++ ) { $ this -> addItem ( new HtmlGridCol ( "col-" . $ this -> identifier . "-" . $ i , $ width ) ) ; } } else { for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ this -> getItem ( $ i ) -> setColsCount ( $ numCols ) ; } } } return $ this ; }
Defines the number of columns in the grid
20
protected function buildUrl ( $ path ) { $ path = str_replace ( '%2F' , '/' , $ path ) ; $ path = str_replace ( ' ' , '%20' , $ path ) ; return rtrim ( $ this -> base , '/' ) . '/' . $ path ; }
Returns the URL to perform an HTTP request .
21
protected function head ( $ path ) { $ defaults = stream_context_get_options ( stream_context_get_default ( ) ) ; $ options = $ this -> context ; if ( $ this -> supportsHead ) { $ options [ 'http' ] [ 'method' ] = 'HEAD' ; } stream_context_set_default ( $ options ) ; $ headers = get_headers ( $ this -> buildUrl ( $ path ) , 1 ) ; stream_context_set_default ( $ defaults ) ; if ( $ headers === false || strpos ( $ headers [ 0 ] , ' 200' ) === false ) { return false ; } return array_change_key_case ( $ headers ) ; }
Performs a HEAD request .
22
protected function parseMetadata ( $ path , array $ headers ) { $ metadata = [ 'path' => $ path , 'visibility' => $ this -> visibility , 'mimetype' => $ this -> parseMimeType ( $ path , $ headers ) , ] ; if ( false !== $ timestamp = $ this -> parseTimestamp ( $ headers ) ) { $ metadata [ 'timestamp' ] = $ timestamp ; } if ( isset ( $ headers [ 'content-length' ] ) && is_numeric ( $ headers [ 'content-length' ] ) ) { $ metadata [ 'size' ] = ( int ) $ headers [ 'content-length' ] ; } return $ metadata ; }
Parses metadata out of response headers .
23
protected function parseMimeType ( $ path , array $ headers ) { if ( isset ( $ headers [ 'content-type' ] ) ) { list ( $ mimetype ) = explode ( ';' , $ headers [ 'content-type' ] , 2 ) ; return trim ( $ mimetype ) ; } list ( $ path ) = explode ( '#' , $ path , 2 ) ; list ( $ path ) = explode ( '?' , $ path , 2 ) ; return MimeType :: detectByFilename ( $ path ) ; }
Parses the mimetype out of response headers .
24
public function generate ( $ url ) { $ time = time ( ) ; $ query = parse_url ( $ url , PHP_URL_QUERY ) ; parse_str ( $ query , $ query ) ; $ query = $ this -> filterKeys ( $ query , $ this -> params ) ; $ query [ 'timestamp' ] = $ time ; $ signature = $ this -> generateToken ( $ query ) ; return $ url . '&timestamp=' . $ time . '&signature=' . $ signature ; }
Generate a URL with signature
25
public function verify ( ) { $ time = $ this -> request -> getQuery ( 'timestamp' ) ; if ( $ this -> expireTime && time ( ) - $ time > $ this -> expireTime ) { return false ; } $ query = $ this -> request -> getParameterReference ( 'get' ) ; $ token = $ this -> request -> getQuery ( 'signature' ) ; unset ( $ query [ 'signature' ] ) ; $ timestamp = $ query [ 'timestamp' ] ; $ query = $ this -> filterKeys ( $ query , $ this -> params ) ; $ query [ 'timestamp' ] = $ timestamp ; return $ this -> generateToken ( $ query ) == $ token ; }
Verify whether the URL signature is OK
26
public function searchAndReplace ( $ text ) { $ state = 0 ; $ length = strlen ( $ text ) ; $ matches = [ ] ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ ch = $ text [ $ i ] ; $ state = $ this -> nextState ( $ state , $ ch ) ; foreach ( $ this -> outputs [ $ state ] as $ match ) { $ offset = $ i - $ this -> searchKeywords [ $ match ] + 1 ; $ matches [ $ offset ] = $ match ; } } ksort ( $ matches ) ; $ buf = '' ; $ lastInsert = 0 ; foreach ( $ matches as $ offset => $ match ) { if ( $ offset >= $ lastInsert ) { $ buf .= substr ( $ text , $ lastInsert , $ offset - $ lastInsert ) ; $ buf .= $ this -> replacePairs [ $ match ] ; $ lastInsert = $ offset + $ this -> searchKeywords [ $ match ] ; } } $ buf .= substr ( $ text , $ lastInsert ) ; return $ buf ; }
Search and replace a set of keywords in some text .
27
protected function processGetResult ( $ key , $ result , $ expire , $ fn ) { if ( false === $ result && ( $ expire || $ fn ) ) { if ( ! is_numeric ( $ expire ) && $ fn ) { throw new \ InvalidArgumentException ( sprintf ( 'Expire time for cache "%s" must be numeric, %s given' , $ key , is_object ( $ expire ) ? get_class ( $ expire ) : gettype ( $ expire ) ) ) ; } if ( $ expire && ! $ fn ) { $ fn = $ expire ; $ expire = 0 ; } $ result = call_user_func ( $ fn , $ this -> wei , $ this ) ; $ this -> set ( $ key , $ result , $ expire ) ; } return $ result ; }
Store data to cache when data is not false and callback is provided
28
public function setMulti ( array $ keys , $ expire = 0 ) { $ results = array ( ) ; foreach ( $ keys as $ key => $ value ) { $ results [ $ key ] = $ this -> set ( $ key , $ value , $ expire ) ; } return $ results ; }
Store multiple items
29
public function getFileContent ( $ file , $ fn ) { $ key = $ file . filemtime ( $ file ) ; return $ this -> get ( $ key , function ( $ wei , $ cache ) use ( $ file , $ fn ) { return $ fn ( $ file , $ wei , $ cache ) ; } ) ; }
Use the file modify time as cache key to store an item from a callback
30
protected function getChecksum ( $ string ) { $ checksum = '' ; foreach ( str_split ( strrev ( $ string ) ) as $ i => $ d ) { $ checksum .= ( $ i % 2 === 0 ) ? ( $ d * 2 ) : $ d ; } return ( 10 - array_sum ( str_split ( $ checksum ) ) % 10 ) % 10 ; }
Return the checksum char of luhn algorithm
31
public function setInis ( $ inis ) { foreach ( $ inis as $ name => $ value ) { ini_set ( 'session.' . $ name , $ value ) ; } $ this -> inis = $ inis + $ this -> inis ; return $ this ; }
Set session configuration options
32
protected function isActive ( ) { $ setting = 'session.use_trans_sid' ; $ current = ini_get ( $ setting ) ; if ( false === $ current ) { throw new \ UnexpectedValueException ( sprintf ( 'Setting %s does not exists.' , $ setting ) ) ; } $ result = @ ini_set ( $ setting , $ current ) ; return $ result !== $ current ; }
Check if session is started
33
public static function binToDec ( $ bin , $ length = 0 ) { $ gmp = gmp_init ( $ bin , 2 ) ; $ dec = gmp_strval ( $ gmp , 10 ) ; return self :: pad ( $ dec , $ length ) ; }
Converts binary string into decimal string .
34
public static function binToHex ( $ bin , $ length = 0 ) { $ gmp = gmp_init ( $ bin , 2 ) ; $ hex = gmp_strval ( $ gmp , 16 ) ; return self :: pad ( $ hex , $ length ) ; }
Converts binary string into hexadecimal string .
35
public static function decToHex ( $ dec , $ length = 0 ) { $ gmp = gmp_init ( $ dec , 10 ) ; $ hex = gmp_strval ( $ gmp , 16 ) ; return self :: pad ( $ hex , $ length ) ; }
Converts decimal string into hexadecimal string .
36
public static function rawToBin ( $ raw , $ length = 0 ) { $ gmp = gmp_import ( $ raw ) ; $ bin = gmp_strval ( $ gmp , 2 ) ; return self :: pad ( $ bin , $ length ) ; }
Converts stream of bytes into binary string .
37
public static function rawToDec ( $ raw , $ length = 0 ) { $ gmp = gmp_import ( $ raw ) ; $ dec = gmp_strval ( $ gmp , 10 ) ; return self :: pad ( $ dec , $ length ) ; }
Converts stream of bytes into decimal string .
38
public static function rawToHex ( $ raw , $ length = 0 ) { $ gmp = gmp_import ( $ raw ) ; $ hex = gmp_strval ( $ gmp , 16 ) ; return self :: pad ( $ hex , $ length ) ; }
Converts stream of bytes into hexadecimal string .
39
public static function pad ( $ input , $ length = 0 ) { $ input = ltrim ( $ input , '0' ) ; if ( $ input == '' ) { $ input = '0' ; } return str_pad ( $ input , $ length , '0' , STR_PAD_LEFT ) ; }
Pad left with zeroes to match given length .
40
public function setDriver ( $ driver ) { $ class = $ this -> wei -> getClass ( $ driver ) ; if ( ! class_exists ( $ class ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Cache driver class "%s" not found' , $ class ) ) ; } if ( ! is_subclass_of ( $ class , 'Wei\BaseCache' ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Cache driver class "%s" must extend "Wei\BaseCache"' , $ class ) ) ; } $ this -> driver = $ driver ; $ this -> object = $ this -> wei -> get ( $ driver ) ; return $ this ; }
Set cache driver
41
public function handle ( Request $ request , Closure $ next ) { $ response = $ next ( $ request ) ; $ this -> newRelic -> nameTransaction ( $ this -> getTransactionName ( $ request ) ) ; return $ response ; }
Handles the request by naming the transaction for New Relic
42
public function getTransactionName ( Request $ request ) { $ route = $ request -> route ( ) ; if ( is_array ( $ route ) ) { if ( isset ( $ route [ 1 ] ) && isset ( $ route [ 1 ] [ 'uses' ] ) ) { return $ route [ 1 ] [ 'uses' ] ; } elseif ( isset ( $ route [ 1 ] ) && isset ( $ route [ 1 ] [ 'as' ] ) ) { return $ route [ 1 ] [ 'as' ] ; } } return 'index.php' ; }
Builds the transaction name . It will return the assigned controller action first then the route name before falling back to just index . php
43
protected function saveFile ( $ uploadedFile ) { $ ext = $ this -> getExt ( ) ; $ fullExt = $ ext ? '.' . $ ext : '' ; if ( $ this -> fileName ) { $ fileName = $ this -> fileName ; } else { $ fileName = substr ( $ uploadedFile [ 'name' ] , 0 , strlen ( $ uploadedFile [ 'name' ] ) - strlen ( $ fullExt ) ) ; } $ this -> file = $ this -> dir . '/' . $ fileName . $ fullExt ; if ( ! $ this -> overwrite ) { $ i = 1 ; while ( is_file ( $ this -> file ) ) { $ this -> file = $ this -> dir . '/' . $ fileName . '-' . $ i . $ fullExt ; $ i ++ ; } } if ( ! $ this -> moveUploadedFile ( $ uploadedFile [ 'tmp_name' ] , $ this -> file ) ) { $ this -> addError ( 'cantMove' ) ; return false ; } return true ; }
Save uploaded file to upload directory
44
public function getDisplayName ( ) { if ( $ this -> name !== '' ) { $ result = $ this -> name ; } else { $ result = '' ; $ string = trim ( $ this -> handle , '_-' ) ; $ segments = preg_split ( '/[_-]+/' , $ string ) ; foreach ( $ segments as $ segment ) { if ( $ segment !== '' ) { $ len = mb_strlen ( $ segment ) ; if ( $ len === 1 ) { $ segment = mb_strtoupper ( $ segment ) ; } else { $ segment = mb_strtoupper ( mb_substr ( $ segment , 0 , 1 ) ) . mb_substr ( $ segment , 1 ) ; } if ( $ result === '' ) { $ result = $ segment ; } else { $ result .= ' ' . $ segment ; } } } if ( $ result === '' ) { $ result = $ this -> handle ; } } return $ result ; }
Get the package display name .
45
public function getSortedProductionVersions ( $ descending = false ) { $ versions = [ ] ; foreach ( $ this -> getVersions ( ) as $ v ) { if ( strpos ( $ v -> getVersion ( ) , Package \ Version :: DEV_PREFIX ) !== 0 ) { $ versions [ ] = $ v ; } } usort ( $ versions , function ( Package \ Version $ a , Package \ Version $ b ) use ( $ descending ) { return version_compare ( $ a -> getVersion ( ) , $ b -> getVersion ( ) ) * ( $ descending ? - 1 : 1 ) ; } ) ; return $ versions ; }
Get the production versions sorted in ascending or descending order .
46
public function getSortedVersions ( $ descending = false , $ developmentVersionsFirst = null ) { if ( $ developmentVersionsFirst === null ) { $ versionComparer = new VersionComparer ( ) ; $ result = $ versionComparer -> sortPackageVersionEntities ( $ this -> getVersions ( ) -> toArray ( ) , $ descending ) ; } else { $ devVersions = $ this -> getSortedDevelopmentVersions ( $ descending ) ; $ prodVersions = $ this -> getSortedProductionVersions ( $ descending ) ; if ( $ developmentVersionsFirst ) { $ result = array_merge ( $ devVersions , $ prodVersions ) ; } else { $ result = array_merge ( $ prodVersions , $ devVersions ) ; } } return $ result ; }
Get the versions sorted in ascending or descending order with development or production versions first .
47
public function get ( $ key = null , $ default = null ) { return isset ( $ this -> entries [ $ key ] ) ? $ this -> entries [ $ key ] : $ default ; }
Get a key s value from the cache .
48
public function expired ( ) { if ( empty ( $ this -> entries ) ) { return true ; } if ( $ this -> timestampManager ) { return $ this -> timestampManager -> check ( $ this -> getTimestamp ( ) ) ; } return false ; }
Check if cached as expired .
49
public function save ( ) { $ updated = time ( ) ; $ this -> entries [ $ this -> timestampKey ] = $ updated ; if ( $ this -> timestampManager ) { $ this -> timestampManager -> update ( $ updated ) ; } return ( bool ) file_put_contents ( $ this -> path , json_encode ( $ this -> entries ) ) ; }
Save to cache .
50
public function importDirectory ( $ directory , $ packageHandle , $ packageVersion , $ basePlacesDirectory ) { $ parsed = $ this -> parser -> parseDirectory ( $ packageHandle , $ packageVersion , $ directory , $ basePlacesDirectory , ParserInterface :: DICTIONARY_NONE ) ; $ translations = $ parsed ? $ parsed -> getSourceStrings ( ) : null ; if ( $ translations === null ) { $ translations = new Translations ( ) ; $ translations -> setLanguage ( $ this -> app -> make ( 'community_translation/sourceLocale' ) ) ; } return $ this -> importTranslations ( $ translations , $ packageHandle , $ packageVersion ) ; }
Parse a directory and extract the translatable strings and import them into the database .
51
public function matchPackageVersionEntities ( $ availableVersions , $ wantedVersion ) { if ( empty ( $ availableVersions ) ) { $ result = null ; } else { $ keys = [ ] ; foreach ( $ availableVersions as $ pv ) { $ keys [ $ pv -> getVersion ( ) ] = $ pv ; } $ bestKey = $ this -> matchPackageVersions ( array_keys ( $ keys ) , $ wantedVersion ) ; $ result = $ keys [ $ bestKey ] ; } return $ result ; }
Guess the best package version entity corresponding to a list of entity instances .
52
public function matchPackageVersions ( $ availableVersions , $ wantedVersion ) { $ m = null ; if ( preg_match ( '/^(\d+(?:\.\d+)*)(?:dev|alpha|a|beta|b|rc)/i' , $ wantedVersion , $ m ) ) { $ wantedVersionBase = $ m [ 1 ] ; } else { $ wantedVersionBase = $ wantedVersion ; } $ wantedVersionComparable = preg_replace ( '/^(.*?\d)(\.0+)+$/' , '\1' , $ wantedVersionBase ) ; $ result = null ; $ availableVersions = $ this -> sortPackageVersions ( $ availableVersions , false ) ; foreach ( $ availableVersions as $ availableVersion ) { if ( $ result === null ) { $ result = $ availableVersion ; } if ( strpos ( $ availableVersion , PackageVersionEntity :: DEV_PREFIX ) === 0 ) { $ availableVersionBase = substr ( $ availableVersion , strlen ( PackageVersionEntity :: DEV_PREFIX ) ) ; $ availableVersionIsDev = true ; } else { $ availableVersionBase = $ availableVersion ; $ availableVersionIsDev = false ; } $ availableVersionComparable = preg_replace ( '/^(.*?\d)(\.0+)+$/' , '\1' , $ availableVersionBase ) ; if ( $ availableVersionIsDev ) { $ availableVersionIsDev .= str_repeat ( '.' . PHP_INT_MAX , 6 ) ; } $ cmp = version_compare ( $ availableVersionComparable , $ wantedVersionComparable ) ; if ( $ cmp > 0 ) { if ( $ availableVersionIsDev && strpos ( $ availableVersionBase . '.' , $ wantedVersionBase . '.' ) === 0 ) { $ result = $ availableVersion ; } break ; } $ result = $ availableVersion ; if ( $ cmp === 0 ) { break ; } } return $ result ; }
Guess the best package version entity corresponding to a list of versions .
53
public function fromPot ( Translations $ pot , LocaleEntity $ locale ) { $ cn = $ this -> app -> make ( EntityManager :: class ) -> getConnection ( ) ; $ po = clone $ pot ; $ po -> setLanguage ( $ locale -> getID ( ) ) ; $ numPlurals = $ locale -> getPluralCount ( ) ; $ searchQuery = $ cn -> prepare ( ' select CommunityTranslationTranslations.* from CommunityTranslationTranslatables inner join CommunityTranslationTranslations on CommunityTranslationTranslatables.id = CommunityTranslationTranslations.translatable where CommunityTranslationTranslations.locale = ' . $ cn -> quote ( $ locale -> getID ( ) ) . ' and CommunityTranslationTranslations.current = 1 and CommunityTranslationTranslatables.hash = ? limit 1 ' ) -> getWrappedStatement ( ) ; foreach ( $ po as $ translationKey => $ translation ) { $ plural = $ translation -> getPlural ( ) ; $ hash = md5 ( ( $ plural === '' ) ? $ translationKey : "$translationKey\005$plural" ) ; $ searchQuery -> execute ( [ $ hash ] ) ; $ row = $ searchQuery -> fetch ( ) ; $ searchQuery -> closeCursor ( ) ; if ( $ row !== false ) { $ translation -> setTranslation ( $ row [ 'text0' ] ) ; if ( $ plural !== '' ) { switch ( $ numPlurals ) { case 6 : $ translation -> setPluralTranslation ( $ row [ 'text5' ] , 4 ) ; case 5 : $ translation -> setPluralTranslation ( $ row [ 'text4' ] , 3 ) ; case 4 : $ translation -> setPluralTranslation ( $ row [ 'text3' ] , 2 ) ; case 3 : $ translation -> setPluralTranslation ( $ row [ 'text2' ] , 1 ) ; case 2 : $ translation -> setPluralTranslation ( $ row [ 'text1' ] , 0 ) ; break ; } } } } return $ po ; }
Fill in the translations for a specific locale .
54
public function getUnreviewedSelectQuery ( LocaleEntity $ locale ) { $ cn = $ this -> app -> make ( EntityManager :: class ) -> getConnection ( ) ; $ queryLocaleID = $ cn -> quote ( $ locale -> getID ( ) ) ; return $ cn -> executeQuery ( $ this -> getBaseSelectString ( $ locale , false , false ) . " inner join ( select distinct translatable from CommunityTranslationTranslations where locale = $queryLocaleID and ( (approved is null) or (current = 1 and approved = 0) ) ) as tNR on CommunityTranslationTranslatables.id = tNR.translatable order by CommunityTranslationTranslatables.text " ) ; }
Get the recordset of all the translations of a locale that needs to be reviewed .
55
public function getPackageSelectQuery ( PackageVersionEntity $ packageVersion , LocaleEntity $ locale , $ excludeUntranslatedStrings = false ) { $ cn = $ this -> app -> make ( EntityManager :: class ) -> getConnection ( ) ; $ queryPackageVersionID = ( int ) $ packageVersion -> getID ( ) ; return $ cn -> executeQuery ( $ this -> getBaseSelectString ( $ locale , true , $ excludeUntranslatedStrings ) . " where CommunityTranslationTranslatablePlaces.packageVersion = $queryPackageVersionID order by CommunityTranslationTranslatablePlaces.sort " ) ; }
Get recordset of the translations for a specific package version and locale .
56
public function forPackage ( $ packageOrHandleVersion , LocaleEntity $ locale , $ excludeUntranslatedStrings = false ) { if ( $ packageOrHandleVersion instanceof PackageVersionEntity ) { $ packageVersion = $ packageOrHandleVersion ; } elseif ( is_array ( $ packageOrHandleVersion ) && isset ( $ packageOrHandleVersion [ 'handle' ] ) && isset ( $ packageOrHandleVersion [ 'version' ] ) ) { $ packageVersion = $ this -> app -> make ( PackageVersionRepository :: class ) -> findOneBy ( [ 'handle' => $ packageOrHandleVersion [ 'handle' ] , 'version' => $ packageOrHandleVersion [ 'version' ] , ] ) ; } elseif ( is_array ( $ packageOrHandleVersion ) && isset ( $ packageOrHandleVersion [ 0 ] ) && isset ( $ packageOrHandleVersion [ 1 ] ) ) { $ packageVersion = $ this -> app -> make ( PackageVersionRepository :: class ) -> findOneBy ( [ 'handle' => $ packageOrHandleVersion [ 0 ] , 'version' => $ packageOrHandleVersion [ 1 ] , ] ) ; } else { $ packageVersion = null ; } if ( $ packageVersion === null ) { throw new UserMessageException ( t ( 'Invalid translated package version specified' ) ) ; } $ rs = $ this -> getPackageSelectQuery ( $ packageVersion , $ locale , $ excludeUntranslatedStrings ) ; $ result = $ this -> buildTranslations ( $ locale , $ rs ) ; $ result -> setHeader ( 'Project-Id-Version' , $ packageVersion -> getPackage ( ) -> getHandle ( ) . ' ' . $ packageVersion -> getVersion ( ) ) ; return $ result ; }
Get the translations for a specific package version and locale .
57
public function unreviewed ( LocaleEntity $ locale ) { $ rs = $ this -> getUnreviewedSelectQuery ( $ locale ) ; $ result = $ this -> buildTranslations ( $ locale , $ rs ) ; $ result -> setHeader ( 'Project-Id-Version' , 'unreviewed' ) ; return $ result ; }
Get the unreviewed translations for a locale .
58
public function localeHasPendingApprovals ( LocaleEntity $ locale ) { $ cn = $ this -> app -> make ( EntityManager :: class ) -> getConnection ( ) ; $ rs = $ cn -> executeQuery ( ' select CommunityTranslationTranslations.id from CommunityTranslationTranslations inner join CommunityTranslationTranslatablePlaces on CommunityTranslationTranslations.translatable = CommunityTranslationTranslatablePlaces.translatable where CommunityTranslationTranslations.locale = ? and ( (CommunityTranslationTranslations.approved is null) or (CommunityTranslationTranslations.current = 1 and CommunityTranslationTranslations.approved = 0) ) limit 1 ' , [ $ locale -> getID ( ) , ] ) ; $ result = $ rs -> fetchColumn ( ) !== false ; $ rs -> closeCursor ( ) ; return $ result ; }
Does a locale have translation strings that needs review?
59
public function getColumnContent ( $ gridField , $ record , $ columnName ) { if ( ! $ record -> canView ( ) ) return ; $ field = GridField_FormAction :: create ( $ gridField , 'ExportSingle' . $ record -> ID , false , "exportsingle" , array ( 'RecordID' => $ record -> ID ) ) -> addExtraClass ( 'gridfield-button-export-single no-ajax' ) -> setAttribute ( 'title' , _t ( 'firebrandhq.EXCELEXPORT' , "Export" ) ) -> setAttribute ( 'data-icon' , 'download-csv' ) ; return $ field -> Field ( ) ; }
Return the button to show at the end of the row
60
public function setUseLabelsAsHeaders ( $ value ) { if ( $ value === null ) { $ this -> useLabelsAsHeaders = null ; } else { $ this -> useLabelsAsHeaders = ( bool ) $ value ; } return $ this ; }
Set the DataFormatter s UseFieldLabelsAsHeaders property
61
public function getOne ( PackageVersionEntity $ packageVersion , LocaleEntity $ locale ) { $ array = $ this -> get ( $ packageVersion , $ locale ) ; return array_shift ( $ array ) ; }
Get some stats about a package version and a locale .
62
public function get ( $ wantedPackageVersions , $ wantedLocales ) { $ packageVersions = array_values ( array_unique ( $ this -> getPackageVersions ( $ wantedPackageVersions ) ) ) ; $ locales = array_values ( array_unique ( $ this -> getLocales ( $ wantedLocales ) ) ) ; $ qb = $ this -> createQueryBuilder ( 's' ) ; if ( count ( $ packageVersions ) === 1 ) { $ qb -> andWhere ( 's.packageVersion = :packageVersion' ) -> setParameter ( 'packageVersion' , $ packageVersions [ 0 ] ) ; } else { $ or = $ qb -> expr ( ) -> orX ( ) ; foreach ( $ packageVersions as $ i => $ pv ) { $ or -> add ( "s.packageVersion = :packageVersion$i" ) ; $ qb -> setParameter ( "packageVersion$i" , $ pv ) ; } $ qb -> andWhere ( $ or ) ; } if ( count ( $ locales ) === 1 ) { $ qb -> andWhere ( 's.locale = :locale' ) ; $ qb -> setParameter ( 'locale' , $ locales [ 0 ] ) ; } else { $ or = $ qb -> expr ( ) -> orX ( ) ; foreach ( $ locales as $ i => $ l ) { $ or -> add ( "s.locale = :locale$i" ) ; $ qb -> setParameter ( "locale$i" , $ l ) ; } $ qb -> andWhere ( $ or ) ; } $ result = $ qb -> getQuery ( ) -> getResult ( ) ; $ missingLocalesForPackageVersions = [ ] ; foreach ( $ packageVersions as $ packageVersion ) { foreach ( $ locales as $ locale ) { $ found = false ; foreach ( $ result as $ stats ) { if ( $ stats -> getPackageVersion ( ) -> getID ( ) === $ packageVersion -> getID ( ) && $ stats -> getLocale ( ) -> getID ( ) === $ locale -> getID ( ) ) { $ found = true ; break ; } } if ( $ found === false ) { if ( ! isset ( $ missingLocalesForPackageVersions [ $ packageVersion -> getID ( ) ] ) ) { $ missingLocalesForPackageVersions [ $ packageVersion -> getID ( ) ] = [ 'packageVersion' => $ packageVersion , 'locales' => [ ] ] ; } $ missingLocalesForPackageVersions [ $ packageVersion -> getID ( ) ] [ 'locales' ] [ ] = $ locale ; } } } foreach ( $ missingLocalesForPackageVersions as $ missingLocalesForPackageVersion ) { $ result = array_merge ( $ result , $ this -> build ( $ missingLocalesForPackageVersion [ 'packageVersion' ] , $ missingLocalesForPackageVersion [ 'locales' ] ) ) ; } return array_values ( $ result ) ; }
Get some stats about one or more package versions and one or more locales .
63
public function setGlobalAccess ( $ enable , $ user = 'current' ) { $ user = $ this -> getUser ( $ user ) ; if ( $ user === null ) { throw new UserMessageException ( t ( 'Invalid user' ) ) ; } if ( $ user -> getUserID ( ) === USER_SUPER_ID ) { return ; } $ group = $ this -> groups -> getGlobalAdministrators ( ) ; if ( $ enable ) { foreach ( $ this -> app -> make ( LocaleRepository :: class ) -> getApprovedLocales ( ) as $ locale ) { $ this -> setLocaleAccess ( $ locale , self :: NONE , $ user ) ; } if ( ! $ user -> inGroup ( $ group ) ) { $ user -> enterGroup ( $ group ) ; } } else { if ( $ user -> inGroup ( $ group ) ) { $ user -> exitGroup ( $ group ) ; } } }
Set or unset global administration access .
64
protected function getWorktreeDirectory ( ) { if ( $ this -> worktreeDirectory === null ) { $ config = $ this -> app -> make ( 'community_translation/config' ) ; $ dir = $ config -> get ( 'options.tempDir' ) ; $ dir = is_string ( $ dir ) ? rtrim ( str_replace ( DIRECTORY_SEPARATOR , '/' , $ dir ) , '/' ) : '' ; if ( $ dir === '' ) { $ fh = $ this -> app -> make ( 'helper/file' ) ; $ dir = $ fh -> getTemporaryDirectory ( ) ; $ dir = is_string ( $ dir ) ? rtrim ( str_replace ( DIRECTORY_SEPARATOR , '/' , $ dir ) , '/' ) : '' ; if ( $ dir === '' ) { throw new UserMessageException ( t ( 'Unable to retrieve the temporary directory.' ) ) ; } } $ fs = $ this -> getFilesystem ( ) ; $ dir = $ dir . '/git-repositories' ; if ( ! @ $ fs -> isDirectory ( $ dir ) ) { @ $ fs -> makeDirectory ( $ dir , DIRECTORY_PERMISSIONS_MODE_COMPUTED , true ) ; if ( ! @ $ fs -> isDirectory ( $ dir ) ) { throw new UserMessageException ( t ( 'Unable to create a temporary directory.' ) ) ; } } $ file = $ dir . '/index.html' ; if ( ! $ fs -> isFile ( $ file ) ) { if ( @ $ fs -> put ( $ file , '' ) === false ) { throw new UserMessageException ( t ( 'Error initializing a temporary directory.' ) ) ; } } $ file = $ dir . '/.htaccess' ; if ( ! $ fs -> isFile ( $ file ) ) { if ( @ $ fs -> put ( $ file , <<<'EOT'Order deny,allowDeny from allphp_flag engine offEOT ) === false ) { throw new UserMessageException ( t ( 'Error initializing a temporary directory.' ) ) ; } } $ handle = strtolower ( $ this -> gitRepository -> getURL ( ) ) ; $ handle = preg_replace ( '/[^a-z0-9\-_\.]+/' , '_' , $ handle ) ; $ handle = preg_replace ( '/_+/' , '_' , $ handle ) ; $ dir .= '/' . $ handle ; $ this -> worktreeDirectory = $ dir ; } return $ this -> worktreeDirectory ; }
Get the working tree directory .
65
protected function getGitDirectory ( ) { if ( $ this -> gitDirectory === null ) { $ this -> gitDirectory = $ this -> getWorktreeDirectory ( ) . '/.git' ; } return $ this -> gitDirectory ; }
Get the git directory .
66
public function getRootDirectory ( ) { $ dir = $ this -> getWorktreeDirectory ( ) ; $ relativeRoot = trim ( str_replace ( DIRECTORY_SEPARATOR , '/' , $ this -> gitRepository -> getDirectoryToParse ( ) ) , '/' ) ; if ( $ relativeRoot !== '' ) { $ dir .= '/' . $ relativeRoot ; } return $ dir ; }
Return the directory containing the files to be parsed .
67
public function update ( ) { $ fs = $ this -> getFilesystem ( ) ; if ( $ fs -> isDirectory ( $ this -> getGitDirectory ( ) ) ) { $ this -> runGit ( 'fetch origin --tags' ) ; } else { $ this -> initialize ( ) ; } }
Initializes or update the git repository .
68
private function runGit ( $ cmd , $ setDirectories = true ) { static $ execAvailable ; if ( ! isset ( $ execAvailable ) ) { $ safeMode = @ ini_get ( 'safe_mode' ) ; if ( ! empty ( $ safeMode ) ) { throw new UserMessageException ( t ( "Safe-mode can't be on" ) ) ; } if ( ! function_exists ( 'exec' ) ) { throw new UserMessageException ( t ( 'exec() function is missing' ) ) ; } if ( in_array ( 'exec' , array_map ( 'trim' , explode ( ',' , strtolower ( @ ini_get ( 'disable_functions' ) ) ) ) ) ) { throw new UserMessageException ( t ( 'exec() function is disabled' ) ) ; } $ execAvailable = true ; } $ line = 'git' ; if ( $ setDirectories ) { $ line .= ' -C ' . escapeshellarg ( str_replace ( '/' , DIRECTORY_SEPARATOR , $ this -> getWorktreeDirectory ( ) ) ) ; } $ line .= ' ' . $ cmd . ' 2>&1' ; $ rc = 1 ; $ output = [ ] ; @ exec ( $ line , $ output , $ rc ) ; if ( $ rc !== 0 ) { throw new UserMessageException ( t ( 'Command failed with return code %1$s: %2$s' , $ rc , implode ( "\n" , $ output ) ) ) ; } return $ output ; }
Execute a git command .
69
public function getInputConceptsQuery ( $ data , $ concepts ) { foreach ( $ concepts as $ concept ) { $ data [ ] = $ this -> setData ( [ 'concepts' => [ [ 'name' => $ concept -> getName ( ) , 'value' => $ concept -> getValue ( ) , ] , ] , ] , 'input' ) ; } return $ data ; }
Generates Input Concept search query and adds it to existing data
70
public function getMetadataQuery ( $ data , $ metadata ) { foreach ( $ metadata as $ searchMetadata ) { $ data [ ] = $ this -> setData ( [ 'metadata' => $ searchMetadata ] , 'input' ) ; } return $ data ; }
Generates Metadata search query and adds it to existing data
71
public function getImagesQuery ( $ data , $ inputs ) { foreach ( $ inputs as $ input ) { $ data [ ] = $ this -> setData ( [ 'image' => [ 'url' => $ input -> getImage ( ) ] ] , 'input' ) ; } return $ data ; }
Generates Image search query and adds it to existing data
72
public function getReverseImagesQuery ( $ data , $ inputs ) { foreach ( $ inputs as $ input ) { $ data [ ] = [ 'output' => $ this -> setData ( [ 'image' => [ 'url' => $ input -> getImage ( ) ] ] , 'input' ) ] ; } return $ data ; }
Generates Reverse Image search query and adds it to existing data
73
public function getInputsFromSearchResult ( $ searchResult ) { $ input_array = [ ] ; if ( ! isset ( $ searchResult [ 'hits' ] ) ) { throw new \ Exception ( 'Hits Not Found' ) ; } foreach ( $ searchResult [ 'hits' ] as $ hit ) { if ( ! isset ( $ hit [ 'input' ] ) ) { throw new \ Exception ( 'Inputs Not Found' ) ; } $ input = new Input ( $ hit [ 'input' ] ) ; $ input_array [ ] = $ input ; } return $ input_array ; }
Parses Search Request Result and gets Inputs
74
public function getDisplayVersion ( ) { if ( $ this -> isDevVersion ( ) ) { return t ( '%s development series' , substr ( $ this -> version , strlen ( static :: DEV_PREFIX ) ) ) ; } else { return $ this -> version ; } }
Get the package version display name .
75
protected function genericHandle ( $ dataFormatterClass , $ ext , GridField $ gridField , $ request = null ) { $ items = $ this -> getItems ( $ gridField ) ; $ this -> setHeader ( $ gridField , $ ext ) ; $ formater = new $ dataFormatterClass ( ) ; $ formater -> setUseLabelsAsHeaders ( $ this -> useLabelsAsHeaders ) ; $ fileData = $ formater -> convertDataObjectSet ( $ items ) ; return $ fileData ; }
Generic Handle request that will return a Spread Sheet in the requested format
76
protected function setHeader ( $ gridField , $ ext ) { $ do = singleton ( $ gridField -> getModelClass ( ) ) ; Controller :: curr ( ) -> getResponse ( ) -> addHeader ( "Content-Disposition" , 'attachment; filename="' . $ do -> i18n_plural_name ( ) . '.' . $ ext . '"' ) ; }
Set the HTTP header to force a download and set the filename .
77
protected function getItems ( GridField $ gridField ) { $ gridField -> getConfig ( ) -> removeComponentsByType ( 'GridFieldPaginator' ) ; $ items = $ gridField -> getManipulatedList ( ) ; foreach ( $ gridField -> getConfig ( ) -> getComponents ( ) as $ component ) { if ( $ component instanceof GridFieldFilterHeader || $ component instanceof GridFieldSortableHeader ) { $ items = $ component -> getManipulatedData ( $ gridField , $ items ) ; } } $ arrayList = new ArrayList ( ) ; foreach ( $ items -> limit ( null ) as $ item ) { if ( ! $ item -> hasMethod ( 'canView' ) || $ item -> canView ( ) ) { $ arrayList -> add ( $ item ) ; } } return $ arrayList ; }
Helper function to extract the item list out of the GridField .
78
public function buildFacebookLike ( ) { $ facebookLikeProvider = new FacebookLikeProvider ( array ( 'layout' => $ this -> configResolver -> getParameter ( 'facebook_like.layout' , 'ez_share_buttons' ) , 'width' => $ this -> configResolver -> getParameter ( 'facebook_like.width' , 'ez_share_buttons' ) , 'showFaces' => $ this -> configResolver -> getParameter ( 'facebook_like.show_faces' , 'ez_share_buttons' ) , 'share' => $ this -> configResolver -> getParameter ( 'facebook_like.share' , 'ez_share_buttons' ) , ) ) ; return $ facebookLikeProvider ; }
Builds Facebook like button provider .
79
public function buildFacebookRecommend ( ) { $ facebookRecommendProvider = new FacebookRecommendProvider ( array ( 'layout' => $ this -> configResolver -> getParameter ( 'facebook_recommend.layout' , 'ez_share_buttons' ) , 'width' => $ this -> configResolver -> getParameter ( 'facebook_recommend.width' , 'ez_share_buttons' ) , 'showFaces' => $ this -> configResolver -> getParameter ( 'facebook_recommend.show_faces' , 'ez_share_buttons' ) , 'share' => $ this -> configResolver -> getParameter ( 'facebook_recommend.share' , 'ez_share_buttons' ) , ) ) ; return $ facebookRecommendProvider ; }
Builds Facebook recommend button provider .
80
public function buildTwitter ( ) { $ twitterProvider = new TwitterProvider ( array ( 'showUsername' => $ this -> configResolver -> getParameter ( 'twitter.show_username' , 'ez_share_buttons' ) , 'largeButton' => $ this -> configResolver -> getParameter ( 'twitter.large_button' , 'ez_share_buttons' ) , 'language' => $ this -> configResolver -> getParameter ( 'twitter.language' , 'ez_share_buttons' ) , ) ) ; return $ twitterProvider ; }
Builds Twitter button provider .
81
public function buildLinkedin ( ) { $ linkedinProvider = new LinkedinProvider ( array ( 'countMode' => $ this -> configResolver -> getParameter ( 'linkedin.count_mode' , 'ez_share_buttons' ) , 'language' => $ this -> configResolver -> getParameter ( 'linkedin.language' , 'ez_share_buttons' ) , ) ) ; return $ linkedinProvider ; }
Builds Linkedin button provider .
82
public function buildGooglePlus ( ) { $ googlePlusProvider = new GooglePlusProvider ( array ( 'size' => $ this -> configResolver -> getParameter ( 'google_plus.size' , 'ez_share_buttons' ) , 'annotation' => $ this -> configResolver -> getParameter ( 'google_plus.annotation' , 'ez_share_buttons' ) , 'width' => $ this -> configResolver -> getParameter ( 'google_plus.width' , 'ez_share_buttons' ) , 'language' => $ this -> configResolver -> getParameter ( 'google_plus.language' , 'ez_share_buttons' ) , ) ) ; return $ googlePlusProvider ; }
Builds Google Plus button provider .
83
public function buildXing ( ) { $ xingProvider = new XingProvider ( array ( 'shape' => $ this -> configResolver -> getParameter ( 'xing.shape' , 'ez_share_buttons' ) , 'counter' => $ this -> configResolver -> getParameter ( 'xing.counter' , 'ez_share_buttons' ) , 'language' => $ this -> configResolver -> getParameter ( 'xing.language' , 'ez_share_buttons' ) , ) ) ; return $ xingProvider ; }
Builds Xing button provider .
84
public function import ( RemotePackageEntity $ remotePackage ) { $ temp = $ this -> download ( $ remotePackage ) ; $ rootPath = $ this -> getRootPath ( $ temp ) ; $ this -> translatableImporter -> importDirectory ( $ rootPath , $ remotePackage -> getHandle ( ) , $ remotePackage -> getVersion ( ) , '' ) ; $ package = $ this -> packageRepo -> findOneBy ( [ 'handle' => $ remotePackage -> getHandle ( ) ] ) ; if ( $ package !== null ) { $ persist = false ; if ( $ remotePackage -> getName ( ) !== '' && $ remotePackage -> getName ( ) !== $ package -> getName ( ) ) { $ package -> setName ( $ remotePackage -> getName ( ) ) ; $ persist = true ; } if ( $ remotePackage -> getUrl ( ) !== '' && $ remotePackage -> getUrl ( ) !== $ package -> getUrl ( ) ) { $ package -> setUrl ( $ remotePackage -> getUrl ( ) ) ; $ persist = true ; } if ( $ persist ) { $ this -> em -> persist ( $ package ) ; $ this -> em -> flush ( $ package ) ; } } }
Import a remote package .
85
public function getVisitsCountFromCurrentIP ( $ timeWindow ) { $ timeWindow = ( int ) $ timeWindow ; $ ipControlLog = $ this -> app -> make ( IPControlLog :: class ) ; return $ ipControlLog -> countVisits ( 'api' , new DateTime ( "-$timeWindow seconds" ) ) ; }
Get the number of visits from the current IP address since a determined number of seconds ago .
86
public function checkRateLimit ( ) { $ rateLimit = $ this -> getRateLimit ( ) ; if ( $ rateLimit !== null ) { list ( $ maxRequests , $ timeWindow ) = $ rateLimit ; $ visits = $ this -> getVisitsCountFromCurrentIP ( $ timeWindow ) ; if ( $ visits >= $ maxRequests ) { throw new UserMessageException ( t ( 'You reached the API rate limit (%1$s requests every %2$s seconds)' , $ maxRequests , $ timeWindow ) ) ; } $ this -> app -> make ( IPControlLog :: class ) -> addVisit ( 'api' ) ; } }
Check if the API Rate limit has been reached .
87
public function setDirectoryToParse ( $ value ) { $ this -> directoryToParse = trim ( str_replace ( DIRECTORY_SEPARATOR , '/' , trim ( ( string ) $ value ) ) , '/' ) ; return $ this ; }
Set the path to the directory to be parsed .
88
public function setDirectoryForPlaces ( $ value ) { $ this -> directoryForPlaces = trim ( str_replace ( DIRECTORY_SEPARATOR , '/' , trim ( ( string ) $ value ) ) , '/' ) ; return $ this ; }
Set the base directory for places .
89
public function addDetectedVersion ( $ version , $ kind , $ repoName ) { $ this -> detectedVersions [ $ version ] = [ 'kind' => $ kind , 'repoName' => $ repoName , ] ; return $ this ; }
Add a repository detected version .
90
public function setTagFilters ( array $ value = null ) { if ( $ value === null ) { $ this -> tagFilters = [ 'none' ] ; } elseif ( empty ( $ value ) ) { $ this -> tagFilters = [ 'all' ] ; } else { $ this -> tagFilters = $ value ; } return $ this ; }
Set the repository tag filters .
91
public function getTagFiltersExpanded ( ) { $ tagFilters = $ this -> getTagFilters ( ) ; if ( $ tagFilters === null ) { $ result = null ; } else { $ result = [ ] ; $ m = null ; foreach ( $ tagFilters as $ tagFilter ) { if ( preg_match ( '/^\s*([<>=]+)\s*(\d+(?:\.\d+)?)\s*$/' , $ tagFilter , $ m ) ) { switch ( $ m [ 1 ] ) { case '<=' : case '<' : case '=' : case '>=' : case '>' : $ result [ ] = [ 'operator' => $ m [ 1 ] , 'version' => $ m [ 2 ] ] ; break ; } } } } return $ result ; }
Extracts the info for tag filter .
92
private function predict ( array $ image , $ modelType , $ language = null ) { $ data [ 'inputs' ] = [ [ 'data' => [ 'image' => $ image , ] , ] , ] ; if ( $ language ) { $ data [ 'model' ] = [ 'output_info' => [ 'output_config' => [ 'language' => $ language , ] , ] , ] ; } return $ this -> getRequest ( ) -> request ( 'POST' , $ this -> getRequestUrl ( sprintf ( 'models/%s/outputs' , $ modelType ) ) , $ data ) ; }
The actual predict call
93
public function predictUrl ( $ url , $ modelType , $ language = null ) { return $ this -> predict ( [ 'url' => $ url ] , $ modelType , $ language ) ; }
Predict by url
94
public function predictPath ( $ path , $ modelType , $ language = null ) { if ( ! file_exists ( $ path ) ) { throw new FileNotFoundException ( $ path ) ; } return $ this -> predict ( [ 'base64' => base64_encode ( file_get_contents ( $ path ) ) , ] , $ modelType , $ language ) ; }
Predict by image path
95
public function predictEncoded ( $ hash , $ modelType , $ language = null ) { return $ this -> predict ( [ 'base64' => $ hash , ] , $ modelType , $ language ) ; }
Predict base64 encoded image
96
public function train ( string $ id ) { $ modelResult = $ this -> getRequest ( ) -> request ( 'POST' , $ this -> getRequestUrl ( sprintf ( 'models/%s/versions' , $ id ) ) ) ; return $ this -> getModelFromResult ( $ modelResult ) ; }
Train the model
97
public function create ( Model $ model ) { $ data [ 'model' ] = $ this -> createModelData ( $ model ) ; $ modelResult = $ this -> getRequest ( ) -> request ( 'POST' , $ this -> getRequestUrl ( 'models' ) , $ data ) ; return $ this -> getModelFromResult ( $ modelResult ) ; }
Create new Model
98
public function update ( Model $ model ) { $ data [ 'models' ] = [ ] ; $ data [ 'models' ] [ ] = $ this -> createModelData ( $ model ) ; $ data [ 'action' ] = 'merge' ; $ modelResult = $ this -> getRequest ( ) -> request ( 'PATCH' , $ this -> getRequestUrl ( 'models' ) , $ data ) ; return $ this -> getModelsFromResult ( $ modelResult ) ; }
Update the model
99
public function createModelData ( Model $ model ) { $ data = [ ] ; if ( $ model -> getId ( ) ) { $ data [ 'id' ] = $ model -> getId ( ) ; } if ( $ model -> getName ( ) ) { $ data [ 'name' ] = $ model -> getName ( ) ; } if ( $ model -> getConcepts ( ) ) { $ data [ 'output_info' ] [ 'data' ] = [ ] ; $ data [ 'output_info' ] [ 'data' ] = $ this -> addModelConcepts ( $ data [ 'output_info' ] [ 'data' ] , $ model -> getConcepts ( ) ) ; } $ data [ 'output_info' ] [ 'output_config' ] = $ model -> getOutputConfig ( ) ; return $ data ; }
Create Model data for Request
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
15