idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
49,000
protected function getCart ( ) { $ cart = $ this -> session -> get ( $ this -> name ) ; return $ cart instanceof Collection ? $ cart : new Collection ( ) ; }
Get the carts content .
49,001
protected function updateRow ( $ rawId , array $ attributes ) { $ cart = $ this -> getCart ( ) ; $ row = $ cart -> get ( $ rawId ) ; foreach ( $ attributes as $ key => $ value ) { $ row -> put ( $ key , $ value ) ; } if ( count ( array_intersect ( array_keys ( $ attributes ) , [ 'qty' , 'price' ] ) ) ) { $ row -> put (...
Update a row if the rawId already exists .
49,002
protected function insertRow ( $ rawId , $ id , $ name , $ qty , $ price , $ attributes = [ ] ) { $ newRow = $ this -> makeRow ( $ rawId , $ id , $ name , $ qty , $ price , $ attributes ) ; $ cart = $ this -> getCart ( ) ; $ cart -> put ( $ rawId , $ newRow ) ; $ this -> save ( $ cart ) ; return $ newRow ; }
Create a new row Object .
49,003
protected function makeRow ( $ rawId , $ id , $ name , $ qty , $ price , array $ attributes = [ ] ) { return new Item ( array_merge ( [ '__raw_id' => $ rawId , 'id' => $ id , 'name' => $ name , 'qty' => $ qty , 'price' => $ price , 'total' => $ qty * $ price , '__model' => $ this -> model , ] , $ attributes ) ) ; }
Make a row item .
49,004
protected function updateQty ( $ rawId , $ qty ) { if ( $ qty <= 0 ) { return $ this -> remove ( $ rawId ) ; } return $ this -> updateRow ( $ rawId , [ 'qty' => $ qty ] ) ; }
Update the quantity of a row .
49,005
private function requestResource ( $ actionPath , $ params = [ ] , $ method = 'GET' ) { $ url = $ this -> getApiUrl ( ) . $ actionPath ; $ cookies = CookieJar :: fromArray ( [ 'PVEAuthCookie' => $ this -> authToken -> getTicket ( ) , ] , $ this -> credentials -> getHostname ( ) ) ; switch ( $ method ) { case 'GET' : re...
Send a request to a given Proxmox API resource .
49,006
private function processHttpResponse ( $ response ) { if ( $ response === null ) { return null ; } switch ( $ this -> fakeType ) { case 'pngb64' : $ base64 = base64_encode ( $ response -> getBody ( ) ) ; return 'data:image/png;base64,' . $ base64 ; case 'object' : case 'array' : return json_decode ( $ response -> getBo...
Parses the response to the desired return type .
49,007
public function login ( ) { $ loginUrl = $ this -> credentials -> getApiUrl ( ) . '/json/access/ticket' ; $ response = $ this -> httpClient -> post ( $ loginUrl , [ 'verify' => false , 'exceptions' => false , 'form_params' => [ 'username' => $ this -> credentials -> getUsername ( ) , 'password' => $ this -> credentials...
Attempts to login using set credentials if succeeded will return the AuthToken used in all requests .
49,008
public function setCredentials ( $ credentials ) { if ( ! $ credentials instanceof Credentials ) { $ credentials = new Credentials ( $ credentials ) ; } $ this -> credentials = $ credentials ; $ this -> authToken = $ this -> login ( ) ; }
Assign the passed Credentials object to the ProxmoxVE .
49,009
public function setResponseType ( $ responseType = 'array' ) { $ supportedFormats = array ( 'json' , 'html' , 'extjs' , 'text' , 'png' ) ; if ( in_array ( $ responseType , $ supportedFormats ) ) { $ this -> fakeType = false ; $ this -> responseType = $ responseType ; } else { switch ( $ responseType ) { case 'pngb64' :...
Sets the response type that is going to be returned when doing requests .
49,010
public function get ( $ actionPath , $ params = [ ] ) { if ( ! is_array ( $ params ) ) { $ errorMessage = 'GET params should be an associative array.' ; throw new \ InvalidArgumentException ( $ errorMessage ) ; } if ( substr ( $ actionPath , 0 , 1 ) != '/' ) { $ actionPath = '/' . $ actionPath ; } $ response = $ this -...
GET a resource defined in the pvesh tool .
49,011
public function getStorages ( $ type = null ) { if ( $ type === null ) { return $ this -> get ( '/storage' ) ; } $ supportedTypes = array ( 'lvm' , 'nfs' , 'dir' , 'zfs' , 'rbd' , 'iscsi' , 'sheepdog' , 'glusterfs' , 'iscsidirect' , ) ; if ( in_array ( $ type , $ supportedTypes ) ) { return $ this -> get ( '/storage' ,...
Retrieves all the storage found in the Proxmox server or only the ones matching the storage type provided if any .
49,012
public function createStorage ( $ storageData ) { if ( ! is_array ( $ storageData ) ) { $ errorMessage = 'Storage data needs to be array' ; throw new \ InvalidArgumentException ( $ errorMessage ) ; } return $ this -> create ( '/storage' , $ storageData ) ; }
Creates a storage resource using the passed data .
49,013
protected function invalidProvider ( $ provider ) { if ( is_null ( $ provider ) ) { return true ; } foreach ( config ( 'auth.guards' ) as $ guardsConfiguration ) { if ( $ guardsConfiguration [ 'provider' ] === $ provider ) { return false ; } } return true ; }
Check if the given provider is not registered in the auth configuration file .
49,014
public static function getAuthGuards ( Request $ request ) { $ middlewares = $ request -> route ( ) -> middleware ( ) ; $ guards = [ ] ; foreach ( $ middlewares as $ middleware ) { if ( Str :: startsWith ( $ middleware , 'auth' ) ) { $ explodedGuards = explode ( ',' , Str :: after ( $ middleware , ':' ) ) ; $ guards = ...
Get guards passed as parameters to auth middleware .
49,015
public static function getGuardsProviders ( $ guards ) { return collect ( $ guards ) -> mapWithKeys ( function ( $ guard ) { return [ GuardChecker :: defaultGuardProvider ( $ guard ) => $ guard ] ; } ) ; }
Get guards provider returning a assoc array with provider on key and guard on value .
49,016
protected function registerMigrations ( ) { $ migrationsPath = __DIR__ . '/../../database/migrations' ; $ this -> loadMigrationsFrom ( $ migrationsPath ) ; $ this -> publishes ( [ $ migrationsPath => database_path ( 'migrations' ) ] , 'migrations' ) ; }
Register migrations to work on php artisan migrate command .
49,017
protected function createAccessTokenProvider ( ProviderRepository $ repository ) { Event :: listen ( AccessTokenCreated :: class , function ( $ event ) use ( $ repository ) { $ provider = config ( 'auth.guards.api.provider' ) ; $ repository -> create ( $ event -> tokenId , $ provider ) ; } ) ; }
Create access token provider when access token is created .
49,018
public function create ( $ token , $ provider ) { $ provider = ( new Provider ) -> forceFill ( [ 'oauth_access_token_id' => $ token , 'provider' => $ provider , 'created_at' => new Carbon ( ) , 'updated_at' => new Carbon ( ) , ] ) ; $ provider -> save ( ) ; return $ provider ; }
Store new register on oauth_access_token_providers table .
49,019
public static function getUserProvider ( Authenticatable $ user ) { foreach ( config ( 'auth.providers' ) as $ provider => $ config ) { if ( $ user instanceof $ config [ 'model' ] ) { return $ provider ; } } throw MissingConfigException :: provider ( $ user ) ; }
Get the user provider on configs .
49,020
public static function getProviderGuard ( $ provider , Authenticatable $ user ) { foreach ( config ( 'auth.guards' ) as $ guard => $ content ) { if ( $ content [ 'driver' ] == 'passport' && $ content [ 'provider' ] == $ provider ) { return $ guard ; } } throw MissingConfigException :: guard ( $ user ) ; }
Get the guard of specific provider to passport driver .
49,021
public static function getUserGuard ( Authenticatable $ user ) { $ provider = self :: getUserProvider ( $ user ) ; return self :: getProviderGuard ( $ provider , $ user ) ; }
Get the user guard on provider with passport driver .
49,022
public function tokens ( ) { return $ this -> hasMany ( Token :: class , 'user_id' ) -> join ( 'oauth_access_token_providers' , function ( $ join ) { $ join -> on ( 'oauth_access_tokens.id' , '=' , 'oauth_access_token_id' ) -> where ( 'oauth_access_token_providers.provider' , '=' , AuthConfigHelper :: getUserProvider (...
Get all of the access tokens for the user relating with Provider .
49,023
public function createToken ( $ name , array $ scopes = [ ] ) { $ defaultProvider = config ( 'auth.guards.api.provider' ) ; $ userProvider = AuthConfigHelper :: getUserProvider ( $ this ) ; config ( [ 'auth.guards.api.provider' => $ userProvider ] ) ; $ token = Container :: getInstance ( ) -> make ( PersonalAccessToken...
Create a new personal access token for the user and create .
49,024
public function handle ( $ request , Closure $ next , ... $ guards ) { if ( empty ( $ guards ) ) { $ this -> authenticate ( $ request , $ guards ) ; return $ next ( $ request ) ; } $ psrRequest = ServerRequest :: createRequest ( $ request ) ; try { $ psrRequest = $ this -> server -> validateAuthenticatedRequest ( $ psr...
Handle an incoming request . Authenticates the guard from access token used on request .
49,025
public function canBeAuthenticated ( Authenticatable $ user , $ guards ) { $ userGuard = AuthConfigHelper :: getUserGuard ( $ user ) ; return in_array ( $ userGuard , $ guards ) ; }
Check if user acting has the required guards and scopes on request .
49,026
public function getTokenGuard ( Token $ token , $ guards ) { $ providers = GuardChecker :: getGuardsProviders ( $ guards ) ; return $ providers -> has ( $ token -> provider ) ? [ $ providers -> get ( $ token -> provider ) ] : [ ] ; }
Get guard related with token .
49,027
public function compileFromName ( string $ fromName = null ) : string { $ settings = Plugin :: getInstance ( ) -> getSettings ( ) ; return $ settings -> prependSender . ( $ settings -> prependSender && $ fromName ? ' ' : '' ) . $ fromName ; }
Compiles the From name value from the submitted name .
49,028
public function compileSubject ( string $ subject = null ) : string { $ settings = Plugin :: getInstance ( ) -> getSettings ( ) ; return $ settings -> prependSubject . ( $ settings -> prependSubject && $ subject ? ' - ' : '' ) . $ subject ; }
Compiles the real email subject from the submitted subject .
49,029
public function compileTextBody ( Submission $ submission ) : string { $ fields = [ ] ; if ( $ submission -> fromName ) { $ fields [ Craft :: t ( 'contact-form' , 'Name' ) ] = $ submission -> fromName ; } $ fields [ Craft :: t ( 'contact-form' , 'Email' ) ] = $ submission -> fromEmail ; if ( is_array ( $ submission -> ...
Compiles the real email textual body from the submitted message .
49,030
public function compileHtmlBody ( string $ textBody ) : string { $ html = Html :: encode ( $ textBody ) ; $ html = Markdown :: process ( $ html ) ; return $ html ; }
Compiles the real email HTML body from the compiled textual body .
49,031
public function actionIndex ( ) { $ this -> requirePostRequest ( ) ; $ request = Craft :: $ app -> getRequest ( ) ; $ plugin = Plugin :: getInstance ( ) ; $ settings = $ plugin -> getSettings ( ) ; $ submission = new Submission ( ) ; $ submission -> fromEmail = $ request -> getBodyParam ( 'fromEmail' ) ; $ submission -...
Sends a contact form submission .
49,032
public function setPremiumSms ( $ shortcode , $ keyword , $ tariff , $ mid = null , $ member = null ) { $ this -> typeDetails [ 'shortcode' ] = $ shortcode ; $ this -> typeDetails [ 'keyword' ] = $ keyword ; $ this -> typeDetails [ 'tariff' ] = $ tariff ; if ( $ mid != null ) { $ this -> typeDetails [ 'mid' ] = $ mid ;...
Send a premium SMS
49,033
public function verify ( SignedRequest $ request ) { $ payload = $ this -> buildPayloadFromRequest ( $ request ) ; $ calculatedSignature = \ hash_hmac ( self :: HMAC_HASH_ALGO , $ payload , $ this -> signingKey , true ) ; $ expectedSignature = \ base64_decode ( $ request -> signature , true ) ; return \ hash_equals ( $...
Verify that the signed request was submitted from MessageBird using the known key .
49,034
public static function createFromGlobals ( ) { $ body = file_get_contents ( 'php://input' ) ; $ queryParameters = $ _GET ; $ requestTimestamp = $ _SERVER [ 'HTTP_MESSAGEBIRD_REQUEST_TIMESTAMP' ] ; $ signature = $ _SERVER [ 'HTTP_MESSAGEBIRD_SIGNATURE' ] ; $ signedRequest = new SignedRequest ( ) ; $ signedRequest -> loa...
Create a new SignedRequest from PHP globals .
49,035
public static function create ( $ query , $ signature , $ requestTimestamp , $ body ) { if ( is_string ( $ query ) ) { $ queryParameters = array ( ) ; parse_str ( $ query , $ queryParameters ) ; } else { $ queryParameters = $ query ; } $ signedRequest = new SignedRequest ( ) ; $ signedRequest -> loadFromArray ( compact...
Create a SignedRequest from the provided data .
49,036
public function getCountry ( ) { $ countryCode = $ this -> getImprintValue ( 'country' ) ; if ( ! $ countryCode ) { return '' ; } try { $ countryInfo = $ this -> countryInformationAcquirer -> getCountryInfo ( $ countryCode ) ; $ countryName = $ countryInfo -> getFullNameLocale ( ) ; } catch ( NoSuchEntityException $ e ...
Retrieve the specific country name by the selected country code
49,037
public function getEmail ( $ antispam = false ) { $ email = $ this -> getImprintValue ( 'email' ) ; if ( ! $ email ) { return '' ; } if ( ! $ antispam ) { return $ email ; } $ parts = explode ( '@' , $ email ) ; if ( count ( $ parts ) != 2 ) { return $ email ; } $ html = '<a href="#" onclick="toRecipient();">' ; $ html...
Try to limit spam by generating a javascript email link
49,038
public function aroundGetProductDetailsHtml ( \ Magento \ Catalog \ Block \ Product \ ListProduct $ subject , \ Closure $ proceed , \ Magento \ Catalog \ Model \ Product $ product ) { $ result = $ proceed ( $ product ) ; $ deliveryBlock = $ subject -> getLayout ( ) -> getBlock ( 'product.info.delivery' ) ; if ( $ deliv...
Retrieve product details html
49,039
private function createCmsPage ( $ pageData ) { $ filename = $ pageData [ 'filename' ] ; $ template = $ this -> getTemplatePath ( 'pages' ) . $ filename ; if ( ! file_exists ( $ template ) ) { return ; } unset ( $ pageData [ 'filename' ] ) ; $ templateContent = @ file_get_contents ( $ template ) ; $ data = [ 'stores' =...
Create a cms page with the given data
49,040
private function createCmsBlock ( $ blockData ) { $ filename = $ blockData [ 'filename' ] ; $ template = $ this -> getTemplatePath ( 'blocks' ) . $ filename ; if ( ! file_exists ( $ template ) ) { return ; } unset ( $ blockData [ 'filename' ] ) ; $ templateContent = @ file_get_contents ( $ template ) ; $ data = [ 'stor...
Create a cms block with the given data
49,041
public function afterGetData ( \ Magento \ Email \ Model \ Source \ Variables $ subject , $ result ) { return array_merge ( $ result , $ this -> getAdditionalConfigVariables ( ) ) ; }
Return available config variables
49,042
public function afterGetVariables ( \ Magento \ Email \ Block \ Adminhtml \ Template \ Edit \ Form $ subject , $ result ) { $ additionalConfigValues = $ this -> variables -> getAdditionalConfigVariables ( ) ; $ optionArray = [ ] ; foreach ( $ additionalConfigValues as $ variable ) { $ optionArray [ ] = [ 'value' => '{{...
Retrieve variables to insert into email
49,043
public function getSubProcessorCodes ( ) { $ codes = [ ] ; foreach ( $ this -> subProcessors -> getIterator ( ) as $ code => $ object ) { $ codes [ ] = $ code ; } return $ codes ; }
Retrieve the subprocessor codes
49,044
protected function periodsSync ( ) { foreach ( $ this -> periods as $ period ) { $ periodKey = $ this -> keys -> period ( $ period ) ; if ( $ this -> noExpiration ( $ periodKey ) ) { $ expireInSeconds = $ this -> newExpiration ( $ period ) ; $ this -> redis -> incrby ( $ periodKey . '_total' , 0 ) ; $ this -> redis -> ...
Sync periods times
49,045
public function top ( $ limit = 5 , $ isLow = false ) { $ cacheKey = $ this -> keys -> cache ( $ limit , $ isLow ) ; $ cachedList = $ this -> cachedList ( $ limit , $ cacheKey ) ; $ visitsIds = $ this -> getVisitsIds ( $ limit , $ this -> keys -> visits , $ isLow ) ; if ( $ visitsIds === $ cachedList -> pluck ( $ this ...
Fetch all time trending subjects .
49,046
public function visits ( ) { if ( $ this -> keys -> id ) { $ this -> redis -> zrem ( $ this -> keys -> visits , $ this -> keys -> id ) ; $ this -> redis -> del ( $ this -> keys -> visits . "_countries:{$this->keys->id}" ) ; $ this -> redis -> del ( $ this -> keys -> visits . "_referers:{$this->keys->id}" ) ; foreach ( ...
reset all time visits
49,047
public function periods ( ) { foreach ( $ this -> periods as $ period => $ days ) { $ periodKey = $ this -> keys -> period ( $ period ) ; $ this -> redis -> del ( $ periodKey ) ; $ this -> redis -> del ( $ periodKey . '_total' ) ; } }
reset day week counters
49,048
public function ips ( $ ips = '*' ) { $ ips = $ this -> redis -> keys ( $ this -> keys -> ip ( $ ips ) ) ; if ( count ( $ ips ) ) { $ this -> redis -> del ( $ ips ) ; } }
reset ips protection
49,049
private function getJson ( $ path , $ zip , $ file , $ assoc = FALSE ) { $ stream = $ zip -> getStream ( $ file ) ; if ( ! $ stream ) { $ this -> h5pF -> setErrorMessage ( $ this -> h5pF -> t ( 'Unable to read file from the package: %fileName' , array ( '%fileName' => $ file ) ) , 'unable-to-read-package-file' ) ; $ zi...
Help read JSON from the archive
49,050
private function getWhitelistRegExp ( $ isLibrary ) { $ whitelist = $ this -> h5pF -> getWhitelist ( $ isLibrary , H5PCore :: $ defaultContentWhitelist , H5PCore :: $ defaultLibraryWhitelistExtras ) ; return array ( $ whitelist , '/\.(' . preg_replace ( '/ +/i' , '|' , preg_quote ( $ whitelist ) ) . ')$/i' ) ; }
Help retrieve file type regexp whitelist from plugin .
49,051
private function getMissingLibraries ( $ libraries ) { $ missing = array ( ) ; foreach ( $ libraries as $ library ) { if ( isset ( $ library [ 'preloadedDependencies' ] ) ) { $ missing = array_merge ( $ missing , $ this -> getMissingDependencies ( $ library [ 'preloadedDependencies' ] , $ libraries ) ) ; } if ( isset (...
Use the dependency declarations to find any missing libraries
49,052
private function getMissingDependencies ( $ dependencies , $ libraries ) { $ missing = array ( ) ; foreach ( $ dependencies as $ dependency ) { $ libString = H5PCore :: libraryToString ( $ dependency ) ; if ( ! isset ( $ libraries [ $ libString ] ) ) { $ missing [ $ libString ] = $ dependency ; } } return $ missing ; }
Helper function for getMissingLibraries searches for dependency required libraries in the provided list of libraries
49,053
private function isExistingFiles ( $ files , $ tmpDir , $ library ) { foreach ( $ files as $ file ) { $ path = str_replace ( array ( '/' , '\\' ) , DIRECTORY_SEPARATOR , $ file [ 'path' ] ) ; if ( ! file_exists ( $ tmpDir . DIRECTORY_SEPARATOR . $ library . DIRECTORY_SEPARATOR . $ path ) ) { $ this -> h5pF -> setErrorM...
Figure out if the provided file paths exists
49,054
private function isValidH5pData ( $ h5pData , $ library_name , $ required , $ optional ) { $ valid = $ this -> isValidRequiredH5pData ( $ h5pData , $ required , $ library_name ) ; $ valid = $ this -> isValidOptionalH5pData ( $ h5pData , $ optional , $ library_name ) && $ valid ; if ( isset ( $ h5pData [ 'coreApi' ] ) &...
Validates h5p . json and library . json data
49,055
private function isValidOptionalH5pData ( $ h5pData , $ requirements , $ library_name ) { $ valid = TRUE ; foreach ( $ h5pData as $ key => $ value ) { if ( isset ( $ requirements [ $ key ] ) ) { $ valid = $ this -> isValidRequirement ( $ value , $ requirements [ $ key ] , $ library_name , $ key ) && $ valid ; } } retur...
Helper function for isValidH5pData
49,056
private function isValidRequirement ( $ h5pData , $ requirement , $ library_name , $ property_name ) { $ valid = TRUE ; if ( is_string ( $ requirement ) ) { if ( $ requirement == 'boolean' ) { if ( ! is_bool ( $ h5pData ) ) { $ this -> h5pF -> setErrorMessage ( $ this -> h5pF -> t ( "Invalid data provided for %property...
Validate a requirement given as regexp or an array of requirements
49,057
private function isValidRequiredH5pData ( $ h5pData , $ requirements , $ library_name ) { $ valid = TRUE ; foreach ( $ requirements as $ required => $ requirement ) { if ( is_int ( $ required ) ) { return $ this -> isValidH5pDataOptions ( $ h5pData , $ requirements , $ library_name ) ; } if ( isset ( $ h5pData [ $ requ...
Validates the required h5p data in libraray . json and h5p . json
49,058
private function getJsonData ( $ filePath , $ return_as_string = FALSE ) { $ json = file_get_contents ( $ filePath ) ; if ( $ json === FALSE ) { return FALSE ; } $ jsonData = json_decode ( $ json , TRUE ) ; if ( $ jsonData === NULL ) { return FALSE ; } return $ return_as_string ? $ json : $ jsonData ; }
Fetch json data from file
49,059
private function arrayCopy ( array $ array ) { $ result = array ( ) ; foreach ( $ array as $ key => $ val ) { if ( is_array ( $ val ) ) { $ result [ $ key ] = self :: arrayCopy ( $ val ) ; } elseif ( is_object ( $ val ) ) { $ result [ $ key ] = clone $ val ; } else { $ result [ $ key ] = $ val ; } } return $ result ; }
Helper function that copies an array
49,060
public function savePackage ( $ content = NULL , $ contentMainId = NULL , $ skipContent = FALSE , $ options = array ( ) ) { if ( $ this -> h5pC -> mayUpdateLibraries ( ) ) { $ this -> saveLibraries ( ) ; } if ( ! $ skipContent ) { $ basePath = $ this -> h5pF -> getUploadedH5pFolderPath ( ) ; $ current_path = $ basePath...
Saves a H5P file
49,061
public function deletePackage ( $ content ) { $ this -> h5pC -> fs -> deleteContent ( $ content ) ; $ this -> h5pC -> fs -> deleteExport ( ( $ content [ 'slug' ] ? $ content [ 'slug' ] . '-' : '' ) . $ content [ 'id' ] . '.h5p' ) ; $ this -> h5pF -> deleteContentData ( $ content [ 'id' ] ) ; }
Delete an H5P package
49,062
private function getFileContents ( $ file ) { if ( file_exists ( $ file ) === FALSE ) { return NULL ; } $ contents = file_get_contents ( $ file ) ; if ( $ contents === FALSE ) { return NULL ; } return $ contents ; }
Get contents of file .
49,063
private function findLibraries ( $ path ) { $ this -> libraries = array ( ) ; if ( is_dir ( $ path ) === FALSE ) { return ; } $ contents = scandir ( $ path ) ; for ( $ i = 0 , $ s = count ( $ contents ) ; $ i < $ s ; $ i ++ ) { if ( $ contents [ $ i ] { 0 } === '.' ) { continue ; } $ libraryPath = $ path . '/' . $ cont...
Scans development directory and find all libraries .
49,064
public function getSemantics ( $ name , $ majorVersion , $ minorVersion ) { $ library = H5PDevelopment :: libraryToString ( $ name , $ majorVersion , $ minorVersion ) ; if ( isset ( $ this -> libraries [ $ library ] ) === FALSE ) { return NULL ; } return $ this -> getFileContents ( $ this -> filesPath . $ this -> libra...
Get semantics for the given library .
49,065
public function saveLibrary ( $ library ) { $ dest = $ this -> path . '/libraries/' . \ H5PCore :: libraryToString ( $ library , TRUE ) ; \ H5PCore :: deleteFileTree ( $ dest ) ; self :: copyFileTree ( $ library [ 'uploadDirectory' ] , $ dest ) ; }
Store the library folder .
49,066
public function saveContent ( $ source , $ content ) { $ dest = "{$this->path}/content/{$content['id']}" ; \ H5PCore :: deleteFileTree ( $ dest ) ; self :: copyFileTree ( $ source , $ dest ) ; }
Store the content folder .
49,067
public function cloneContent ( $ id , $ newId ) { $ path = $ this -> path . '/content/' ; if ( file_exists ( $ path . $ id ) ) { self :: copyFileTree ( $ path . $ id , $ path . $ newId ) ; } }
Creates a stored copy of the content folder .
49,068
public function exportContent ( $ id , $ target ) { $ source = "{$this->path}/content/{$id}" ; if ( file_exists ( $ source ) ) { self :: copyFileTree ( $ source , $ target ) ; } else { self :: dirReady ( $ target ) ; } }
Fetch content folder and save in target directory .
49,069
public function exportLibrary ( $ library , $ target , $ developmentPath = NULL ) { $ folder = \ H5PCore :: libraryToString ( $ library , TRUE ) ; $ srcPath = ( $ developmentPath === NULL ? "/libraries/{$folder}" : $ developmentPath ) ; self :: copyFileTree ( "{$this->path}{$srcPath}" , "{$target}/{$folder}" ) ; }
Fetch library folder and save in target directory .
49,070
public function saveExport ( $ source , $ filename ) { $ this -> deleteExport ( $ filename ) ; if ( ! self :: dirReady ( "{$this->path}/exports" ) ) { throw new Exception ( "Unable to create directory for H5P export file." ) ; } if ( ! copy ( $ source , "{$this->path}/exports/{$filename}" ) ) { throw new Exception ( "U...
Save export in file system
49,071
public function cacheAssets ( & $ files , $ key ) { foreach ( $ files as $ type => $ assets ) { if ( empty ( $ assets ) ) { continue ; } $ content = '' ; foreach ( $ assets as $ asset ) { $ assetContent = file_get_contents ( $ this -> path . $ asset -> path ) ; $ cssRelPath = preg_replace ( '/[^\/]+$/' , '' , $ asset -...
Will concatenate all JavaScrips and Stylesheets into two files in order to improve page performance .
49,072
public function getCachedAssets ( $ key ) { $ files = array ( ) ; $ js = "/cachedassets/{$key}.js" ; if ( file_exists ( $ this -> path . $ js ) ) { $ files [ 'scripts' ] = array ( ( object ) array ( 'path' => $ js , 'version' => '' ) ) ; } $ css = "/cachedassets/{$key}.css" ; if ( file_exists ( $ this -> path . $ css )...
Will check if there are cache assets available for content .
49,073
public function deleteCachedAssets ( $ keys ) { foreach ( $ keys as $ hash ) { foreach ( array ( 'js' , 'css' ) as $ ext ) { $ path = "{$this->path}/cachedassets/{$hash}.{$ext}" ; if ( file_exists ( $ path ) ) { unlink ( $ path ) ; } } } }
Remove the aggregated cache files .
49,074
public function saveFile ( $ file , $ contentId ) { if ( empty ( $ contentId ) ) { $ path = $ this -> getEditorPath ( ) ; } else { $ path = $ this -> path . '/content/' . $ contentId ; } $ path .= '/' . $ file -> getType ( ) . 's' ; self :: dirReady ( $ path ) ; $ path .= '/' . $ file -> getName ( ) ; copy ( $ _FILES [...
Save files uploaded through the editor . The files must be marked as temporary until the content form is saved .
49,075
public function cloneContentFile ( $ file , $ fromId , $ toId ) { if ( $ fromId === 'editor' ) { $ sourcepath = $ this -> getEditorPath ( ) ; } else { $ sourcepath = "{$this->path}/content/{$fromId}" ; } $ sourcepath .= '/' . $ file ; $ filename = basename ( $ file ) ; $ filedir = str_replace ( $ filename , '' , $ file...
Copy a file from another content or editor tmp dir . Used when copy pasting content in H5P Editor .
49,076
public function moveContentDirectory ( $ source , $ contentId = NULL ) { if ( $ source === NULL ) { return NULL ; } if ( $ contentId === NULL || $ contentId == 0 ) { $ target = $ this -> getEditorPath ( ) ; } else { $ target = "{$this->path}/content/{$contentId}" ; } $ contentSource = $ source . DIRECTORY_SEPARATOR . '...
Copy a content from one directory to another . Defaults to cloning content from the current temporary upload folder to the editor path .
49,077
public function removeContentFile ( $ file , $ contentId ) { $ path = "{$this->path}/content/{$contentId}/{$file}" ; if ( file_exists ( $ path ) ) { unlink ( $ path ) ; $ parts = explode ( '/' , $ path ) ; while ( array_pop ( $ parts ) !== NULL ) { $ dir = implode ( '/' , $ parts ) ; if ( is_dir ( $ dir ) && count ( sc...
Checks to see if content has the given file . Used when saving content .
49,078
public function hasPresave ( $ libraryFolder , $ developmentPath = null ) { $ path = is_null ( $ developmentPath ) ? 'libraries' . DIRECTORY_SEPARATOR . $ libraryFolder : $ developmentPath ; $ filePath = realpath ( $ this -> path . DIRECTORY_SEPARATOR . $ path . DIRECTORY_SEPARATOR . 'presave.js' ) ; return file_exists...
Check if the file presave . js exists in the root of the library
49,079
public function getUpgradeScript ( $ machineName , $ majorVersion , $ minorVersion ) { $ upgrades = "/libraries/{$machineName}-{$majorVersion}.{$minorVersion}/upgrades.js" ; if ( file_exists ( $ this -> path . $ upgrades ) ) { return $ upgrades ; } else { return NULL ; } }
Check if upgrades script exist for library .
49,080
public function saveFileFromZip ( $ path , $ file , $ stream ) { $ filePath = $ path . '/' . $ file ; $ matches = array ( ) ; preg_match ( '/(.+)\/[^\/]*$/' , $ filePath , $ matches ) ; self :: dirReady ( $ matches [ 1 ] ) ; return file_put_contents ( $ filePath , $ stream ) ; }
Store the given stream into the given file .
49,081
private static function copyFileTree ( $ source , $ destination ) { if ( ! self :: dirReady ( $ destination ) ) { throw new \ Exception ( 'unabletocopy' ) ; } $ ignoredFiles = self :: getIgnoredFiles ( "{$source}/.h5pignore" ) ; $ dir = opendir ( $ source ) ; if ( $ dir === FALSE ) { trigger_error ( 'Unable to open dir...
Recursive function for copying directories .
49,082
private static function getIgnoredFiles ( $ file ) { if ( file_exists ( $ file ) === FALSE ) { return array ( ) ; } $ contents = file_get_contents ( $ file ) ; if ( $ contents === FALSE ) { return array ( ) ; } return preg_split ( '/\s+/' , $ contents ) ; }
Retrieve array of file names from file .
49,083
public static function toJSON ( $ content ) { return '{"title":' . ( isset ( $ content -> title ) ? json_encode ( $ content -> title ) : 'null' ) . ',"authors":' . ( isset ( $ content -> authors ) ? $ content -> authors : 'null' ) . ',"source":' . ( isset ( $ content -> source ) ? '"' . $ content -> source . '"' : 'nul...
JSON encode metadata
49,084
public static function toDBArray ( $ metadata , $ include_title = true , $ include_missing = true , & $ types = array ( ) ) { $ fields = array ( ) ; if ( ! is_array ( $ metadata ) ) { $ metadata = ( array ) $ metadata ; } foreach ( self :: $ fields as $ key => $ config ) { if ( $ key === 'title' && ! $ include_title ) ...
Make the metadata into an associative array keyed by the property names
49,085
private static function validStats ( $ type , $ sub_type ) { if ( ( $ type === 'content' && $ sub_type === 'shortcode insert' ) || ( $ type === 'library' && $ sub_type === NULL ) || ( $ type === 'results' && $ sub_type === 'content' ) ) { return TRUE ; } elseif ( self :: isAction ( $ type , $ sub_type ) ) { return TRUE...
Check if the event should be included in the statistics counter .
49,086
private static function isAction ( $ type , $ sub_type ) { if ( ( $ type === 'content' && in_array ( $ sub_type , array ( 'create' , 'create upload' , 'update' , 'update upload' , 'upgrade' , 'delete' ) ) ) || ( $ type === 'library' && in_array ( $ sub_type , array ( 'create' , 'update' ) ) ) ) { return TRUE ; } return...
Check if event type is an action .
49,087
protected function getDataArray ( ) { return array ( 'created_at' => $ this -> time , 'type' => $ this -> type , 'sub_type' => empty ( $ this -> sub_type ) ? '' : $ this -> sub_type , 'content_id' => empty ( $ this -> content_id ) ? 0 : $ this -> content_id , 'content_title' => empty ( $ this -> content_title ) ? '' : ...
A helper which makes it easier for systems to save the data . Add all relevant properties to a assoc . array . There are no NULL values . Empty string or 0 is used instead . Used by both Drupal and WordPress .
49,088
public function findCrashedExports ( \ DateTime $ before = null ) { $ qb = $ this -> createQueryBuilder ( 'e' ) ; $ qb -> where ( $ qb -> expr ( ) -> gte ( 'e.crash' , 'e.nbretry' ) ) ; if ( null !== $ before ) { $ qb -> andWhere ( $ qb -> expr ( ) -> lte ( 'e.created' , ':created' ) ) ; $ qb -> setParameter ( ':create...
Returns exports that crashed . If a date is provided only exports created before this date are returned .
49,089
public function getDatabaseCGU ( $ databox_id ) { return $ this -> render ( 'admin/databox/cgus.html.twig' , [ 'languages' => $ this -> app [ 'locales.available' ] , 'cgus' => $ this -> findDataboxById ( $ databox_id ) -> get_cgus ( ) , 'current_locale' => $ this -> app [ 'locale' ] , ] ) ; }
Get databox CGU s
49,090
public function deleteBase ( Request $ request , $ databox_id ) { $ databox = null ; $ success = false ; $ msg = $ this -> app -> trans ( 'An error occured' ) ; try { $ databox = $ this -> findDataboxById ( $ databox_id ) ; if ( $ databox -> get_record_amount ( ) > 0 ) { $ msg = $ this -> app -> trans ( 'admin::base: v...
Delete a databox
49,091
public function reindex ( Request $ request , $ databox_id ) { $ success = false ; try { $ this -> findDataboxById ( $ databox_id ) -> reindex ( ) ; $ success = true ; } catch ( \ Exception $ e ) { } if ( 'json' === $ request -> getRequestFormat ( ) ) { return $ this -> app -> json ( [ 'success' => $ success , 'msg' =>...
Reindex databox content
49,092
public function setIndexable ( Request $ request , $ databox_id ) { $ success = false ; try { $ databox = $ this -> findDataboxById ( $ databox_id ) ; $ indexable = ! ! $ request -> request -> get ( 'indexable' , false ) ; $ this -> getApplicationBox ( ) -> set_databox_indexable ( $ databox , $ indexable ) ; $ success ...
Make a databox indexable
49,093
public function updateDatabaseCGU ( Request $ request , $ databox_id ) { $ databox = $ this -> findDataboxById ( $ databox_id ) ; try { foreach ( $ request -> request -> get ( 'TOU' , [ ] ) as $ loc => $ terms ) { $ databox -> update_cgus ( $ loc , $ terms , ! ! $ request -> request -> get ( 'valid' , false ) ) ; } } c...
Update databox CGU s
49,094
public function mountCollection ( Request $ request , $ databox_id , $ collection_id ) { $ connection = $ this -> getApplicationBox ( ) -> get_connection ( ) ; $ connection -> beginTransaction ( ) ; try { $ authenticator = $ this -> app -> getAuthenticator ( ) ; $ baseId = \ collection :: mount_collection ( $ this -> a...
Mount a collection on a databox
49,095
public function sendLogoPdf ( Request $ request , $ databox_id ) { try { if ( null !== ( $ file = $ request -> files -> get ( 'newLogoPdf' ) ) && $ file -> isValid ( ) ) { if ( $ file -> getClientSize ( ) < 65536 ) { $ databox = $ this -> findDataboxById ( $ databox_id ) ; $ this -> getApplicationBox ( ) -> write_datab...
Set a new logo for a databox
49,096
public function deleteLogoPdf ( Request $ request , $ databox_id ) { $ success = false ; try { $ this -> getApplicationBox ( ) -> write_databox_pic ( $ this -> app [ 'media-alchemyst' ] , $ this -> app [ 'filesystem' ] , $ this -> findDataboxById ( $ databox_id ) , null , \ databox :: PIC_PDF ) ; $ success = true ; } c...
Delete an existing logo for a databox
49,097
public function clearLogs ( Request $ request , $ databox_id ) { $ success = false ; try { $ this -> findDataboxById ( $ databox_id ) -> clear_logs ( ) ; $ success = true ; } catch ( \ Exception $ e ) { } if ( 'json' === $ request -> getRequestFormat ( ) ) { return $ this -> app -> json ( [ 'success' => $ success , 'ms...
Clear databox logs
49,098
public function changeViewName ( Request $ request , $ databox_id ) { if ( null === $ viewName = $ request -> request -> get ( 'viewname' ) ) { $ this -> app -> abort ( 400 , $ this -> app -> trans ( 'Missing view name parameter' ) ) ; } $ success = false ; try { $ this -> findDataboxById ( $ databox_id ) -> set_viewna...
Change the name of a databox
49,099
public function unmountDatabase ( Request $ request , $ databox_id ) { $ success = false ; try { $ databox = $ this -> findDataboxById ( $ databox_id ) ; $ databox -> unmount_databox ( ) ; $ success = true ; } catch ( \ Exception $ e ) { } if ( 'json' === $ request -> getRequestFormat ( ) ) { $ msg = $ success ? $ this...
Unmount a databox