idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
49,900
public function getIp ( ) { if ( ! $ this -> ip ) { if ( $ this -> random ) { $ this -> ip = long2ip ( mt_rand ( ) ) ; } else { $ this -> ip = array_get ( $ _SERVER , 'HTTP_CLIENT_IP' , array_get ( $ _SERVER , 'HTTP_X_FORWARDED_FOR' , array_get ( $ _SERVER , 'HTTP_X_FORWARDED' , array_get ( $ _SERVER , 'HTTP_FORWARDED_FOR' , array_get ( $ _SERVER , 'HTTP_FORWARDED' , array_get ( $ _SERVER , 'REMOTE_ADDR' , '127.0.0.1' ) ) ) ) ) ) ; } } $ this -> ip = explode ( ',' , $ this -> ip ) ; $ this -> ip = trim ( head ( $ this -> ip ) ) ; return $ this -> ip ; }
Get ip from server info .
49,901
public function get ( $ property = '' ) { $ data = $ this -> getData ( ) ; if ( ! $ property ) { return $ data ; } return array_get ( $ data , $ property , '' ) ; }
Get an array or single item of geoip data Also stores data in memory for further requests .
49,902
public function getRaw ( ) { $ ip = $ this -> getIp ( ) ; $ this -> setIp ( $ ip ) ; $ data = array_get ( $ this -> storeRaw , $ ip ) ; if ( ! $ data ) { try { $ data = $ this -> getDriver ( ) -> getRaw ( $ ip ) ; } catch ( \ Exception $ e ) { throw new GeoIPException ( 'Failed to get raw geoip data' , 0 , $ e ) ; } $ this -> storeRaw [ $ ip ] = $ data ; } return $ data ; }
Get the raw geoip data from the driver .
49,903
protected function getData ( ) { $ ip = $ this -> getIp ( ) ; $ this -> setIp ( $ ip ) ; $ data = array_get ( $ this -> store , $ ip ) ; if ( ! $ data ) { try { $ data = $ this -> getDriver ( ) -> get ( $ ip ) ; } catch ( \ Exception $ e ) { throw new GeoIPException ( 'Failed to get geoip data' , 0 , $ e ) ; } $ this -> store [ $ ip ] = $ data ; } return $ data ; }
Get an array or single item of geoip data .
49,904
protected function updateMaxmindDatabase ( ) { $ maxmindDatabaseUrl = array_get ( $ this -> config , 'maxmind.download' , 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz' ) ; $ database = array_get ( $ this -> config , 'maxmind.database' , false ) ; if ( ! file_exists ( $ dir = pathinfo ( $ database , PATHINFO_DIRNAME ) ) ) { mkdir ( $ dir , 0777 , true ) ; } try { $ file = $ this -> guzzle -> get ( $ maxmindDatabaseUrl ) -> getBody ( ) ; file_put_contents ( $ database , gzdecode ( $ file ) ) ; } catch ( Exception $ e ) { return false ; } return $ database ; }
Update function for maxmind database .
49,905
public function get ( $ ip ) { $ data = $ this -> getRaw ( $ ip ) ; if ( empty ( $ data ) || ( array_get ( $ data , 'status' ) === 'fail' ) ) { return $ this -> getDefault ( ) ; } return [ 'city' => array_get ( $ data , 'city' ) , 'country' => array_get ( $ data , 'country' ) , 'countryCode' => array_get ( $ data , 'countryCode' ) , 'latitude' => ( float ) number_format ( array_get ( $ data , 'lat' ) , 5 ) , 'longitude' => ( float ) number_format ( array_get ( $ data , 'lon' ) , 5 ) , 'region' => array_get ( $ data , 'regionName' ) , 'regionCode' => array_get ( $ data , 'region' ) , 'timezone' => array_get ( $ data , 'timezone' ) , 'postalCode' => array_get ( $ data , 'zip' ) , ] ; }
Get array of data using ip - api .
49,906
protected function getUrl ( $ ip ) { $ baseUrl = 'http://ip-api.com/json/' ; $ key = '' ; if ( array_get ( $ this -> config , 'key' , false ) ) { $ baseUrl = 'https://pro.ip-api.com/json/' ; $ key = array_get ( $ this -> config , 'key' ) ; } return $ baseUrl . $ ip . ( ( $ key ) ? '?key=' . $ key : '' ) ; }
Get the ip - api url add key and change base url if pro user .
49,907
public function get ( $ ip ) { $ data = $ this -> getRaw ( $ ip ) ; if ( empty ( $ data ) ) { return $ this -> getDefault ( ) ; } return [ 'city' => $ data -> city -> name , 'country' => $ data -> country -> name , 'countryCode' => $ data -> country -> isoCode , 'latitude' => ( float ) number_format ( $ data -> location -> latitude , 5 ) , 'longitude' => ( float ) number_format ( $ data -> location -> longitude , 5 ) , 'region' => $ data -> mostSpecificSubdivision -> name , 'regionCode' => $ data -> mostSpecificSubdivision -> isoCode , 'continent' => $ data -> continent -> name , 'continentCode' => $ data -> continent -> code , 'timezone' => $ data -> location -> timeZone , 'postalCode' => $ data -> postal -> code , ] ; }
Get array of data using Maxmind .
49,908
protected function create ( ) { if ( array_get ( $ this -> config , 'user_id' , false ) ) { return $ this -> createWebClient ( ) ; } if ( array_get ( $ this -> config , 'database' , false ) ) { return $ this -> createDatabase ( ) ; } throw new InvalidCredentialsException ( ) ; }
Create the maxmind driver based on config .
49,909
protected function createWebClient ( ) { $ userId = array_get ( $ this -> config , 'user_id' , false ) ; $ licenseKey = array_get ( $ this -> config , 'license_key' , false ) ; if ( ! $ userId || ! $ licenseKey ) { throw new InvalidCredentialsException ( ) ; } return new Client ( $ userId , $ licenseKey ) ; }
Create the maxmind web client .
49,910
protected function createDatabase ( ) { $ database = array_get ( $ this -> config , 'database' , false ) ; if ( ! $ database || ! file_exists ( $ database ) ) { throw new InvalidCredentialsException ( ) ; } try { return new Reader ( $ database ) ; } catch ( \ MaxMind \ Db \ Reader \ InvalidDatabaseException $ e ) { throw new InvalidDatabaseException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } }
Create the maxmind database reader .
49,911
protected function resolveUses ( string $ uses ) { $ result = $ this -> parseAdvancedUses ( $ uses ) ; return ! empty ( $ result -> getRoot ( ) ) ? $ result : $ uses ; }
prepare use variable for using .
49,912
protected function parseMultiLevelsValueCollection ( SimpleXMLElement $ content , MultiLevel $ multilevel ) : array { $ value = [ ] ; $ result = [ ] ; $ features = $ content -> { $ multilevel -> getRoot ( ) } ; if ( ! empty ( $ features ) ) { foreach ( $ features as $ key => $ feature ) { foreach ( $ multilevel as $ use ) { if ( \ strpos ( $ use , '{' ) !== false ) { $ secondary = $ this -> resolveUses ( $ use ) ; $ value [ $ secondary -> getKey ( ) ] = $ this -> parseMultiLevelsValueCollection ( $ feature , $ secondary ) ; } else { list ( $ name , $ as ) = \ strpos ( $ use , '>' ) !== false ? \ explode ( '>' , $ use , 2 ) : [ $ use , $ use ] ; if ( \ preg_match ( '/^([A-Za-z0-9_\-\.]+)\((.*)\=(.*)\)$/' , $ name , $ matches ) ) { $ as = alias_get ( $ as , $ name ) ; $ item = $ this -> getSelfMatchingValue ( $ feature , $ matches , $ as ) ; if ( \ is_null ( $ as ) ) { $ value = \ array_merge ( $ value , $ item ) ; } else { Arr :: set ( $ value , $ as , $ item ) ; } } else { $ name = alias_get ( $ name , '@' ) ; Arr :: set ( $ value , $ as , $ this -> getValue ( $ feature , $ name ) ) ; } } } $ result [ ] = $ value ; } } return $ result ; }
Resolve values by collection of multi levels .
49,913
protected function filterValue ( $ value , ? string $ filter = null ) { $ resolver = $ this -> getFilterResolver ( $ filter ) ; if ( \ method_exists ( $ resolver [ 0 ] , $ resolver [ 1 ] ) ) { return $ this -> callFilterResolver ( $ resolver , $ value ) ; } return $ value ; }
Filter value .
49,914
protected function resolveValue ( array $ config , string $ hash ) { if ( ! isset ( $ config [ 'uses' ] ) ) { return $ config [ 'default' ] ?? null ; } if ( ! \ is_array ( $ config [ 'uses' ] ) ) { return $ this -> getValue ( $ this -> getContent ( ) , $ config [ 'uses' ] , $ hash ) ; } $ values = [ ] ; foreach ( $ config [ 'uses' ] as $ use ) { $ values [ ] = $ this -> getValue ( $ this -> getContent ( ) , $ use , $ hash ) ; } return $ values ; }
Resolve value from content .
49,915
protected function getFilterResolver ( string $ filter ) : array { $ class = $ filter ; $ method = 'filter' ; $ position = \ strpos ( $ filter , '@' ) ; if ( $ position === 0 ) { $ method = 'filter' . \ ucwords ( \ substr ( $ filter , 1 ) ) ; return [ $ this , $ method ] ; } if ( $ position !== false ) { list ( $ class , $ method ) = \ explode ( '@' , $ filter , 2 ) ; } return $ this -> makeFilterResolver ( $ class , $ method ) ; }
Get filter resolver .
49,916
protected function parseData ( $ data ) { $ hash = \ hash ( 'sha256' , microtime ( true ) ) ; $ value = $ data ; $ filter = null ; if ( \ is_array ( $ data ) ) { $ value = $ this -> resolveValue ( $ data , $ hash ) ; $ filter = $ data [ 'filter' ] ?? null ; } if ( $ value === $ hash ) { $ value = $ data [ 'default' ] ?? null ; } if ( ! \ is_null ( $ filter ) ) { $ value = $ this -> filterValue ( $ value , $ filter ) ; } return $ value ; }
Parse single data .
49,917
public function rebase ( string $ base = null ) : self { $ this -> content = data_get ( $ this -> getOriginalContent ( ) , $ base ) ; return $ this ; }
Rebase document node .
49,918
public function namespaced ( string $ namespace , array $ schema , array $ config = [ ] ) : array { $ document = $ this -> getContent ( ) ; $ namespaces = $ this -> getAvailableNamespaces ( ) ; if ( ! \ is_null ( $ namespace ) && isset ( $ namespaces [ $ namespace ] ) ) { $ document = $ document -> children ( $ namespaces [ $ namespace ] ) ; } $ this -> content = $ document ; return $ this -> parse ( $ schema , $ config ) ; }
Set document namespace and parse the XML .
49,919
protected function getValueAttribute ( SimpleXMLElement $ content , string $ use , $ default = null ) { return $ this -> castValue ( $ this -> getRawValueAttribute ( $ content , $ use , $ default ) ) ; }
Resolve value by uses as attribute .
49,920
protected function getRawValueAttribute ( SimpleXMLElement $ content , ? string $ use , $ default = null ) { list ( $ value , $ attribute ) = \ explode ( '::' , $ use , 2 ) ; if ( ! empty ( $ value ) ) { if ( \ is_null ( $ parent = object_get ( $ content , $ value ) ) ) { return $ default ; } } else { $ parent = $ content ; } $ attributes = $ parent -> attributes ( ) ; return data_get ( $ attributes , $ attribute , $ default ) ; }
Resolve value by uses as attribute as raw .
49,921
protected function getValueData ( SimpleXMLElement $ content , ? string $ use , $ default = null ) { $ value = $ this -> castValue ( data_get ( $ content , $ use ) ) ; if ( empty ( $ value ) && ! \ in_array ( $ value , [ '0' ] ) ) { return $ default ; } return $ value ; }
Resolve value by uses as data .
49,922
protected function getSelfMatchingValue ( SimpleXMLElement $ content , array $ matches = [ ] , ? string $ alias = null ) : array { $ name = $ matches [ 1 ] ; $ key = $ matches [ 2 ] ; $ meta = $ matches [ 3 ] ; $ item = [ ] ; $ uses = ( $ key == '@' ? $ meta : "{$key},{$meta}" ) ; if ( \ is_null ( $ alias ) ) { $ alias = $ name ; } $ collection = $ this -> getValue ( $ content , \ sprintf ( '%s[%s]' , $ name , $ uses ) ) ; foreach ( ( array ) $ collection as $ collect ) { $ v = $ collect [ $ meta ] ; if ( $ key == '@' ) { $ item [ $ alias ] [ ] = $ v ; } else { $ item [ $ collect [ $ key ] ] = $ v ; } } return $ item ; }
Get self matching value .
49,923
protected function getAvailableNamespaces ( ) : ? array { if ( \ is_null ( $ this -> namespaces ) ) { $ this -> namespaces = $ this -> getOriginalContent ( ) -> getNameSpaces ( true ) ; } return $ this -> namespaces ; }
Get available namespaces and cached it during runtime to avoid overhead .
49,924
public function files ( ) { if ( ! $ this -> hasRequestParameter ( 'uri' ) ) { throw new common_exception_MissingParameter ( 'uri' , __METHOD__ ) ; } $ itemUri = $ this -> getRequestParameter ( 'uri' ) ; $ item = $ this -> getResource ( $ itemUri ) ; if ( ! $ this -> hasRequestParameter ( 'lang' ) ) { throw new common_exception_MissingParameter ( 'lang' , __METHOD__ ) ; } $ itemLang = $ this -> getRequestParameter ( 'lang' ) ; $ filters = array ( ) ; if ( $ this -> hasRequestParameter ( 'filters' ) ) { $ filterParameter = $ this -> getRequestParameter ( 'filters' ) ; if ( is_array ( $ filterParameter ) ) { foreach ( $ filterParameter as $ filter ) { if ( preg_match ( '/\/\*/' , $ filter [ 'mime' ] ) ) { $ this -> logWarning ( 'Stars mime type are not yet supported, filter "' . $ filter [ 'mime' ] . '" will fail' ) ; } $ filters [ ] = $ filter [ 'mime' ] ; } } else { if ( preg_match ( '/\/\*/' , $ filterParameter ) ) { $ this -> logWarning ( 'Stars mime type are not yet supported, filter "' . $ filterParameter . '" will fail' ) ; } $ filters = array_map ( 'trim' , explode ( ',' , $ filterParameter ) ) ; } } $ depth = $ this -> hasRequestParameter ( 'depth' ) ? $ this -> getRequestParameter ( 'depth' ) : 1 ; $ resolver = new ItemMediaResolver ( $ item , $ itemLang ) ; $ asset = $ resolver -> resolve ( $ this -> getRequestParameter ( 'path' ) ) ; $ data = $ asset -> getMediaSource ( ) -> getDirectory ( $ asset -> getMediaIdentifier ( ) , $ filters , $ depth ) ; foreach ( $ data [ 'children' ] as & $ child ) { if ( isset ( $ child [ 'parent' ] ) ) { $ child [ 'url' ] = \ tao_helpers_Uri :: url ( 'files' , 'ItemContent' , 'taoItems' , array ( 'uri' => $ itemUri , 'lang' => $ itemLang , '1' => $ child [ 'parent' ] ) ) ; unset ( $ child [ 'parent' ] ) ; } } $ this -> returnJson ( $ data ) ; }
Returns a json encoded array describign a directory
49,925
public function fileExists ( ) { if ( ! $ this -> hasRequestParameter ( 'uri' ) || ! $ this -> hasRequestParameter ( 'path' ) || ! $ this -> hasRequestParameter ( 'lang' ) ) { throw new common_exception_MissingParameter ( ) ; } $ item = $ this -> getResource ( $ this -> getRequestParameter ( 'uri' ) ) ; $ itemLang = $ this -> getRequestParameter ( 'lang' ) ; try { $ resolver = new ItemMediaResolver ( $ item , $ itemLang ) ; $ asset = $ resolver -> resolve ( $ this -> getRequestParameter ( 'path' ) ) ; $ asset -> getMediaSource ( ) -> getFileInfo ( $ asset -> getMediaIdentifier ( ) ) ; $ found = true ; } catch ( tao_models_classes_FileNotFoundException $ exception ) { $ found = false ; } return $ this -> returnJson ( array ( 'exists' => $ found ) ) ; }
Returns whenever or not a file exists at the indicated path
49,926
public function delete ( ) { if ( ! $ this -> hasRequestParameter ( 'uri' ) || ! $ this -> hasRequestParameter ( 'path' ) || ! $ this -> hasRequestParameter ( 'lang' ) ) { throw new common_exception_MissingParameter ( ) ; } $ item = $ this -> getResource ( $ this -> getRequestParameter ( 'uri' ) ) ; $ itemLang = $ this -> getRequestParameter ( 'lang' ) ; $ resolver = new ItemMediaResolver ( $ item , $ itemLang ) ; $ asset = $ resolver -> resolve ( $ this -> getRequestParameter ( 'path' ) ) ; $ deleted = $ asset -> getMediaSource ( ) -> delete ( $ asset -> getMediaIdentifier ( ) ) ; return $ this -> returnJson ( array ( 'deleted' => $ deleted ) ) ; }
Delete a file from the item directory
49,927
protected function getMediaSource ( $ urlPrefix , $ item , $ itemLang ) { $ resolver = new ItemMediaResolver ( $ item , $ itemLang ) ; $ asset = $ resolver -> resolve ( $ urlPrefix ) ; return $ asset -> getMediaSource ( ) ; }
Get the media source based on the partial url
49,928
protected function defaultData ( ) { parent :: defaultData ( ) ; if ( $ this -> hasRequestParameter ( 'uri' ) ) { $ uri = $ this -> getRequestParameter ( 'uri' ) ; $ classUri = $ this -> getRequestParameter ( 'classUri' ) ; if ( ! empty ( $ uri ) ) { $ item = $ this -> getResource ( tao_helpers_Uri :: decode ( $ uri ) ) ; $ this -> setData ( 'label' , $ item -> getLabel ( ) ) ; $ this -> setData ( 'authoringUrl' , _url ( 'authoring' , 'Items' , 'taoItems' , array ( 'uri' => $ uri , 'classUri' => $ classUri ) ) ) ; $ this -> setData ( 'previewUrl' , $ this -> getClassService ( ) -> getPreviewUrl ( $ item ) ) ; } } }
overwrite the parent defaultData adding the item label to be sent to the view
49,929
public function editItemClass ( ) { $ this -> defaultData ( ) ; $ clazz = $ this -> getClass ( $ this -> getRequestParameter ( 'id' ) ) ; if ( $ this -> hasRequestParameter ( 'property_mode' ) ) { $ this -> setSessionAttribute ( 'property_mode' , $ this -> getRequestParameter ( 'property_mode' ) ) ; } $ myForm = $ this -> getClassForm ( $ clazz , $ this -> getClassService ( ) -> getRootClass ( ) ) ; if ( $ this -> hasWriteAccess ( $ clazz -> getUri ( ) ) ) { if ( $ myForm -> isSubmited ( ) ) { if ( $ myForm -> isValid ( ) ) { if ( $ clazz instanceof core_kernel_classes_Resource ) { $ this -> setData ( "selectNode" , tao_helpers_Uri :: encode ( $ clazz -> getUri ( ) ) ) ; } $ this -> setData ( 'message' , __ ( 'Class schema saved' ) ) ; $ this -> setData ( 'reload' , false ) ; } } } else { $ myForm -> setActions ( array ( ) ) ; } $ this -> setData ( 'formTitle' , __ ( 'Manage item class schema' ) ) ; $ this -> setData ( 'myForm' , $ myForm -> render ( ) ) ; $ this -> setView ( 'form.tpl' , 'tao' ) ; }
Edit a class
49,930
public function authoring ( ) { $ this -> defaultData ( ) ; $ item = $ this -> getResource ( $ this -> getRequestParameter ( 'id' ) ) ; if ( ! $ this -> isLocked ( $ item , 'item_locked.tpl' ) ) { $ this -> setData ( 'error' , false ) ; try { $ itemModel = $ this -> getClassService ( ) -> getItemModel ( $ item ) ; if ( ! is_null ( $ itemModel ) ) { $ itemModelImpl = $ this -> getClassService ( ) -> getItemModelImplementation ( $ itemModel ) ; $ authoringUrl = $ itemModelImpl -> getAuthoringUrl ( $ item ) ; if ( ! empty ( $ authoringUrl ) ) { LockManager :: getImplementation ( ) -> setLock ( $ item , $ this -> getSession ( ) -> getUser ( ) -> getIdentifier ( ) ) ; return $ this -> forwardUrl ( $ authoringUrl ) ; } } throw new common_exception_NoImplementation ( ) ; $ this -> setData ( 'instanceUri' , tao_helpers_Uri :: encode ( $ item -> getUri ( ) , false ) ) ; } catch ( Exception $ e ) { if ( $ e instanceof InterruptedActionException ) { throw $ e ; } $ this -> setData ( 'error' , true ) ; if ( ! empty ( $ itemModel ) && $ itemModel instanceof core_kernel_classes_Resource ) { $ errorMsg = __ ( 'No item authoring tool available for the selected type of item: %s' . $ itemModel -> getLabel ( ) ) ; } else { $ errorMsg = __ ( 'No item type selected for the current item.' ) . " {$item->getLabel()} " . __ ( 'Please select first the item type!' ) ; } $ this -> setData ( 'errorMsg' , $ errorMsg ) ; } } }
Item Authoring tool loader action
49,931
protected function getItemPacker ( ) { $ itemModel = $ this -> itemService -> getItemModel ( $ this -> item ) ; if ( is_null ( $ itemModel ) ) { throw new common_exception_NoImplementation ( 'No item model for item ' . $ this -> item -> getUri ( ) ) ; } $ impl = $ this -> itemService -> getItemModelImplementation ( $ itemModel ) ; if ( is_null ( $ impl ) ) { throw new common_exception_NoImplementation ( 'No implementation for model ' . $ itemModel -> getUri ( ) ) ; } $ packerClass = $ impl -> getPackerClass ( ) ; if ( is_null ( $ packerClass ) || get_parent_class ( $ packerClass ) !== 'oat\taoItems\model\pack\ItemPacker' ) { throw new common_exception_NoImplementation ( 'The packer class seems to be not implemented' ) ; } return new $ packerClass ( ) ; }
Get the packer for the item regarding it s implementation .
49,932
public function pack ( $ assetEncoders = array ( ) , $ nestedResourcesInclusion = true ) { try { $ itemPacker = $ this -> getItemPacker ( ) ; $ itemPacker -> setAssetEncoders ( $ assetEncoders ) ; $ itemPacker -> setNestedResourcesInclusion ( $ nestedResourcesInclusion ) ; $ itemPack = $ itemPacker -> packItem ( $ this -> item , $ this -> lang , $ this -> getStorageDirectory ( ) ) ; } catch ( Exception $ e ) { throw new common_Exception ( 'The item ' . $ this -> item -> getUri ( ) . ' cannot be packed : ' . $ e -> getMessage ( ) ) ; } return $ itemPack ; }
Pack an item .
49,933
public function getItemCategories ( RdfResource $ item ) { $ categories = [ ] ; foreach ( $ item -> getTypes ( ) as $ class ) { $ eligibleProperties = $ this -> getElligibleProperties ( $ class ) ; $ propertiesValues = $ item -> getPropertiesValues ( array_keys ( $ eligibleProperties ) ) ; foreach ( $ propertiesValues as $ propertyValues ) { foreach ( $ propertyValues as $ value ) { if ( $ value instanceof RdfResource ) { $ sanitizedIdentifier = self :: sanitizeCategoryName ( $ value -> getLabel ( ) ) ; } else { $ sanitizedIdentifier = self :: sanitizeCategoryName ( ( string ) $ value ) ; } $ categories [ ] = $ sanitizedIdentifier ; } } } return $ categories ; }
Get the categories of an item
49,934
public function getElligibleProperties ( RdfClass $ class ) { $ properties = $ this -> getItemService ( ) -> getClazzProperties ( $ class , new RdfClass ( self :: ITEM_CLASS_URI ) ) ; return array_filter ( $ properties , function ( $ property ) { if ( in_array ( $ property -> getUri ( ) , self :: $ excludedPropUris ) ) { return false ; } $ widget = $ property -> getWidget ( ) ; return ! is_null ( $ widget ) && in_array ( $ widget -> getUri ( ) , self :: $ supportedWidgetUris ) ; } ) ; }
Get the properties from a class that can be exposed
49,935
public function doesExposeCategory ( RdfProperty $ property ) { $ exposeProperty = new RdfProperty ( self :: EXPOSE_PROP_URI ) ; $ expose = $ property -> getOnePropertyValue ( $ exposeProperty ) ; return ! is_null ( $ expose ) && $ expose -> getUri ( ) === GenerisRdf :: GENERIS_TRUE ; }
Check if a property is exposed
49,936
public function exposeCategory ( RdfProperty $ property , $ value ) { $ exposeProperty = new RdfProperty ( self :: EXPOSE_PROP_URI ) ; if ( $ value == true ) { $ property -> setPropertyValue ( $ exposeProperty , GenerisRdf :: GENERIS_TRUE ) ; } else { $ property -> removePropertyValue ( $ exposeProperty , GenerisRdf :: GENERIS_TRUE ) ; } }
Expose or not a property
49,937
public function getItemService ( ) { if ( is_null ( $ this -> itemService ) ) { $ this -> itemService = taoItems_models_classes_ItemsService :: singleton ( ) ; } return $ this -> itemService ; }
Service getter and initializer .
49,938
public static function copyResources ( $ sourceDirectory , $ destinationDirectory , $ excludeFiles = array ( ) ) { $ exclude = array_merge ( $ excludeFiles , array ( '.' , '..' , '.svn' ) ) ; $ success = true ; foreach ( scandir ( $ sourceDirectory ) as $ file ) { if ( ! in_array ( $ file , $ exclude ) ) { $ success &= tao_helpers_File :: copy ( $ sourceDirectory . $ file , $ destinationDirectory . $ file , true ) ; } } return $ success ; }
Copy the resources from one directory to another
49,939
public static function setContext ( $ parameters , $ prefix = '' ) { self :: $ context = array ( ) ; foreach ( $ parameters as $ key => $ value ) { self :: $ context [ $ prefix . $ key ] = $ value ; } }
Short description of method setContext
49,940
public function getDirectory ( $ parentLink = '' , $ acceptableMime = array ( ) , $ depth = 1 ) { if ( ! tao_helpers_File :: securityCheck ( $ parentLink ) ) { throw new common_exception_Error ( __ ( 'Your path contains error' ) ) ; } $ label = rtrim ( $ parentLink , '/' ) ; if ( strrpos ( $ parentLink , '/' ) !== false && substr ( $ parentLink , - 1 ) !== '/' ) { $ label = substr ( $ parentLink , strrpos ( $ parentLink , '/' ) + 1 ) ; $ parentLink = $ parentLink . '/' ; } if ( in_array ( $ parentLink , array ( '' , '/' ) ) ) { $ label = $ this -> getItem ( ) -> getLabel ( ) ; $ parentLink = '/' ; } $ data = array ( 'path' => $ parentLink , 'label' => $ label ) ; if ( $ depth <= 0 ) { $ data [ 'parent' ] = $ parentLink ; return $ data ; } $ children = array ( ) ; $ itemDirectory = $ this -> getItemDirectory ( ) ; if ( $ parentLink != '/' ) { $ directory = $ itemDirectory -> getDirectory ( $ parentLink ) ; } else { $ directory = $ itemDirectory ; } $ iterator = $ directory -> getFlyIterator ( ) ; foreach ( $ iterator as $ content ) { if ( $ content instanceof Directory ) { $ children [ ] = $ this -> getDirectory ( $ itemDirectory -> getRelPath ( $ content ) , $ acceptableMime , $ depth - 1 ) ; } else { $ fileInfo = $ this -> getInfoFromFile ( $ content ) ; if ( empty ( $ acceptableMime ) || in_array ( $ fileInfo [ 'mime' ] , $ acceptableMime ) ) { $ children [ ] = $ fileInfo ; } } } $ data [ 'children' ] = $ children ; return $ data ; }
Get a array representing the tree of directory
49,941
public function download ( $ link ) { $ file = $ this -> getFile ( $ link ) ; $ relPath = $ this -> getItemDirectory ( ) -> getRelPath ( $ file ) ; $ tmpDir = rtrim ( \ tao_helpers_File :: createTempDir ( ) , '/' ) ; $ tmpFile = $ tmpDir . $ relPath ; if ( ! is_dir ( dirname ( $ tmpFile ) ) ) { mkdir ( dirname ( $ tmpFile ) , 0755 , true ) ; } if ( ( $ resource = fopen ( $ tmpFile , 'w' ) ) !== false ) { stream_copy_to_stream ( $ file -> readStream ( ) , $ resource ) ; fclose ( $ resource ) ; return $ tmpFile ; } throw new \ common_Exception ( 'Unable to write "' . $ link . '" into tmp folder("' . $ tmpFile . '").' ) ; }
Copy file content to temp file . Path is return to be downloaded
49,942
public function add ( $ source , $ fileName , $ parent ) { if ( ! \ tao_helpers_File :: securityCheck ( $ fileName , true ) ) { throw new \ common_Exception ( 'Unsecured filename "' . $ fileName . '"' ) ; } if ( ( $ resource = fopen ( $ source , 'r' ) ) === false ) { throw new \ common_Exception ( 'Unable to read content of file ("' . $ source . '")' ) ; } $ file = $ this -> getItemDirectory ( ) -> getDirectory ( $ parent ) -> getFile ( $ fileName ) ; $ writeSuccess = $ file -> put ( $ resource ) ; fclose ( $ resource ) ; if ( ! $ writeSuccess ) { throw new \ common_Exception ( 'Unable to write file ("' . $ fileName . '")' ) ; } return $ this -> getInfoFromFile ( $ file ) ; }
Add content to file
49,943
public function sasEditInstance ( ) { $ this -> loadStandaloneMode ( ) ; $ clazz = $ this -> getCurrentClass ( ) ; $ instance = $ this -> getCurrentInstance ( ) ; $ formContainer = new tao_actions_form_Instance ( $ clazz , $ instance ) ; $ myForm = $ formContainer -> getForm ( ) ; if ( $ myForm -> isSubmited ( ) ) { if ( $ myForm -> isValid ( ) ) { $ binder = new tao_models_classes_dataBinding_GenerisFormDataBinder ( $ instance ) ; $ instance = $ binder -> bind ( $ myForm -> getValues ( ) ) ; $ instance = $ this -> getClassService ( ) -> setDefaultItemContent ( $ instance ) ; $ this -> setData ( 'message' , __ ( 'Item saved' ) ) ; } } $ this -> setData ( 'uri' , tao_helpers_Uri :: encode ( $ instance -> getUri ( ) ) ) ; $ this -> setData ( 'classUri' , tao_helpers_Uri :: encode ( $ clazz -> getUri ( ) ) ) ; $ this -> setData ( 'formTitle' , __ ( 'Edit item' ) ) ; $ this -> setData ( 'myForm' , $ myForm -> render ( ) ) ; $ this -> setView ( 'form.tpl' , 'tao' ) ; }
Edit an instances
49,944
public function viewItem ( ) { $ this -> loadStandaloneMode ( ) ; if ( ! $ this -> isXmlHttpRequest ( ) ) { throw new common_exception_BadRequest ( 'wrong request mode' ) ; } $ itemClass = $ this -> getCurrentClass ( ) ; $ item = $ this -> getCurrentInstance ( ) ; $ lang = null ; if ( $ this -> hasRequestParameter ( 'target_lang' ) ) { $ lang = $ this -> getRequestParameter ( 'target_lang' ) ; } $ hiddenProperties = array ( taoItems_models_classes_ItemsService :: PROPERTY_ITEM_CONTENT ) ; $ properties = array ( ) ; foreach ( $ this -> getClassService ( ) -> getClazzProperties ( $ itemClass ) as $ property ) { if ( in_array ( $ property -> getUri ( ) , $ hiddenProperties ) ) { continue ; } $ range = $ property -> getRange ( ) ; if ( is_null ( $ lang ) ) { $ propValues = $ item -> getPropertyValues ( $ property ) ; } else { $ propContainer = $ item -> getPropertyValuesByLg ( $ property , $ lang ) ; $ propValues = $ propContainer -> getIterator ( ) ; } foreach ( $ propValues as $ propValue ) { if ( $ range -> getUri ( ) == OntologyRdfs :: RDFS_LITERAL ) { $ value = ( string ) $ propValue ; } else { $ resource = new core_kernel_classes_Resource ( $ propValue ) ; $ value = $ resource -> getLabel ( ) ; } $ properties [ ] = array ( 'name' => $ property -> getLabel ( ) , 'value' => $ value ) ; } } $ previewData = $ this -> initPreview ( $ item , $ itemClass ) ; if ( count ( $ previewData ) == 0 ) { $ this -> setData ( 'preview' , false ) ; $ this -> setData ( 'previewMsg' , __ ( 'Not yet available' ) ) ; } else { $ this -> setData ( 'preview' , true ) ; $ this -> setData ( 'instanceUri' , tao_helpers_Uri :: encode ( $ item -> getUri ( ) , false ) ) ; foreach ( $ previewData as $ key => $ value ) { $ this -> setData ( $ key , $ value ) ; } } $ this -> setData ( 'uri' , tao_helpers_Uri :: encode ( $ item -> getUri ( ) ) ) ; $ this -> setData ( 'classUri' , tao_helpers_Uri :: encode ( $ itemClass -> getUri ( ) ) ) ; $ this -> setData ( 'label' , $ item -> getLabel ( ) ) ; $ this -> setData ( 'itemProperties' , $ properties ) ; $ this -> setView ( 'view.tpl' ) ; }
view and item
49,945
protected function deployItem ( core_kernel_classes_Resource $ item , $ languageCode , $ compiledDirectory ) { $ itemService = taoItems_models_classes_ItemsService :: singleton ( ) ; $ sourceDir = $ itemService -> getItemDirectory ( $ item , $ languageCode ) ; $ success = taoItems_helpers_Deployment :: copyResources ( $ sourceDir -> getPrefix ( ) , $ compiledDirectory , array ( 'index.html' ) ) ; if ( ! $ success ) { return $ this -> fail ( __ ( 'Unable to copy resources for language %s' , $ languageCode ) ) ; } $ xhtml = $ itemService -> render ( $ item , $ languageCode ) ; $ subReport = taoItems_helpers_Deployment :: retrieveExternalResources ( $ xhtml , $ compiledDirectory ) ; if ( $ subReport -> getType ( ) == common_report_Report :: TYPE_SUCCESS ) { $ xhtml = $ subReport -> getData ( ) ; file_put_contents ( $ compiledDirectory . 'index.html' , $ xhtml ) ; return new common_report_Report ( common_report_Report :: TYPE_SUCCESS , __ ( 'Published "%1$s" in language "%2$s"' , $ item -> getLabel ( ) , $ languageCode ) ) ; } else { return $ subReport ; } }
deploys the item into the given absolute directory
49,946
protected function createService ( core_kernel_classes_Resource $ item , tao_models_classes_service_StorageDirectory $ destinationDirectory ) { $ service = new tao_models_classes_service_ServiceCall ( new core_kernel_classes_Resource ( taoItems_models_classes_ItemsService :: INSTANCE_SERVICE_ITEM_RUNNER ) ) ; $ service -> addInParameter ( new tao_models_classes_service_ConstantParameter ( new core_kernel_classes_Resource ( taoItems_models_classes_ItemsService :: INSTANCE_FORMAL_PARAM_ITEM_PATH ) , $ destinationDirectory -> getId ( ) ) ) ; $ service -> addInParameter ( new tao_models_classes_service_ConstantParameter ( new core_kernel_classes_Resource ( taoItems_models_classes_ItemsService :: INSTANCE_FORMAL_PARAM_ITEM_URI ) , $ item ) ) ; return $ service ; }
Create the item s ServiceCall .
49,947
public function getItemClass ( $ uri = '' ) { $ returnValue = null ; if ( empty ( $ uri ) && ! is_null ( $ this -> itemClass ) ) { $ returnValue = $ this -> itemClass ; } else { $ clazz = $ this -> getClass ( $ uri ) ; if ( $ this -> isItemClass ( $ clazz ) ) { $ returnValue = $ clazz ; } } return $ returnValue ; }
get an item subclass by uri . If the uri is not set it returns the item class ( the top level class . If the uri don t reference an item subclass it returns null
49,948
public function isItemClass ( core_kernel_classes_Class $ clazz ) { $ returnValue = ( bool ) false ; if ( $ this -> itemClass -> getUri ( ) == $ clazz -> getUri ( ) ) { return true ; } foreach ( $ clazz -> getParentClasses ( true ) as $ parent ) { if ( $ parent -> getUri ( ) == $ this -> itemClass -> getUri ( ) ) { $ returnValue = true ; break ; } } return ( bool ) $ returnValue ; }
check if the class is a or a subclass of an Item
49,949
public function deleteResource ( core_kernel_classes_Resource $ resource ) { if ( LockManager :: getImplementation ( ) -> isLocked ( $ resource ) ) { $ userId = common_session_SessionManager :: getSession ( ) -> getUser ( ) -> getIdentifier ( ) ; LockManager :: getImplementation ( ) -> releaseLock ( $ resource , $ userId ) ; } $ result = $ this -> deleteItemContent ( $ resource ) && parent :: deleteResource ( $ resource ) ; if ( $ result ) { $ this -> getEventManager ( ) -> trigger ( new ItemRemovedEvent ( $ resource -> getUri ( ) ) ) ; } return $ result ; }
delete an item
49,950
public function hasItemContent ( core_kernel_classes_Resource $ item , $ lang = '' ) { if ( is_null ( $ item ) ) { return false ; } if ( empty ( $ lang ) ) { $ lang = $ this -> getSessionLg ( ) ; } $ itemContents = $ item -> getPropertyValuesByLg ( $ this -> itemContentProperty , $ lang ) ; return ! $ itemContents -> isEmpty ( ) ; }
Check if the item has an itemContent Property
49,951
public function hasItemModel ( core_kernel_classes_Resource $ item , $ models ) { $ returnValue = ( bool ) false ; $ itemModel = $ item -> getOnePropertyValue ( $ this -> itemModelProperty ) ; if ( $ itemModel instanceof core_kernel_classes_Resource ) { if ( in_array ( $ itemModel -> getUri ( ) , $ models ) ) { $ returnValue = true ; } } return ( bool ) $ returnValue ; }
Check if the Item has on of the itemModel property in the models array
49,952
public function isItemModelDefined ( core_kernel_classes_Resource $ item ) { $ returnValue = ( bool ) false ; if ( ! is_null ( $ item ) ) { $ model = $ item -> getOnePropertyValue ( $ this -> itemModelProperty ) ; if ( $ model instanceof core_kernel_classes_Literal ) { if ( strlen ( ( string ) $ model ) > 0 ) { $ returnValue = true ; } } else if ( ! is_null ( $ model ) ) { $ returnValue = true ; } } return ( bool ) $ returnValue ; }
Check if the itemModel has been defined for that item
49,953
public function getModelRuntime ( core_kernel_classes_Resource $ item ) { $ returnValue = null ; if ( ! is_null ( $ item ) ) { $ itemModel = $ item -> getOnePropertyValue ( $ this -> itemModelProperty ) ; if ( ! is_null ( $ itemModel ) ) { $ returnValue = $ itemModel -> getOnePropertyValue ( $ this -> getProperty ( taoItems_models_classes_itemModel :: CLASS_URI_RUNTIME ) ) ; } } return $ returnValue ; }
Get the runtime associated to the item model .
49,954
public function hasModelStatus ( core_kernel_classes_Resource $ item , $ status ) { $ returnValue = ( bool ) false ; if ( ! is_null ( $ item ) ) { if ( ! is_array ( $ status ) && is_string ( $ status ) ) { $ status = array ( $ status ) ; } try { $ itemModel = $ item -> getOnePropertyValue ( $ this -> itemModelProperty ) ; if ( $ itemModel instanceof core_kernel_classes_Resource ) { $ itemModelStatus = $ itemModel -> getUniquePropertyValue ( $ this -> getProperty ( ItemModelStatus :: CLASS_URI ) ) ; if ( in_array ( $ itemModelStatus -> getUri ( ) , $ status ) ) { $ returnValue = true ; } } } catch ( common_exception_EmptyProperty $ ce ) { $ returnValue = false ; } } return ( bool ) $ returnValue ; }
Short description of method hasModelStatus
49,955
protected function cloneItemContent ( core_kernel_classes_Resource $ source , core_kernel_classes_Resource $ destination , core_kernel_classes_Property $ property ) { $ serializer = $ this -> getFileReferenceSerializer ( ) ; $ this -> setItemModel ( $ destination , $ this -> getItemModel ( $ source ) ) ; foreach ( $ source -> getUsedLanguages ( $ this -> itemContentProperty ) as $ lang ) { $ sourceItemDirectory = $ this -> getItemDirectory ( $ source , $ lang ) ; $ destinationItemDirectory = $ this -> getItemDirectory ( $ destination , $ lang ) ; foreach ( $ source -> getPropertyValuesCollection ( $ property , array ( 'lg' => $ lang ) ) -> getIterator ( ) as $ propertyValue ) { $ id = $ propertyValue instanceof core_kernel_classes_Resource ? $ propertyValue -> getUri ( ) : ( string ) $ propertyValue ; $ sourceDirectory = $ serializer -> unserializeDirectory ( $ id ) ; $ iterator = $ sourceDirectory -> getFlyIterator ( Directory :: ITERATOR_FILE | Directory :: ITERATOR_RECURSIVE ) ; foreach ( $ iterator as $ iteratorFile ) { $ newFile = $ destinationItemDirectory -> getFile ( $ sourceItemDirectory -> getRelPath ( $ iteratorFile ) ) ; $ newFile -> write ( $ iteratorFile -> readStream ( ) ) ; } $ destinationDirectory = $ destinationItemDirectory -> getDirectory ( $ sourceItemDirectory -> getRelPath ( $ sourceDirectory ) ) ; $ serializer -> serialize ( $ destinationDirectory ) ; } } }
Clone item content
49,956
public function getItemModel ( core_kernel_classes_Resource $ item ) { $ returnValue = null ; $ itemModel = $ item -> getOnePropertyValue ( $ this -> itemModelProperty ) ; if ( $ itemModel instanceof core_kernel_classes_Resource ) { $ returnValue = $ itemModel ; } return $ returnValue ; }
Short description of method getItemModel
49,957
public function setItemModel ( core_kernel_classes_Resource $ item , core_kernel_classes_Resource $ model ) { return $ item -> editPropertyValues ( $ this -> getProperty ( self :: PROPERTY_ITEM_MODEL ) , $ model ) ; }
Set the model of an item
49,958
public function getSessionLg ( ) { $ sessionLang = \ common_session_SessionManager :: getSession ( ) -> getDataLanguage ( ) ; if ( empty ( $ sessionLang ) ) { throw new Exception ( 'the data language of the user cannot be found in session' ) ; } return ( string ) $ sessionLang ; }
Rertrieve current user s language from the session object to know where item content should be located
49,959
public function deleteItemContent ( core_kernel_classes_Resource $ item ) { $ definitonFileValues = $ item -> getPropertyValues ( $ this -> itemContentProperty ) ; if ( ! empty ( $ definitonFileValues ) ) { $ directory = $ this -> getFileReferenceSerializer ( ) -> unserializeDirectory ( reset ( $ definitonFileValues ) ) ; if ( $ directory -> exists ( ) ) { $ directory -> deleteSelf ( ) ; } } foreach ( $ item -> getUsedLanguages ( $ this -> itemContentProperty ) as $ lang ) { $ files = $ item -> getPropertyValuesByLg ( $ this -> itemContentProperty , $ lang ) ; foreach ( $ files -> getIterator ( ) as $ file ) { if ( $ file instanceof core_kernel_classes_Resource ) { $ this -> getFileReferenceSerializer ( ) -> cleanUp ( $ file -> getUri ( ) ) ; } } } return true ; }
Deletes the content but does not unreference it
49,960
public function getItemModelImplementation ( core_kernel_classes_Resource $ itemModel ) { $ serviceId = ( string ) $ itemModel -> getOnePropertyValue ( $ this -> getProperty ( self :: PROPERTY_ITEM_MODEL_SERVICE ) ) ; if ( empty ( $ serviceId ) ) { throw new common_exception_NoImplementation ( 'No implementation found for item model ' . $ itemModel -> getUri ( ) ) ; } try { $ itemModelService = $ this -> getServiceManager ( ) -> get ( $ serviceId ) ; } catch ( ServiceNotFoundException $ e ) { if ( ! class_exists ( $ serviceId ) ) { throw new common_exception_Error ( 'Item model service ' . $ serviceId . ' not found' ) ; } common_Logger :: w ( 'Outdated model definition "' . $ serviceId . '", please use test model service' ) ; $ itemModelService = new $ serviceId ( ) ; } if ( ! $ itemModelService instanceof \ taoItems_models_classes_itemModel ) { throw new common_exception_Error ( 'Item model service ' . get_class ( $ itemModelService ) . ' not compatible for item model ' . $ itemModelService -> getUri ( ) ) ; } return $ itemModelService ; }
Get the correct implementation for a specific item model
49,961
public function setDefaultFilesourceId ( $ filesourceId ) { $ ext = common_ext_ExtensionsManager :: singleton ( ) -> getExtensionById ( 'taoItems' ) ; $ ext -> setConfig ( self :: CONFIG_DEFAULT_FILESOURCE , $ filesourceId ) ; }
sets the filesource to use for new items
49,962
public function getItemDirectory ( core_kernel_classes_Resource $ item , $ language = '' ) { if ( $ language === '' ) { $ files = $ item -> getPropertyValues ( $ this -> itemContentProperty ) ; } else { $ files = $ item -> getPropertyValuesByLg ( $ this -> itemContentProperty , $ language ) -> toArray ( ) ; } if ( count ( $ files ) > 1 ) { common_Logger :: i ( print_r ( $ files , true ) ) ; throw new common_Exception ( __METHOD__ . ': Item ' . $ item -> getUri ( ) . ' has multiple.' ) ; } if ( count ( $ files ) == 1 ) { $ file = reset ( $ files ) ; $ file = is_object ( $ file ) && $ file instanceof core_kernel_classes_Resource ? $ file -> getUri ( ) : ( string ) $ file ; return $ this -> getFileReferenceSerializer ( ) -> unserializeDirectory ( $ file ) ; } $ model = $ this -> getItemModel ( $ item ) ; if ( is_null ( $ model ) ) { throw new common_Exception ( 'Call to ' . __FUNCTION__ . ' for item without model' ) ; } $ actualLang = empty ( $ language ) ? $ this -> getSessionLg ( ) : $ language ; $ filePath = tao_helpers_Uri :: getUniqueId ( $ item -> getUri ( ) ) . DIRECTORY_SEPARATOR . 'itemContent' . DIRECTORY_SEPARATOR . $ actualLang ; $ itemDirectory = $ this -> getDefaultItemDirectory ( ) -> getDirectory ( $ filePath ) ; $ serial = $ this -> getFileReferenceSerializer ( ) -> serialize ( $ itemDirectory ) ; $ item -> setPropertyValueByLg ( $ this -> itemContentProperty , $ serial , $ actualLang ) ; return $ itemDirectory ; }
Returns the items flysystem directory
49,963
public function getDefaultItemDirectory ( ) { $ filesystemId = common_ext_ExtensionsManager :: singleton ( ) -> getExtensionById ( 'taoItems' ) -> getConfig ( self :: CONFIG_DEFAULT_FILESOURCE ) ; return $ this -> getServiceManager ( ) -> get ( FileSystemService :: SERVICE_ID ) -> getDirectory ( $ filesystemId ) ; }
Returns the defaul item directory
49,964
public function getAllByModel ( $ itemModel ) { if ( ! empty ( $ itemModel ) ) { $ uri = ( $ itemModel instanceof core_kernel_classes_Resource ) ? $ itemModel -> getUri ( ) : $ itemModel ; return $ this -> itemClass -> searchInstances ( array ( $ this -> itemModelProperty -> getUri ( ) => $ uri ) , array ( 'recursive' => true ) ) ; } return array ( ) ; }
Get items of a specific model
49,965
public function setAssets ( $ type , $ assets , $ publicDirectory ) { if ( ! in_array ( $ type , self :: $ assetTypes ) ) { throw new InvalidArgumentException ( 'Unknow asset type "' . $ type . '", it should be either ' . implode ( ', ' , self :: $ assetTypes ) ) ; } if ( ! is_array ( $ assets ) ) { throw new InvalidArgumentException ( 'Assests should be an array, "' . gettype ( $ assets ) . '" given' ) ; } $ encoder = EncoderService :: singleton ( ) -> get ( $ this -> assetEncoders [ $ type ] , $ publicDirectory ) ; foreach ( $ assets as $ asset ) { if ( $ asset instanceof MediaAsset ) { $ mediaSource = $ asset -> getMediaSource ( ) ; if ( $ mediaSource instanceof MediaSource || $ mediaSource instanceof HttpSource ) { $ assetKey = $ asset -> getMediaIdentifier ( ) ; } else { $ assetKey = $ mediaSource -> getBaseName ( $ asset -> getMediaIdentifier ( ) ) ; } } else { $ assetKey = $ asset ; } $ this -> assets [ $ type ] [ $ assetKey ] = $ encoder -> encode ( $ asset ) ; } }
Set item s assets of a given type to the pack .
49,966
protected function getItemModel ( ) { try { return $ this -> getItem ( ) -> getUniquePropertyValue ( new core_kernel_classes_Property ( taoItems_models_classes_ItemsService :: PROPERTY_ITEM_MODEL ) ) ; } catch ( common_Exception $ e ) { return null ; } }
Obtains a reference on the Item Model related to the currently exported item instance .
49,967
public function getAssetContent ( $ assetPath ) { $ mediaAsset = $ this -> getItemMediaResolver ( ) -> resolve ( $ assetPath ) ; $ mediaSource = $ mediaAsset -> getMediaSource ( ) ; $ srcPath = $ mediaSource -> download ( $ mediaAsset -> getMediaIdentifier ( ) ) ; return file_get_contents ( $ srcPath ) ; }
Get the content of an asset .
49,968
public static function quickTransform ( $ xml , $ xsl , $ params = array ( ) ) { $ xml_dom = self :: getDOM ( $ xml ) ; $ xsl_dom = self :: prepareXsl ( $ xsl , $ params ) ; return self :: transform ( $ xml_dom , $ xsl_dom , $ params ) ; }
Transform the given xml with the given stylesheet adding params if necessary
49,969
public static function prepareXsl ( $ xsl , $ params = array ( ) ) { $ xsl_dom = self :: getDOM ( $ xsl ) ; return self :: addParams ( $ xsl_dom , $ params ) ; }
prepare the xsl stylesheet and add params dynamically
49,970
public static function getDOM ( $ str ) { $ dom = new DOMDocument ( ) ; is_file ( $ str ) ? $ dom -> load ( $ str ) : $ dom -> loadXML ( $ str ) ; return $ dom ; }
return the DOM corresponding to the parameter
49,971
private static function addParams ( $ dom , $ params ) { if ( ! sizeof ( $ params ) ) { return $ dom ; } $ xpath = new DOMXPath ( $ dom ) ; $ xpath -> registerNamespace ( self :: XSLT_SHORT_NS , self :: XSLT_NS ) ; $ items = $ xpath -> query ( '/' . self :: XSLT_SHORT_NS . ':stylesheet|' . self :: XSLT_SHORT_NS . ':transform/' . self :: XSLT_SHORT_NS . ':param' ) ; $ existing = array ( ) ; foreach ( $ items as $ param ) { $ existing [ ] = $ param -> getAttribute ( 'name' ) ; } foreach ( $ params as $ name => $ val ) { if ( ! in_array ( $ name , $ existing ) ) { $ node = $ dom -> createElementNS ( self :: XSLT_NS , self :: XSLT_SHORT_NS . ":param" ) ; $ node -> setAttribute ( 'name' , $ name ) ; common_Logger :: w ( 'Parameters "' . $ name . '"added automatically by the ' . get_class ( ) . ':addParams \'s function because it was missing in the xsl stylesheet' ) ; } } return $ dom ; }
insert the tag param for each params noexistent in xsl stylesheet
49,972
private function renderItem ( $ item ) { $ this -> response = $ this -> response -> withBody ( stream_for ( $ this -> getRenderedItem ( $ item ) ) ) ; }
Add the rendered item to psr7 response
49,973
public function getAdapters ( ) { $ registry = $ this -> getRegistry ( ) ; $ config = [ ] ; if ( $ registry -> isRegistered ( self :: REGISTRY_ENTRY_KEY ) ) { $ config = $ registry -> get ( self :: REGISTRY_ENTRY_KEY ) ; } if ( isset ( $ config [ self :: PREVIEWERS_KEY ] ) ) { return $ config [ self :: PREVIEWERS_KEY ] ; } return [ ] ; }
Gets the list of adapters
49,974
public function registerAdapter ( DynamicModule $ module ) { if ( ! is_null ( $ module ) && ! empty ( $ module -> getModule ( ) ) ) { $ registry = $ this -> getRegistry ( ) ; $ config = [ ] ; if ( $ registry -> isRegistered ( self :: REGISTRY_ENTRY_KEY ) ) { $ config = $ registry -> get ( self :: REGISTRY_ENTRY_KEY ) ; } $ config [ self :: PREVIEWERS_KEY ] [ $ module -> getModule ( ) ] = $ module -> toArray ( ) ; $ registry -> set ( self :: REGISTRY_ENTRY_KEY , $ config ) ; return true ; } return false ; }
Registers a previewer adapter
49,975
public function unregisterAdapter ( $ moduleId ) { $ registry = $ this -> getRegistry ( ) ; $ config = [ ] ; if ( $ registry -> isRegistered ( self :: REGISTRY_ENTRY_KEY ) ) { $ config = $ registry -> get ( self :: REGISTRY_ENTRY_KEY ) ; } if ( isset ( $ config [ self :: PREVIEWERS_KEY ] ) && isset ( $ config [ self :: PREVIEWERS_KEY ] [ $ moduleId ] ) ) { unset ( $ config [ self :: PREVIEWERS_KEY ] [ $ moduleId ] ) ; $ registry -> set ( self :: REGISTRY_ENTRY_KEY , $ config ) ; return true ; } return false ; }
Unregisters a previewer adapter
49,976
public function getStrings ( \ core_kernel_classes_Resource $ resource ) { $ tokenizer = $ this -> getItemContentTokenizer ( $ resource ) ; if ( is_null ( $ tokenizer ) ) { return [ ] ; } return $ tokenizer -> getStrings ( $ resource ) ; }
Find item model tokenizer and send request to it to extract tokens
49,977
public function registerPreviewExtraButtons ( $ name , $ toolConfig ) { $ newConfig = array ( 'extraButtons' => array ( ) ) ; $ newConfig [ 'extraButtons' ] [ $ name ] = $ toolConfig ; $ this -> register ( self :: AMD , $ newConfig ) ; }
Register an extra button for the preview in the client lib config registry
49,978
protected function getClassProperties ( ) { $ properties = parent :: getClassProperties ( ) ; unset ( $ properties [ taoItems_models_classes_ItemsService :: PROPERTY_ITEM_MODEL ] ) ; unset ( $ properties [ taoItems_models_classes_ItemsService :: PROPERTY_ITEM_CONTENT ] ) ; unset ( $ properties [ taoItems_models_classes_ItemsService :: PROPERTY_ITEM_CONTENT_SRC ] ) ; return $ properties ; }
Get editable properties
49,979
protected function registerExtensions ( array $ config ) { foreach ( $ config as $ entry ) { $ name = ArrayHelper :: getValue ( $ entry , 'name' , false ) ; $ options = ArrayHelper :: getValue ( $ entry , 'options' , '' ) ; $ depends = ArrayHelper :: getValue ( $ entry , 'depends' , [ ] ) ; if ( in_array ( $ name , $ this -> enabledExtensions ) ) { if ( ! $ this -> checkEnabledExtensions ( $ depends ) ) { throw new InvalidConfigException ( "Extension {$name} requires " . implode ( ', ' , $ depends ) . " extensions to be enabled." ) ; } $ options = Json :: encode ( $ options ) ; $ this -> view -> registerJs ( "{$this->id}_ias.extension(new {$name}({$options}));" , View :: POS_READY , "{$this->id}_ias_{$name}" ) ; } } }
Register jQuery IAS extensions .
49,980
protected function registerEventHandlers ( array $ config ) { foreach ( $ config as $ name => $ depends ) { $ eventName = 'eventOn' . ucfirst ( $ name ) ; if ( ! empty ( $ this -> $ eventName ) ) { if ( ! $ this -> checkEnabledExtensions ( $ depends ) ) { throw new InvalidConfigException ( "The \"{$name}\" event requires " . implode ( ', ' , $ depends ) . " extensions to be enabled." ) ; } $ this -> view -> registerJs ( "{$this->id}_ias.on('{$name}', {$this->$eventName});" , View :: POS_READY , "{$this->id}_ias_event_{$eventName}" ) ; } } }
Register jQuery IAS event handlers .
49,981
protected function checkEnabledExtensions ( $ extensions ) { $ extensions = ( array ) $ extensions ; if ( empty ( $ extensions ) ) { return true ; } else { return ( count ( array_intersect ( $ this -> enabledExtensions , $ extensions ) ) == count ( $ extensions ) ) ; } }
Check whether the given extensions are enabled .
49,982
public function add ( $ tracking ) { $ sessionTracks = [ ] ; if ( Session :: has ( $ this -> sessionIdentifier ) ) { $ sessionTracks = Session :: get ( $ this -> sessionIdentifier ) ; } $ trackingKey = md5 ( $ tracking ) ; $ sessionTracks [ $ trackingKey ] = $ tracking ; Session :: flash ( $ this -> sessionIdentifier , $ sessionTracks ) ; }
adds a tracking
49,983
public function get ( ) { $ trackings = [ ] ; if ( Session :: has ( $ this -> sessionIdentifier ) ) { $ trackings = Session :: get ( $ this -> sessionIdentifier ) ; Session :: forget ( $ this -> sessionIdentifier ) ; } return $ trackings ; }
returns all trackings
49,984
public function trackPage ( $ page = null , $ title = null , $ hittype = null ) { $ allowedHitTypes = [ 'pageview' , 'appview' , 'event' , 'transaction' , 'item' , 'social' , 'exception' , 'timing' ] ; if ( $ hittype === null ) { $ hittype = $ allowedHitTypes [ 0 ] ; } if ( ! in_array ( $ hittype , $ allowedHitTypes ) ) { return ; } $ trackingCode = "ga('send', 'pageview');" ; if ( $ page !== null || $ title !== null || $ hittype !== null ) { $ page = ( $ page === null ) ? "window.location.protocol + '//' + window.location.hostname + window.location.pathname + window.location.search" : "'{$page}'" ; $ title = ( $ title === null ) ? "document.title" : "'{$title}'" ; $ trackingCode = "ga('send', {'hitType': '{$hittype}', 'page': {$page}, 'title': {$title}});" ; } $ this -> trackingBag -> add ( $ trackingCode ) ; }
track an page view
49,985
public function trackEvent ( $ category , $ action , $ label = null , $ value = null ) { $ command = '' ; if ( $ label !== null ) { $ command .= ", '{$label}'" ; if ( $ value !== null && is_numeric ( $ value ) ) { $ command .= ", {$value}" ; } } $ trackingCode = "ga('send', 'event', '{$category}', '{$action}'$command);" ; $ this -> trackingBag -> add ( $ trackingCode ) ; }
track an event
49,986
public function render ( ) { $ script [ ] = $ this -> _getJavascriptTemplateBlockBegin ( ) ; $ trackingUserId = ( null === $ this -> userId ) ? '' : sprintf ( ", {'userId': '%s'}" , $ this -> userId ) ; if ( $ this -> debug ) { $ script [ ] = "ga('create', '{$this->trackingId}', { 'cookieDomain': 'none' }, '{$this->trackerName}'{$trackingUserId});" ; } else { $ script [ ] = "ga('create', '{$this->trackingId}', '{$this->trackingDomain}', '{$this->trackerName}'{$trackingUserId});" ; } if ( $ this -> ecommerceTracking ) { $ script [ ] = "ga('require', 'ecommerce');" ; } if ( $ this -> displayFeatures ) { $ script [ ] = "ga('require', 'displayfeatures');" ; } if ( $ this -> anonymizeIp ) { $ script [ ] = "ga('set', 'anonymizeIp', true);" ; } if ( $ this -> nonInteraction ) { $ script [ ] = "ga('set', 'nonInteraction', true);" ; } if ( $ this -> campaign instanceof Campaign ) { $ script [ ] = ( new CampaignRenderer ( $ this -> campaign ) ) -> render ( ) ; } $ trackingStack = $ this -> trackingBag -> get ( ) ; if ( count ( $ trackingStack ) ) { $ script [ ] = implode ( "\n" , $ trackingStack ) ; } if ( $ this -> autoTrack ) { $ script [ ] = "ga('send', 'pageview');" ; } if ( $ this -> ecommerceTracking ) { $ script [ ] = "ga('ecommerce:send');" ; } $ script [ ] = $ this -> _getJavascriptTemplateBlockEnd ( ) ; return implode ( '' , $ script ) ; }
returns the javascript embedding code
49,987
public function nonInteraction ( $ value = null ) { if ( null === $ value ) { return $ this -> nonInteraction ; } $ this -> nonInteraction = ( $ value === true ) ; return $ this ; }
sets or gets nonInteraction
49,988
public function setCustom ( $ dimension , $ value = null ) { if ( $ value === null && is_array ( $ dimension ) ) { $ params = json_encode ( $ dimension ) ; $ trackingCode = "ga('set', $params);" ; } else { $ trackingCode = "ga('set', '$dimension', '$value');" ; } $ this -> trackCustom ( $ trackingCode ) ; return $ this ; }
sets custom dimensions
49,989
protected function _getJavascriptTemplateBlockBegin ( ) { $ appendix = $ this -> debug ? '_debug' : '' ; $ scriptTag = ( $ this -> cspNonce === null ) ? '<script>' : '<script nonce="' . $ this -> cspNonce . '">' ; return ( $ this -> renderScriptBlock ) ? $ scriptTag . "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics{$appendix}.js','ga');" : '' ; }
returns start block
49,990
public function makeInstance ( ) { $ class = $ this -> getVersionedRedisSentinelManagerClass ( ) ; $ config = $ this -> config -> get ( 'database.redis-sentinel' , [ ] ) ; $ driver = Arr :: pull ( $ config , 'client' , 'predis' ) ; if ( $ this -> appVersionLessThan ( '5.7' ) ) { return new RedisSentinelManager ( new $ class ( $ driver , $ config ) ) ; } return new RedisSentinelManager ( new $ class ( $ this -> app , $ driver , $ config ) ) ; }
Create an instance of the package s core Redis Sentinel service .
49,991
protected function getVersionedRedisSentinelManagerClass ( ) { if ( $ this -> config -> isLumen ) { $ frameworkVersion = '5.4' ; } else { $ frameworkVersion = '5.4.20' ; } if ( $ this -> appVersionLessThan ( $ frameworkVersion ) ) { return Laravel540RedisSentinelManager :: class ; } return Laravel5420RedisSentinelManager :: class ; }
Get the fully - qualified class name of the RedisSentinelManager class for the current version of Laravel or Lumen .
49,992
protected function resolveConnection ( $ name = null ) { $ name = $ name ? : 'default' ; $ options = Arr :: get ( $ this -> config , 'options' , [ ] ) ; if ( isset ( $ this -> config [ $ name ] ) ) { return $ this -> connector ( ) -> connect ( $ this -> config [ $ name ] , $ options ) ; } if ( isset ( $ this -> config [ 'clusters' ] [ 'name' ] ) ) { throw new InvalidArgumentException ( 'Redis Sentinel connections do not support Redis Cluster.' ) ; } throw new InvalidArgumentException ( 'The Redis Sentinel connection [' . $ name . '] is not defined.' ) ; }
Get the Redis Connection instance represented by the specified name
49,993
public function register ( ) { if ( ! $ this -> config -> shouldIntegrateHorizon ) { return ; } $ this -> config -> loadHorizonConfiguration ( ) ; $ this -> registerServices ( ) ; if ( $ this -> shouldRebindHorizonRedisFactory ( ) ) { $ this -> rebindHorizonRedisFactory ( ) ; } }
Configure the package s services for use with Laravel Horizon .
49,994
protected function rebindHorizonRedisFactory ( ) { foreach ( ( new HorizonServiceBindings ( ) ) as $ serviceClass ) { $ this -> app -> when ( $ serviceClass ) -> needs ( RedisFactory :: class ) -> give ( function ( ) { return $ this -> app -> make ( 'redis-sentinel.manager' ) ; } ) ; } }
Add contextual bindings for Horizon s services that inject the package s Redis Sentinel manager .
49,995
protected function addHorizonSentinelQueueConnector ( ) { $ this -> app -> make ( 'queue' ) -> extend ( 'redis-sentinel' , function ( ) { $ redis = $ this -> app -> make ( 'redis-sentinel.manager' ) ; return new HorizonRedisConnector ( $ redis ) ; } ) ; }
Add redis - sentinel as an available queue connection driver option to the Laravel queue manager using Horizon s modified Redis connector .
49,996
public function boot ( ) { $ this -> bootComponentDrivers ( ) ; if ( $ this -> config -> shouldOverrideLaravelRedisApi ) { $ this -> removeDeferredRedisServices ( ) ; } if ( $ this -> config -> shouldIntegrateHorizon ) { $ horizon = new HorizonServiceProvider ( $ this -> app , $ this -> config ) ; $ horizon -> register ( ) ; $ horizon -> boot ( ) ; } }
Boot the service by registering extensions with Laravel s cache queue and session managers for the redis - sentinel driver .
49,997
public function register ( ) { $ this -> config = ConfigurationLoader :: load ( $ this -> app ) ; $ this -> registerServices ( ) ; if ( $ this -> config -> shouldOverrideLaravelRedisApi ) { $ this -> registerOverrides ( ) ; } }
Bind the redis - sentinel database driver to the application service container .
49,998
protected function registerServices ( ) { $ this -> app -> singleton ( 'redis-sentinel' , function ( ) { return VersionedManagerFactory :: make ( $ this -> app , $ this -> config ) ; } ) ; $ this -> app -> singleton ( 'redis-sentinel.manager' , function ( $ app ) { return $ app -> make ( 'redis-sentinel' ) -> getVersionedManager ( ) ; } ) ; $ this -> app -> alias ( 'redis-sentinel' , Factory :: class ) ; }
Register the core Redis Sentinel connection manager .
49,999
protected function registerOverrides ( ) { $ this -> app -> singleton ( 'redis' , function ( $ app ) { return $ app -> make ( 'redis-sentinel' ) ; } ) ; $ this -> app -> bind ( 'redis.connection' , function ( $ app ) { return $ app -> make ( 'redis-sentinel.manager' ) -> connection ( ) ; } ) ; }
Replace the standard Laravel Redis service with the Redis Sentinel database driver so all Redis operations use Sentinel connections .