idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
57,000
public function dispatch ( DomainEvents $ events ) : void { $ events -> each ( function ( DomainEvent $ event ) { $ this -> listeners -> each ( function ( Listener $ listener ) use ( $ event ) { $ listener -> handle ( $ event ) ; } ) ; } ) ; }
dispatch domain events to listeners
57,001
public function initialize ( $ request ) { $ this -> _inputStream = new Zend_Amf_Parse_InputStream ( $ request ) ; $ this -> _deserializer = new Zend_Amf_Parse_Amf0_Deserializer ( $ this -> _inputStream ) ; $ this -> readMessage ( $ this -> _inputStream ) ; return $ this ; }
Prepare the AMF InputStream for parsing .
57,002
public function readMessage ( Zend_Amf_Parse_InputStream $ stream ) { $ clientVersion = $ stream -> readUnsignedShort ( ) ; if ( ( $ clientVersion != Zend_Amf_Constants :: AMF0_OBJECT_ENCODING ) && ( $ clientVersion != Zend_Amf_Constants :: AMF3_OBJECT_ENCODING ) && ( $ clientVersion != Zend_Amf_Constants :: FMS_OBJECT_ENCODING ) ) { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( 'Unknown Player Version ' . $ clientVersion ) ; } $ this -> _bodies = array ( ) ; $ this -> _headers = array ( ) ; $ headerCount = $ stream -> readInt ( ) ; while ( $ headerCount -- ) { $ this -> _headers [ ] = $ this -> readHeader ( ) ; } $ bodyCount = $ stream -> readInt ( ) ; while ( $ bodyCount -- ) { $ this -> _bodies [ ] = $ this -> readBody ( ) ; } return $ this ; }
Takes the raw AMF input stream and converts it into valid PHP objects
57,003
public function readHeader ( ) { $ name = $ this -> _inputStream -> readUTF ( ) ; $ mustRead = ( bool ) $ this -> _inputStream -> readByte ( ) ; $ length = $ this -> _inputStream -> readLong ( ) ; try { $ data = $ this -> _deserializer -> readTypeMarker ( ) ; } catch ( Exception $ e ) { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( 'Unable to parse ' . $ name . ' header data: ' . $ e -> getMessage ( ) . ' ' . $ e -> getLine ( ) , 0 , $ e ) ; } $ header = new Zend_Amf_Value_MessageHeader ( $ name , $ mustRead , $ data , $ length ) ; return $ header ; }
Deserialize a message header from the input stream .
57,004
public function readBody ( ) { $ targetURI = $ this -> _inputStream -> readUTF ( ) ; $ responseURI = $ this -> _inputStream -> readUTF ( ) ; $ length = $ this -> _inputStream -> readLong ( ) ; try { $ data = $ this -> _deserializer -> readTypeMarker ( ) ; } catch ( Exception $ e ) { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( 'Unable to parse ' . $ targetURI . ' body data ' . $ e -> getMessage ( ) , 0 , $ e ) ; } if ( $ this -> _deserializer -> getObjectEncoding ( ) == Zend_Amf_Constants :: AMF3_OBJECT_ENCODING ) { if ( is_array ( $ data ) && $ data [ 0 ] instanceof Zend_Amf_Value_Messaging_AbstractMessage ) { $ data = $ data [ 0 ] ; } $ this -> _objectEncoding = Zend_Amf_Constants :: AMF3_OBJECT_ENCODING ; } $ body = new Zend_Amf_Value_MessageBody ( $ targetURI , $ responseURI , $ data ) ; return $ body ; }
Deserialize a message body from the input stream
57,005
public function onAuthenticationSuccess ( Request $ request , TokenInterface $ token , $ providerKey ) { $ targetPath = $ request -> getSession ( ) -> get ( '_security.' . $ providerKey . '.target_path' ) ; if ( ! $ targetPath ) { $ targetPath = $ this -> getDefaultSuccessRedirectUrl ( ) ; } return new RedirectResponse ( $ targetPath ) ; }
Override to change what happens after successful authentication
57,006
protected function addRelation ( ) { if ( $ this -> relationType == 'hasAndBelongsToMany' ) { $ junction = $ this -> getJunction ( ) ; try { Validate :: table ( $ junction ) -> exists ( ) ; } catch ( dbException $ e ) { Database :: create ( $ junction , [ $ this -> tables [ 'local' ] . '_id' => 'integer' , $ this -> tables [ 'foreign' ] . '_id' => 'integer' , ] ) ; $ this -> insertRelationData ( $ junction , $ this -> tables [ 'local' ] , 'hasMany' , [ 'local' => $ this -> tables [ 'local' ] . '_id' , 'foreign' => $ this -> keys [ 'local' ] ] ) ; $ this -> insertRelationData ( $ junction , $ this -> tables [ 'foreign' ] , 'hasMany' , [ 'local' => $ this -> tables [ 'foreign' ] . '_id' , 'foreign' => $ this -> keys [ 'foreign' ] ] ) ; } } $ this -> insertRelationData ( $ this -> tables [ 'local' ] , $ this -> tables [ 'foreign' ] , $ this -> relationType , $ this -> keys ) ; }
Add data to configs and create all necessary files
57,007
protected function join ( $ row ) { $ keys [ 'local' ] = $ this -> keys [ 'local' ] ; $ keys [ 'foreign' ] = $ this -> keys [ 'foreign' ] ; if ( $ this -> relationType == 'hasAndBelongsToMany' ) { $ join = Database :: table ( $ this -> getJunction ( ) ) -> groupBy ( $ this -> tables [ 'local' ] . '_id' ) -> where ( $ this -> tables [ 'local' ] . '_id' , '=' , $ row -> { $ keys [ 'local' ] } ) -> findAll ( ) -> asArray ( null , $ this -> tables [ 'foreign' ] . '_id' ) ; if ( empty ( $ join ) ) return [ ] ; return Database :: table ( $ this -> tables [ 'foreign' ] ) -> where ( $ keys [ 'foreign' ] , 'IN' , $ join [ $ row -> { $ keys [ 'local' ] } ] ) ; } return Database :: table ( $ this -> tables [ 'foreign' ] ) -> where ( $ keys [ 'foreign' ] , '=' , $ row -> { $ keys [ 'local' ] } ) ; }
Process query with joined data
57,008
function Text_Diff3 ( $ orig , $ final1 , $ final2 ) { if ( extension_loaded ( 'xdiff' ) ) { $ engine = new Text_Diff_Engine_xdiff ( ) ; } else { $ engine = new Text_Diff_Engine_native ( ) ; } $ this -> _edits = $ this -> _diff3 ( $ engine -> diff ( $ orig , $ final1 ) , $ engine -> diff ( $ orig , $ final2 ) ) ; }
Computes diff between 3 sequences of strings .
57,009
public function serialize ( $ value ) { if ( $ value instanceof SerializablePersonalDataValue ) { return $ this -> serializePersonalDataValue ( $ value ) ; } elseif ( $ value instanceof SerializableValue ) { return $ this -> serializeValue ( $ value ) ; } return $ value ; }
serialize a value object into its string - based persistence form
57,010
private function serializePersonalDataValue ( SerializablePersonalDataValue $ value ) : array { $ dataKey = PersonalDataKey :: generate ( ) ; $ dataString = json_encode ( $ value -> serialize ( ) ) ; $ this -> dataStore -> storeData ( $ value -> personalKey ( ) , $ dataKey , PersonalData :: fromString ( $ dataString ) ) ; return [ 'personalKey' => $ value -> personalKey ( ) -> serialize ( ) , 'dataKey' => $ dataKey -> serialize ( ) , ] ; }
serialize a value that contains personal data
57,011
public function deserializePersonalValue ( string $ type , string $ json ) : SerializablePersonalDataValue { $ values = json_decode ( $ json ) ; $ personalKey = PersonalKey :: deserialize ( $ values -> personalKey ) ; $ dataKey = PersonalDataKey :: deserialize ( $ values -> dataKey ) ; return $ type :: deserialize ( $ this -> dataStore -> retrieveData ( $ personalKey , $ dataKey ) -> toString ( ) ) ; }
deserialize a value that contains personal data
57,012
public function addParameter ( $ parameter ) { if ( $ parameter instanceof Zend_Server_Method_Parameter ) { $ this -> _parameters [ ] = $ parameter ; if ( null !== ( $ name = $ parameter -> getName ( ) ) ) { $ this -> _parameterNameMap [ $ name ] = count ( $ this -> _parameters ) - 1 ; } } else { require_once 'Zend/Server/Method/Parameter.php' ; $ parameter = new Zend_Server_Method_Parameter ( array ( 'type' => ( string ) $ parameter , ) ) ; $ this -> _parameters [ ] = $ parameter ; } return $ this ; }
Add a parameter
57,013
public function getParameters ( ) { $ types = array ( ) ; foreach ( $ this -> _parameters as $ parameter ) { $ types [ ] = $ parameter -> getType ( ) ; } return $ types ; }
Retrieve parameters as list of types
57,014
public function getParameter ( $ index ) { if ( ! is_string ( $ index ) && ! is_numeric ( $ index ) ) { return null ; } if ( array_key_exists ( $ index , $ this -> _parameterNameMap ) ) { $ index = $ this -> _parameterNameMap [ $ index ] ; } if ( array_key_exists ( $ index , $ this -> _parameters ) ) { return $ this -> _parameters [ $ index ] ; } return null ; }
Retrieve a single parameter by name or index
57,015
public static function create ( $ name , $ type , $ extension , $ vendor ) { $ componentLabel = $ componentName = array_pop ( $ name ) ; if ( substr ( $ componentName , - 9 ) !== 'Component' ) { $ componentName .= 'Component' ; } $ componentPath = implode ( DIRECTORY_SEPARATOR , $ name ) ; $ componentAbsPath = GeneralUtility :: getFileAbsFileName ( 'EXT:' . $ extension . DIRECTORY_SEPARATOR . 'Components' . DIRECTORY_SEPARATOR . implode ( DIRECTORY_SEPARATOR , $ name ) ) ; if ( ! is_dir ( $ componentAbsPath ) && ! mkdir ( $ componentAbsPath , 06775 , true ) ) { throw new CommandException ( 'Could not create component directory' , 1507997978 ) ; } $ componentNamespace = rtrim ( $ vendor . '\\' . GeneralUtility :: underscoredToUpperCamelCase ( $ extension ) . '\\Component\\' . implode ( '\\' , $ name ) , '\\' ) ; $ substitute = [ '###extension###' => $ extension , '###namespace###' => $ componentNamespace , '###label###' => $ componentLabel , '###tspath###' => strtolower ( implode ( '.' , array_merge ( $ name , [ $ componentLabel ] ) ) ) , '###path###' => $ componentPath , ] ; $ skeletonTemplate = GeneralUtility :: getFileAbsFileName ( 'EXT:tw_componentlibrary/Resources/Private/Skeleton/' . ucfirst ( $ type ) . '.php' ) ; $ skeletonString = strtr ( file_get_contents ( $ skeletonTemplate ) , $ substitute ) ; $ skeletonFile = $ componentAbsPath . DIRECTORY_SEPARATOR . $ componentName . '.php' ; file_put_contents ( $ skeletonFile , $ skeletonString ) ; chmod ( $ skeletonFile , 0664 ) ; }
Kickstart a new component
57,016
public function handleUploadedFiles ( UploadedFile $ file , $ extension , $ dir ) { $ original_file = $ file -> getClientOriginalName ( ) ; $ path_parts = pathinfo ( $ original_file ) ; $ increment = '' ; while ( file_exists ( $ dir . FileManager :: DS . $ path_parts [ 'filename' ] . $ increment . '.' . $ extension ) ) { $ increment ++ ; } $ basename = $ path_parts [ 'filename' ] . $ increment . '.' . $ extension ; $ file -> move ( $ dir , $ basename ) ; }
Upload the files
57,017
public function makeDir ( $ dir_path ) { $ fm = new Filesystem ( ) ; if ( ! file_exists ( $ dir_path ) ) { $ fm -> mkdir ( $ dir_path , 0755 ) ; } else { $ this -> getFileManager ( ) -> throwError ( "Cannot create directory '" . $ dir_path . "': Directory already exists" , 500 ) ; } }
Create new directory
57,018
public function renameFile ( FileInfo $ fileInfo , $ new_file_name ) { try { $ this -> validateFile ( $ fileInfo , $ new_file_name ) ; $ fm = new Filesystem ( ) ; $ old_file = $ fileInfo -> getFilepath ( true ) ; $ new_file = $ new_file_name ; $ fm -> rename ( $ old_file , $ new_file ) ; } catch ( \ Exception $ e ) { $ this -> getFileManager ( ) -> throwError ( "Cannot rename file or directory" , 500 , $ e ) ; } }
Renames the file
57,019
public function validateFile ( FileInfo $ fileInfo , $ new_filename = null ) { $ file_path = $ fileInfo -> getFilePath ( true ) ; if ( ! is_dir ( $ file_path ) ) { $ fm = new Filesystem ( ) ; $ tmp_dir = $ this -> createTmpDir ( $ fm ) ; $ fm -> copy ( $ file_path , $ tmp_dir . FileManager :: DS . $ fileInfo -> getFilename ( ) ) ; if ( ! is_null ( $ new_filename ) ) { $ new_filename = basename ( $ new_filename ) ; $ fm -> rename ( $ tmp_dir . FileManager :: DS . $ fileInfo -> getFilename ( ) , $ tmp_dir . FileManager :: DS . $ new_filename ) ; } $ this -> checkFileType ( $ fm , $ tmp_dir ) ; } }
Validate the files to check if they have a valid file type
57,020
public function createTmpDir ( Filesystem $ fm ) { $ tmp_dir = $ this -> getFileManager ( ) -> getUploadPath ( ) . FileManager :: DS . "." . strtotime ( "now" ) ; $ fm -> mkdir ( $ tmp_dir ) ; return $ tmp_dir ; }
Create a temporary directory
57,021
public function checkFileType ( Filesystem $ fm , $ tmp_dir ) { $ di = new \ RecursiveDirectoryIterator ( $ tmp_dir ) ; foreach ( new \ RecursiveIteratorIterator ( $ di ) as $ filepath => $ file ) { $ fileInfo = new FileInfo ( $ filepath , $ this -> getFileManager ( ) ) ; $ mime_valid = $ this -> checkMimeType ( $ fileInfo ) ; if ( $ mime_valid !== true ) { $ fm -> remove ( $ tmp_dir ) ; $ this -> getFileManager ( ) -> throwError ( $ mime_valid , 500 ) ; } } $ fm -> remove ( $ tmp_dir ) ; }
Check if the file type is an valid file type by extracting the zip inside a temporary directory
57,022
public function checkMimeType ( $ fileInfo ) { $ mime = $ fileInfo -> getMimetype ( ) ; if ( $ mime != 'directory' && ! in_array ( $ mime , $ this -> getFileManager ( ) -> getExtensionsAllowed ( ) ) ) { return 'Mime type "' . $ mime . '" not allowed for file "' . $ fileInfo -> getFilename ( ) . '"' ; } return true ; }
Check the mimetype
57,023
public function extractZipTo ( $ filepath , $ destination ) { $ chapterZip = new \ ZipArchive ( ) ; if ( $ chapterZip -> open ( $ filepath ) ) { $ chapterZip -> extractTo ( $ destination ) ; $ chapterZip -> close ( ) ; } }
Extract the zip to the given location
57,024
function Text_Diff_Mapped ( $ from_lines , $ to_lines , $ mapped_from_lines , $ mapped_to_lines ) { assert ( count ( $ from_lines ) == count ( $ mapped_from_lines ) ) ; assert ( count ( $ to_lines ) == count ( $ mapped_to_lines ) ) ; parent :: Text_Diff ( $ mapped_from_lines , $ mapped_to_lines ) ; $ xi = $ yi = 0 ; for ( $ i = 0 ; $ i < count ( $ this -> _edits ) ; $ i ++ ) { $ orig = & $ this -> _edits [ $ i ] -> orig ; if ( is_array ( $ orig ) ) { $ orig = array_slice ( $ from_lines , $ xi , count ( $ orig ) ) ; $ xi += count ( $ orig ) ; } $ final = & $ this -> _edits [ $ i ] -> final ; if ( is_array ( $ final ) ) { $ final = array_slice ( $ to_lines , $ yi , count ( $ final ) ) ; $ yi += count ( $ final ) ; } } }
Computes a diff between sequences of strings .
57,025
public function import_from_client ( ) { if ( ! Permission :: check ( 'ADMIN' ) ) { Security :: permissionFailure ( $ this ) ; return ; } $ form = $ this -> ImportFromClientForm ( ) ; if ( Session :: get ( 'reloadOnImportDialogClose' ) ) { Requirements :: javascript ( CB_DIR . '/javascript/CodeBank.ImportDialog.js' ) ; Session :: clear ( 'reloadOnImportDialogClose' ) ; } return $ this -> customise ( array ( 'Content' => ' ' , 'Form' => $ form ) ) -> renderWith ( 'CMSDialog' ) ; }
Handles requests for the import from client popup
57,026
public function ImportFromClientForm ( ) { if ( ! Permission :: check ( 'ADMIN' ) ) { Security :: permissionFailure ( $ this ) ; return ; } $ uploadField = new FileField ( 'ImportFile' , _t ( 'CodeBank.EXPORT_FILE' , '_Client Export File' ) ) ; $ uploadField -> getValidator ( ) -> setAllowedExtensions ( array ( 'cbexport' ) ) ; File :: config ( ) -> allowed_extensions = array ( 'cbexport' ) ; $ fields = new FieldList ( new LiteralField ( 'ImportWarning' , '<p class="message warning">' . _t ( 'CodeBank.IMPORT_DATA_WARNING' , '_Warning clicking import will erase all snippets in the database, it is recommended you backup your database before proceeding' ) . '</p>' ) , new TabSet ( 'Root' , new Tab ( 'Main' , $ uploadField , new CheckboxField ( 'AppendData' , _t ( 'CodeBank.APPEND_IMPORT' , '_Import and Append Data (keep your existing data however appending may cause duplicates)' ) ) ) ) ) ; $ actions = new FieldList ( FormAction :: create ( 'doImportData' , _t ( 'CodeBank.IMPORT' , '_Import' ) ) -> addExtraClass ( 'ss-ui-button ss-ui-action-constructive' ) -> setAttribute ( 'data-icon' , 'accept' ) -> setUseButtonTag ( true ) ) ; $ validator = new RequiredFields ( 'ImportFile' ) ; $ form = new Form ( $ this , 'ImportFromClientForm' , $ fields , $ actions , $ validator ) ; $ form -> addExtraClass ( 'member-profile-form' ) ; return $ form ; }
Form used for importing data from the client
57,027
protected function raise ( DomainEvent $ event ) : void { $ this -> apply ( $ event ) ; $ this -> streamEvents = $ this -> streamEvents -> add ( new StreamEvent ( $ this -> aggregateId ( ) , $ this -> aggregateVersion ( ) , $ event ) ) ; }
raise an event from within the aggregate . this applies the event to the aggregate state and stores it in the pending stream events collection awaiting flush .
57,028
public function flushEvents ( ) : StreamEvents { $ events = $ this -> streamEvents -> copy ( ) ; $ this -> streamEvents = StreamEvents :: make ( ) ; return $ events ; }
returns and clears the internal pending stream events . this DOES violate CQS however it s important not to retrieve or store these events multiple times . pass these directly into the event store .
57,029
public static function buildFrom ( StreamEvents $ events ) : Aggregate { $ aggregate = new static ; $ events -> each ( function ( StreamEvent $ event ) use ( $ aggregate ) { $ aggregate -> apply ( $ event -> event ( ) ) ; if ( ! $ event -> version ( ) -> equals ( $ aggregate -> aggregateVersion ( ) ) ) { throw new UnexpectedAggregateVersionWhenBuildingFromEvents ( "When building from stream events aggregate {$aggregate->aggregateId()->toString()} expected version {$event->version()->toInt()} but got {$aggregate->aggregateVersion()->toInt()}." ) ; } } ) ; return $ aggregate ; }
reconstruct the aggregate state from domain events
57,030
protected function apply ( DomainEvent $ event ) : void { $ eventName = explode ( '\\' , get_class ( $ event ) ) ; $ method = 'apply' . $ eventName [ count ( $ eventName ) - 1 ] ; if ( method_exists ( $ this , $ method ) ) { $ this -> $ method ( $ event ) ; } $ this -> version = $ this -> version -> next ( ) ; }
apply domain events to aggregate state by mapping the class name to method name using strings
57,031
public function send ( $ url , $ method , $ body , $ headers = [ ] , $ options = [ ] ) { $ request = new Request ( $ method , $ url , $ headers , $ body ) ; try { $ rawResponse = $ this -> client -> send ( $ request , $ options ) ; } catch ( RequestException $ e ) { $ rawResponse = $ e -> getResponse ( ) ; if ( $ e -> getCode ( ) === 409 ) { $ body = $ this -> getResponseBody ( $ rawResponse ) ; $ rawHeaders = $ rawResponse -> getHeaders ( ) ; $ httpStatusCode = $ rawResponse -> getStatusCode ( ) ; return new BoxRawResponse ( $ rawHeaders , $ body , $ httpStatusCode ) ; } if ( $ e -> getPrevious ( ) instanceof RingException || ! $ rawResponse instanceof ResponseInterface ) { throw new Exceptions \ BoxClientException ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } } if ( $ rawResponse -> getStatusCode ( ) >= 400 ) { throw new Exceptions \ BoxClientException ( $ rawResponse -> getBody ( ) ) ; } $ body = $ this -> getResponseBody ( $ rawResponse ) ; $ rawHeaders = $ rawResponse -> getHeaders ( ) ; $ httpStatusCode = $ rawResponse -> getStatusCode ( ) ; return new BoxRawResponse ( $ rawHeaders , $ body , $ httpStatusCode ) ; }
Send request to the server and fetch the raw response
57,032
public function isSnippetLanguageIncluded ( $ obj ) { if ( $ obj instanceof SnippetLanguage ) { if ( $ this -> _cache_language_ids === null ) { $ this -> populateLanguageIDs ( ) ; } return ( isset ( $ this -> _cache_language_ids [ $ obj -> ID ] ) && $ this -> _cache_language_ids [ $ obj -> ID ] ) ; } else if ( $ obj instanceof Snippet ) { if ( $ this -> _cache_snippet_ids === null ) { $ this -> populateSnippetIDs ( ) ; } return ( isset ( $ this -> _cache_snippet_ids [ $ obj -> ID ] ) && $ this -> _cache_snippet_ids [ $ obj -> ID ] ) ; } else if ( $ obj instanceof SnippetFolder ) { if ( $ this -> _cache_folder_ids === null ) { $ this -> populateFolderIDs ( ) ; } return ( isset ( $ this -> _cache_folder_ids [ $ obj -> ID ] ) && $ this -> _cache_folder_ids [ $ obj -> ID ] ) ; } return false ; }
Returns TRUE if the given snippet or language should be included in the tree .
57,033
protected function LinkWithSearch ( $ link ) { $ params = array ( 'q' => ( array ) $ this -> request -> getVar ( 'q' ) , 'tag' => $ this -> request -> getVar ( 'tag' ) , 'creator' => $ this -> request -> getVar ( 'creator' ) , 'ParentID' => $ this -> request -> getVar ( 'ParentID' ) ) ; $ link = Controller :: join_links ( $ link , ( array_filter ( array_values ( $ params ) ) ? '?' . http_build_query ( $ params ) : null ) ) ; $ this -> extend ( 'updateLinkWithSearch' , $ link ) ; return $ link ; }
Generates the link with search params
57,034
public function getLinkMain ( ) { if ( $ this -> currentPageID ( ) != 0 && $ this -> class == 'CodeBankEditSnippet' ) { return $ this -> LinkWithSearch ( Controller :: join_links ( $ this -> Link ( 'show' ) , $ this -> currentPageID ( ) ) ) ; } else if ( $ this -> currentPageID ( ) != 0 && $ this -> class == 'CodeBank' ) { $ otherID = null ; if ( ! empty ( $ this -> urlParams [ 'OtherID' ] ) && is_numeric ( $ this -> urlParams [ 'OtherID' ] ) ) { $ otherID = intval ( $ this -> urlParams [ 'OtherID' ] ) ; } return $ this -> LinkWithSearch ( Controller :: join_links ( $ this -> Link ( 'show' ) , $ this -> currentPageID ( ) , $ otherID ) ) ; } return $ this -> LinkWithSearch ( singleton ( 'CodeBank' ) -> Link ( ) ) ; }
Gets the main tab link
57,035
public function TreeIsFiltered ( ) { return ( $ this -> request -> getVar ( 'q' ) || $ this -> request -> getVar ( 'tag' ) || $ this -> request -> getVar ( 'creator' ) ) ; }
Checks to see if the tree should be filtered or not
57,036
public function SiteTreeAsUL ( ) { $ html = $ this -> getSiteTreeFor ( $ this -> stat ( 'tree_class' ) , null , 'Children' , null ) ; $ this -> extend ( 'updateSiteTreeAsUL' , $ html ) ; return $ html ; }
Gets the snippet language tree as an unordered list
57,037
public function SearchForm ( ) { $ languages = SnippetLanguage :: get ( ) -> leftJoin ( 'Snippet' , '"Snippet"."LanguageID"="SnippetLanguage"."ID"' ) -> where ( '"SnippetLanguage"."Hidden"=0 OR "Snippet"."ID" IS NOT NULL' ) -> sort ( 'Name' ) ; $ fields = new FieldList ( new TextField ( 'q[Term]' , _t ( 'CodeBank.KEYWORD' , '_Keyword' ) ) , $ classDropdown = new DropdownField ( 'q[LanguageID]' , _t ( 'CodeBank.LANGUAGE' , '_Language' ) , $ languages -> map ( 'ID' , 'Name' ) ) ) ; $ classDropdown -> setEmptyString ( _t ( 'CodeBank.ALL_LANGUAGES' , '_All Languages' ) ) ; $ actions = new FieldList ( FormAction :: create ( 'doSearch' , _t ( 'CodeBank.APPLY_FILTER' , '_Apply Filter' ) ) -> setUseButtonTag ( true ) ) ; $ form = Form :: create ( $ this , 'SearchForm' , $ fields , $ actions ) -> addExtraClass ( 'cms-search-form' ) -> setFormMethod ( 'GET' ) -> setFormAction ( $ this -> Link ( ) ) -> disableSecurityToken ( ) -> unsetValidator ( ) ; $ form -> loadDataFrom ( $ this -> request -> getVars ( ) ) ; $ this -> extend ( 'updateSearchForm' , $ form ) ; return $ form ; }
Generates the search form
57,038
public function compare ( ) { $ compareContent = false ; $ snippet1 = Snippet :: get ( ) -> byID ( intval ( $ this -> urlParams [ 'ID' ] ) ) ; if ( empty ( $ snippet1 ) || $ snippet1 === false || $ snippet1 -> ID == 0 ) { $ snippet1 = false ; } if ( $ snippet1 !== false ) { $ snippet2 = $ snippet1 -> Version ( intval ( $ this -> urlParams [ 'OtherID' ] ) ) ; if ( empty ( $ snippet2 ) || $ snippet1 === false || $ snippet2 -> ID == 0 ) { $ snippet2 = false ; } if ( $ snippet2 !== false ) { $ snippet1Text = preg_replace ( '/\r\n|\n|\r/' , "\n" , $ snippet1 -> SnippetText ) ; $ snippet2Text = preg_replace ( '/\r\n|\n|\r/' , "\n" , $ snippet2 -> Text ) ; $ diff = new Text_Diff ( 'auto' , array ( preg_split ( '/\n/' , $ snippet1Text ) , preg_split ( '/\n/' , $ snippet2Text ) ) ) ; $ renderer = new WP_Text_Diff_Renderer_Table ( ) ; $ renderedDiff = $ renderer -> render ( $ diff ) ; if ( ! empty ( $ renderedDiff ) ) { $ lTable = '<table cellspacing="0" cellpadding="0" border="0" class="diff">' . '<colgroup>' . '<col class="ltype"/>' . '<col class="content"/>' . '</colgroup>' . '<tbody>' ; $ rTable = $ lTable ; header ( 'content-type: text/plain' ) ; $ xml = simplexml_load_string ( '<tbody>' . str_replace ( '&nbsp;' , ' ' , $ renderedDiff ) . '</tbody>' ) ; foreach ( $ xml -> children ( ) as $ row ) { $ i = 0 ; $ lTable .= '<tr>' ; $ rTable .= '<tr>' ; foreach ( $ row -> children ( ) as $ td ) { $ attr = $ td -> attributes ( ) ; if ( $ i == 0 ) { $ lTable .= $ td -> asXML ( ) ; } else { $ rTable .= $ td -> asXML ( ) ; } $ i ++ ; } $ lTable .= '</tr>' ; $ rTable .= '</tr>' ; } $ lTable .= '</tbody></table>' ; $ rTable .= '</tbody></table>' ; $ compareContent = '<div class="compare leftSide">' . $ lTable . '</div>' . '<div class="compare rightSide">' . $ rTable . '</div>' ; } } } Requirements :: css ( CB_DIR . '/css/CompareView.css' ) ; Requirements :: javascript ( CB_DIR . '/javascript/CodeBank.CompareView.js' ) ; return $ this -> renderWith ( 'CodeBank_CompareView' , array ( 'CompareContent' => $ compareContent ) ) ; }
Handles rendering of the compare view
57,039
public function getTreeHints ( ) { $ json = '' ; $ classes = array ( 'Snippet' , 'SnippetLanguage' , 'SnippetFolder' ) ; $ cacheCanCreate = array ( ) ; foreach ( $ classes as $ class ) $ cacheCanCreate [ $ class ] = singleton ( $ class ) -> canCreate ( ) ; $ cache = SS_Cache :: factory ( 'CodeBank_TreeHints' ) ; $ cacheKey = md5 ( implode ( '_' , array ( Member :: currentUserID ( ) , implode ( ',' , $ cacheCanCreate ) , implode ( ',' , $ classes ) ) ) ) ; if ( $ this -> request -> getVar ( 'flush' ) ) $ cache -> clean ( Zend_Cache :: CLEANING_MODE_ALL ) ; $ json = $ cache -> load ( $ cacheKey ) ; if ( ! $ json ) { $ def [ 'Root' ] = array ( ) ; $ def [ 'Root' ] [ 'disallowedParents' ] = array ( ) ; foreach ( $ classes as $ class ) { $ sng = singleton ( $ class ) ; $ allowedChildren = $ sng -> allowedChildren ( ) ; if ( $ allowedChildren == null ) $ allowedChildren = array ( ) ; foreach ( $ allowedChildren as $ child ) { $ instance = singleton ( $ child ) ; if ( $ instance instanceof HiddenClass ) continue ; if ( ! array_key_exists ( $ child , $ cacheCanCreate ) || ! $ cacheCanCreate [ $ child ] ) continue ; if ( $ instance -> stat ( 'need_permission' ) && ! $ this -> can ( singleton ( $ class ) -> stat ( 'need_permission' ) ) ) continue ; $ title = $ instance -> i18n_singular_name ( ) ; $ def [ $ class ] [ 'allowedChildren' ] [ ] = array ( "ssclass" => $ child , "ssname" => $ title ) ; } $ allowedChildren = array_keys ( array_diff ( $ classes , $ allowedChildren ) ) ; if ( $ allowedChildren ) $ def [ $ class ] [ 'disallowedChildren' ] = $ allowedChildren ; $ defaultChild = $ sng -> default_child ( ) ; if ( $ defaultChild != null ) $ def [ $ class ] [ 'defaultChild' ] = $ defaultChild ; if ( isset ( $ def [ $ class ] [ 'disallowedChildren' ] ) ) { foreach ( $ def [ $ class ] [ 'disallowedChildren' ] as $ disallowedChild ) { $ def [ $ disallowedChild ] [ 'disallowedParents' ] [ ] = $ class ; } } $ def [ 'Root' ] [ 'disallowedParents' ] [ ] = $ class ; } $ json = Convert :: raw2xml ( Convert :: raw2json ( $ def ) ) ; $ cache -> save ( $ json , $ cacheKey ) ; } return $ json ; }
Create serialized JSON string with tree hints data to be injected into data - hints attribute of root node of jsTree .
57,040
public function addSnippet ( SS_HTTPRequest $ request ) { if ( $ request -> getVar ( 'Type' ) == 'SnippetFolder' ) { return $ this -> redirect ( Controller :: join_links ( $ this -> Link ( 'addFolder' ) , '?FolderID=' . str_replace ( 'folder-' , '' , $ request -> getVar ( 'ID' ) ) ) ) ; } else { return $ this -> redirect ( Controller :: join_links ( $ this -> Link ( 'add' ) , '?LanguageID=' . str_replace ( 'language-' , '' , $ request -> getVar ( 'ID' ) ) ) ) ; } }
Handles requests to add a snippet or folder to a language
57,041
public function moveSnippet ( SS_HTTPRequest $ request ) { $ snippet = Snippet :: get ( ) -> byID ( intval ( $ request -> getVar ( 'ID' ) ) ) ; if ( empty ( $ snippet ) || $ snippet === false || $ snippet -> ID == 0 ) { $ this -> response -> setStatusCode ( 403 , _t ( 'CodeBank.SNIPPIT_NOT_EXIST' , '_Snippit does not exist' ) ) ; return ; } $ parentID = $ request -> getVar ( 'ParentID' ) ; if ( strpos ( $ parentID , 'language-' ) !== false ) { $ lang = SnippetLanguage :: get ( ) -> byID ( intval ( str_replace ( 'language-' , '' , $ parentID ) ) ) ; if ( empty ( $ lang ) || $ lang === false || $ lang -> ID == 0 ) { $ this -> response -> setStatusCode ( 403 , _t ( 'CodeBank.LANGUAGE_NOT_EXIST' , '_Language does not exist' ) ) ; return ; } if ( $ lang -> ID != $ snippet -> LanguageID ) { $ this -> response -> setStatusCode ( 403 , _t ( 'CodeBank.CANNOT_MOVE_TO_LANGUAGE' , '_You cannot move a snippet to another language' ) ) ; return ; } DB :: query ( 'UPDATE "Snippet" SET "FolderID"=0 WHERE "ID"=' . $ snippet -> ID ) ; $ this -> response -> addHeader ( 'X-Status' , rawurlencode ( _t ( 'CodeBank.SNIPPET_MOVED' , '_Snippet moved successfully' ) ) ) ; return ; } else if ( strpos ( $ parentID , 'folder-' ) !== false ) { $ folder = SnippetFolder :: get ( ) -> byID ( intval ( str_replace ( 'folder-' , '' , $ parentID ) ) ) ; if ( empty ( $ folder ) || $ folder === false || $ folder -> ID == 0 ) { $ this -> response -> setStatusCode ( 403 , _t ( 'CodeBank.FOLDER_NOT_EXIST' , '_Folder does not exist' ) ) ; return ; } if ( $ folder -> LanguageID != $ snippet -> LanguageID ) { $ this -> response -> setStatusCode ( 403 , _t ( 'CodeBank.CANNOT_MOVE_TO_FOLDER' , '_You cannot move a snippet to a folder in another language' ) ) ; return ; } DB :: query ( 'UPDATE "Snippet" SET "FolderID"=' . $ folder -> ID . ' WHERE "ID"=' . $ snippet -> ID ) ; $ this -> response -> addHeader ( 'X-Status' , rawurlencode ( _t ( 'CodeBank.SNIPPET_MOVED' , '_Snippet moved successfully' ) ) ) ; return ; } $ this -> response -> setStatusCode ( 403 , _t ( 'CodeBank.UNKNOWN_PARENT' , '_Unknown Parent' ) ) ; }
Handles moving of a snippet when the tree is reordered
57,042
public function AddFolderForm ( ) { $ fields = new FieldList ( new TabSet ( 'Root' , new Tab ( 'Main' , 'Main' , new TextField ( 'Name' , _t ( 'SnippetFolder.NAME' , '_Name' ) , null , 150 ) ) ) ) ; $ noParent = true ; if ( strpos ( $ this -> request -> getVar ( 'ParentID' ) , 'language-' ) !== false ) { $ fields -> push ( new HiddenField ( 'LanguageID' , 'LanguageID' , intval ( str_replace ( 'language-' , '' , $ this -> request -> getVar ( 'ParentID' ) ) ) ) ) ; $ noParent = false ; } else if ( strpos ( $ this -> request -> getVar ( 'ParentID' ) , 'folder-' ) !== false ) { $ folder = SnippetFolder :: get ( ) -> byID ( intval ( str_replace ( 'folder-' , '' , $ this -> request -> getVar ( 'ParentID' ) ) ) ) ; if ( ! empty ( $ folder ) && $ folder !== false && $ folder -> ID != 0 ) { $ fields -> push ( new HiddenField ( 'ParentID' , 'ParentID' , $ folder -> ID ) ) ; $ fields -> push ( new HiddenField ( 'LanguageID' , 'LanguageID' , $ folder -> LanguageID ) ) ; $ noParent = false ; } } else { if ( $ this -> request -> postVar ( 'LanguageID' ) ) { $ fields -> push ( new HiddenField ( 'LanguageID' , 'LanguageID' , intval ( $ this -> request -> postVar ( 'LanguageID' ) ) ) ) ; $ noParent = false ; } if ( $ this -> request -> postVar ( 'ParentID' ) ) { $ fields -> push ( new HiddenField ( 'ParentID' , 'ParentID' , intval ( $ this -> request -> postVar ( 'ParentID' ) ) ) ) ; $ noParent = false ; } } $ actions = new FieldList ( new FormAction ( 'doAddFolder' , _t ( 'CodeBank.SAVE' , '_Save' ) ) ) ; $ validator = new RequiredFields ( 'Name' ) ; $ form = new Form ( $ this , 'AddFolderForm' , $ fields , $ actions , $ validator ) ; $ form -> addExtraClass ( 'member-profile-form' ) ; if ( $ noParent ) { $ form -> setMessage ( _t ( 'CodeBank.FOLDER_NO_PARENT' , '_Folder does not have a parent language or folder' ) , 'bad' ) ; $ form -> setFields ( new FieldList ( ) ) ; $ form -> setActions ( new FieldList ( ) ) ; } return $ form ; }
Form used for adding a folder
57,043
public function RenameFolderForm ( ) { $ folder = SnippetFolder :: get ( ) -> byID ( intval ( str_replace ( 'folder-' , '' , $ this -> request -> getVar ( 'ID' ) ) ) ) ; if ( ! empty ( $ folder ) && $ folder !== false && $ folder -> ID != 0 ) { $ fields = new FieldList ( new TabSet ( 'Root' , new Tab ( 'Main' , 'Main' , new TextField ( 'Name' , _t ( 'SnippetFolder.NAME' , '_Name' ) , null , 150 ) ) ) , new HiddenField ( 'ID' , 'ID' ) ) ; $ actions = new FieldList ( new FormAction ( 'doRenameFolder' , _t ( 'CodeBank.SAVE' , '_Save' ) ) ) ; } else { $ fields = new FieldList ( ) ; $ actions = new FieldList ( ) ; } $ validator = new RequiredFields ( 'Name' ) ; $ form = new Form ( $ this , 'RenameFolderForm' , $ fields , $ actions , $ validator ) ; $ form -> addExtraClass ( 'member-profile-form' ) ; if ( empty ( $ folder ) || $ folder === false || $ folder -> ID == 0 ) { $ form -> setMessage ( _t ( 'CodeBank.FOLDER_NOT_FOUND' , '_Folder could not be found' ) , 'bad' ) ; } else { $ form -> loadDataFrom ( $ folder ) ; $ form -> setFormAction ( Controller :: join_links ( $ form -> FormAction ( ) , '?ID=' . $ folder -> ID ) ) ; } return $ form ; }
Form used for renaming a folder
57,044
public function doRenameFolder ( $ data , Form $ form ) { $ folder = SnippetFolder :: get ( ) -> byID ( intval ( $ data [ 'ID' ] ) ) ; if ( empty ( $ folder ) || $ folder === false || $ folder -> ID == 0 ) { $ form -> sessionMessage ( _t ( 'CodeBank.FOLDER_NOT_FOUND' , '_Folder could not be found' ) , 'bad' ) ; return $ this -> redirectBack ( ) ; } $ existingCheck = SnippetFolder :: get ( ) -> filter ( 'Name:nocase' , Convert :: raw2sql ( $ data [ 'Name' ] ) ) -> filter ( 'LanguageID' , $ folder -> LanguageID ) -> filter ( 'ParentID' , $ folder -> ParentID ) -> filter ( 'ID:not' , $ folder -> ID ) ; if ( $ existingCheck -> Count ( ) > 0 ) { $ form -> sessionMessage ( _t ( 'CodeBank.FOLDER_EXISTS' , '_A folder already exists with that name' ) , 'bad' ) ; return $ this -> redirectBack ( ) ; } $ form -> saveInto ( $ folder ) ; $ folder -> write ( ) ; Requirements :: customScript ( 'window.parent.renameCodeBankTreeNode("folder-' . $ folder -> ID . '", "' . addslashes ( $ folder -> TreeTitle ) . '");' ) ; $ form -> setMessage ( _t ( 'CodeBank.FOLDER_RENAMED' , '_Folder Renamed' ) , 'good' ) ; return $ this -> customise ( array ( 'Content' => ' ' , 'Form' => $ form ) ) -> renderWith ( 'CMSDialog' ) ; }
Performs the rename of the folder
57,045
public function deleteFolder ( ) { $ folder = SnippetFolder :: get ( ) -> byID ( intval ( str_replace ( 'folder-' , '' , $ this -> request -> getVar ( 'ID' ) ) ) ) ; if ( empty ( $ folder ) || $ folder === false || $ folder -> ID == 0 ) { $ this -> response -> setStatusCode ( 404 , _t ( 'CodeBank.FOLDER_NOT_FOUND' , '_Folder could not be found' ) ) ; return ; } $ folder -> delete ( ) ; return 'HELO' ; }
Deletes a folder node
57,046
public function printSnippet ( ) { $ record = $ this -> getRecord ( $ this -> currentPageID ( ) ) ; if ( ! empty ( $ record ) && $ record !== false && $ record -> ID > 0 ) { $ version = false ; if ( ! empty ( $ this -> urlParams [ 'OtherID' ] ) && is_numeric ( $ this -> urlParams [ 'OtherID' ] ) ) { $ version = $ record -> Version ( intval ( $ this -> urlParams [ 'OtherID' ] ) ) ; } Requirements :: css ( CB_DIR . '/javascript/external/syntaxhighlighter/themes/shCore.css' ) ; Requirements :: css ( CB_DIR . '/javascript/external/syntaxhighlighter/themes/shCoreDefault.css' ) ; Requirements :: css ( CB_DIR . '/javascript/external/syntaxhighlighter/themes/shThemeDefault.css' ) ; Requirements :: javascript ( CB_DIR . '/javascript/external/syntaxhighlighter/brushes/shCore.js' ) ; Requirements :: javascript ( CB_DIR . '/javascript/external/syntaxhighlighter/brushes/' . $ record -> getBrushName ( ) . '.js' ) ; Requirements :: javascript ( CB_DIR . '/javascript/CodeBank_PrinterFriendly.js' ) ; return $ this -> renderWith ( 'CodeBank_PrinterFriendly' , array ( 'Snippet' => $ record , 'SnippetVersion' => $ version , 'CodeBankDir' => CB_DIR ) ) ; } return $ this -> response -> setStatusCode ( 404 ) ; }
Handles requests to print the current snippet
57,047
protected function hasOldTables ( ) { if ( ! file_exists ( ASSETS_PATH . '/.codeBankMigrated' ) ) { $ tables = DB :: tableList ( ) ; if ( array_key_exists ( 'snippits' , $ tables ) && array_key_exists ( 'snippit_search' , $ tables ) ) { return true ; } else { touch ( ASSETS_PATH . '/.codeBankMigrated' ) ; } } return false ; }
Tests to see if the old tables exist
57,048
public function each ( Callable $ f ) : void { foreach ( $ this -> items as $ i ) { $ f ( $ i ) ; } }
run a function against each item in the collection
57,049
public function equals ( Collection $ that ) : bool { return get_class ( $ this ) == get_class ( $ that ) && $ this -> items === $ that -> items ; }
compare one collection against another . collections are considered equal if both collection classes are of the same type and both item arrays are considered equal with strict comparison .
57,050
public function reduce ( Callable $ f , $ initial = null ) { return array_reduce ( $ this -> items , $ f , $ initial ) ; }
return a single value reduced from the collection by the provided function .
57,051
public function setExtbaseConfiguration ( $ pluginName , $ controllerClass , $ actionName , $ extensionName = null ) { if ( ! empty ( $ extensionName ) ) { $ extensionName = GeneralUtility :: camelCaseToLowerCaseUnderscored ( trim ( $ extensionName ) ) ; if ( ! in_array ( $ extensionName , ExtensionManagementUtility :: getLoadedExtensionListArray ( ) ) ) { throw new \ RuntimeException ( sprintf ( 'Extension "%s" is not available' , $ extensionName ) , 1481645834 ) ; } $ this -> extbaseExtensionName = $ extensionName ; } $ pluginName = trim ( $ pluginName ) ; if ( empty ( $ pluginName ) ) { throw new \ RuntimeException ( sprintf ( 'Invalid plugin name "%s"' , $ pluginName ) , 1481646376 ) ; } $ this -> extbasePlugin = $ pluginName ; $ controllerClass = trim ( $ controllerClass ) ; if ( empty ( $ controllerClass ) || ! class_exists ( $ controllerClass ) || ! ( $ controllerReflection = new \ ReflectionClass ( $ controllerClass ) ) -> implementsInterface ( ControllerInterface :: class ) ) { throw new \ RuntimeException ( sprintf ( 'Invalid controller class "%s"' , $ controllerClass ) , 1481646376 ) ; } $ this -> extbaseControllerClass = $ controllerClass ; $ this -> extbaseController = preg_replace ( '/Controller$/' , '' , $ controllerReflection -> getShortName ( ) ) ; $ actionName = trim ( $ actionName ) ; if ( empty ( $ actionName ) || ! is_callable ( [ $ this -> extbaseControllerClass , $ actionName . 'Action' ] ) ) { throw new \ RuntimeException ( sprintf ( 'Invalid controller action "%s"' , $ actionName ) , 1481646569 ) ; } $ this -> extbaseAction = $ actionName ; $ this -> controllerArgumentRequestPrefix = 'tx_' . strtolower ( str_replace ( '_' , '' , $ this -> extbaseExtensionName ) ) . '_' . strtolower ( $ this -> extbasePlugin ) ; $ this -> request -> setControllerObjectName ( $ this -> extbaseControllerClass ) ; $ this -> request -> setControllerExtensionName ( $ this -> extbaseExtensionName ) ; $ this -> request -> setControllerName ( $ this -> extbaseController ) ; $ this -> request -> setControllerActionName ( $ this -> extbaseAction ) ; $ this -> request -> setPluginName ( $ this -> extbasePlugin ) ; $ this -> request -> setArgument ( $ this -> controllerArgumentRequestPrefix , [ 'controller' => $ this -> extbaseController , 'action' => $ this -> extbaseAction , ] ) ; $ configurationManager = $ this -> objectManager -> get ( ConfigurationManagerInterface :: class ) ; $ this -> controllerSettings = $ configurationManager -> getConfiguration ( ConfigurationManagerInterface :: CONFIGURATION_TYPE_SETTINGS , GeneralUtility :: underscoredToUpperCamelCase ( $ this -> extbaseExtensionName ) , $ this -> extbasePlugin ) ; }
Set the extbase configuration
57,052
public function setControllerActionArgument ( $ name , $ value ) { $ name = trim ( $ name ) ; if ( empty ( $ name ) ) { throw new \ RuntimeException ( 'Invalid extbase controller argument name' , 1481708515 ) ; } $ this -> request -> setArgument ( $ name , $ value ) ; }
Set a controller action argument
57,053
public function setControllerSettings ( array $ settings , $ override = false ) { $ this -> controllerSettings = $ override ? $ settings : array_replace ( $ this -> controllerSettings , $ settings ) ; }
Set the controller settings
57,054
protected function getControllerInstance ( ) { if ( $ this -> controllerInstance === null ) { $ extendedControllerClassName = $ this -> extbaseController . 'ComponentController_' . md5 ( $ this -> extbaseControllerClass ) ; if ( ! class_exists ( $ extendedControllerClassName , false ) ) { $ extendedControllerPhp = 'class ' . $ extendedControllerClassName . ' extends ' . $ this -> extbaseControllerClass ; $ extendedControllerPhp .= ' implements ' . ComponentControllerInterface :: class ; $ extendedControllerPhp .= ' { use ' . ComponentControllerTrait :: class . '; }' ; eval ( $ extendedControllerPhp ) ; } $ this -> controllerInstance = $ this -> objectManager -> get ( $ extendedControllerClassName ) ; } $ settings = $ this -> controllerSettings ? : [ ] ; return $ this -> controllerInstance -> setSettings ( $ settings ) ; }
Return an extend Extbase controller instance
57,055
public function writeInteger ( $ int ) { if ( ( $ int & 0xffffff80 ) == 0 ) { $ this -> _stream -> writeByte ( $ int & 0x7f ) ; return $ this ; } if ( ( $ int & 0xffffc000 ) == 0 ) { $ this -> _stream -> writeByte ( ( $ int >> 7 ) | 0x80 ) ; $ this -> _stream -> writeByte ( $ int & 0x7f ) ; return $ this ; } if ( ( $ int & 0xffe00000 ) == 0 ) { $ this -> _stream -> writeByte ( ( $ int >> 14 ) | 0x80 ) ; $ this -> _stream -> writeByte ( ( $ int >> 7 ) | 0x80 ) ; $ this -> _stream -> writeByte ( $ int & 0x7f ) ; return $ this ; } $ this -> _stream -> writeByte ( ( $ int >> 22 ) | 0x80 ) ; $ this -> _stream -> writeByte ( ( $ int >> 15 ) | 0x80 ) ; $ this -> _stream -> writeByte ( ( $ int >> 8 ) | 0x80 ) ; $ this -> _stream -> writeByte ( $ int & 0xff ) ; return $ this ; }
Write an AMF3 integer
57,056
public function writeString ( & $ string ) { $ len = strlen ( $ string ) ; if ( ! $ len ) { $ this -> writeInteger ( 0x01 ) ; return $ this ; } $ ref = array_key_exists ( $ string , $ this -> _referenceStrings ) ? $ this -> _referenceStrings [ $ string ] : false ; if ( $ ref === false ) { $ this -> _referenceStrings [ $ string ] = count ( $ this -> _referenceStrings ) ; $ this -> writeBinaryString ( $ string ) ; } else { $ ref <<= 1 ; $ this -> writeInteger ( $ ref ) ; } return $ this ; }
Send string to output stream
57,057
public function writeByteArray ( & $ data ) { if ( $ this -> writeObjectReference ( $ data ) ) { return $ this ; } if ( is_string ( $ data ) ) { } else if ( $ data instanceof Zend_Amf_Value_ByteArray ) { $ data = $ data -> getData ( ) ; } else { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( 'Invalid ByteArray specified; must be a string or Zend_Amf_Value_ByteArray' ) ; } $ this -> writeBinaryString ( $ data ) ; return $ this ; }
Send ByteArray to output stream
57,058
public function writeXml ( $ xml ) { if ( $ this -> writeObjectReference ( $ xml ) ) { return $ this ; } if ( is_string ( $ xml ) ) { } else if ( $ xml instanceof DOMDocument ) { $ xml = $ xml -> saveXml ( ) ; } else if ( $ xml instanceof SimpleXMLElement ) { $ xml = $ xml -> asXML ( ) ; } else { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( 'Invalid xml specified; must be a DOMDocument or SimpleXMLElement' ) ; } $ this -> writeBinaryString ( $ xml ) ; return $ this ; }
Send xml to output stream
57,059
public function writeArray ( & $ array ) { $ this -> _referenceObjects [ ] = $ array ; $ numeric = array ( ) ; $ string = array ( ) ; foreach ( $ array as $ key => & $ value ) { if ( is_int ( $ key ) ) { $ numeric [ ] = $ value ; } else { $ string [ $ key ] = $ value ; } } $ length = count ( $ numeric ) ; $ id = ( $ length << 1 ) | 0x01 ; $ this -> writeInteger ( $ id ) ; foreach ( $ string as $ key => & $ value ) { $ this -> writeString ( $ key ) -> writeTypeMarker ( $ value ) ; } $ this -> writeString ( $ this -> _strEmpty ) ; foreach ( $ numeric as & $ value ) { $ this -> writeTypeMarker ( $ value ) ; } return $ this ; }
Write a PHP array back to the amf output stream
57,060
public function login ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; $ response [ 'login' ] = true ; $ member = MemberAuthenticator :: authenticate ( array ( 'Email' => $ data -> user , 'Password' => $ data -> pass ) ) ; if ( $ member instanceof Member && $ member -> ID != 0 && Permission :: check ( 'CODE_BANK_ACCESS' , 'any' , $ member ) ) { try { $ member -> logIn ( ) ; $ ipAgrement = CodeBankConfig :: CurrentConfig ( ) -> IPAgreement ; $ prefs = new stdClass ( ) ; $ prefs -> heartbeat = $ member -> UseHeartbeat ; $ response [ 'status' ] = 'HELO' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.WELCOME_USER' , '_Welcome {user}' , array ( 'user' => htmlentities ( $ member -> Name ) ) ) ; $ response [ 'data' ] = array ( 'id' => Member :: currentUserID ( ) , 'hasIPAgreement' => ! empty ( $ ipAgrement ) , 'preferences' => $ prefs , 'isAdmin' => ( Permission :: check ( 'ADMIN' ) !== false ) , 'displayName' => ( trim ( $ member -> Name ) == '' ? $ member -> Email : trim ( $ member -> Name ) ) ) ; } catch ( Exception $ e ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.SERVER_ERROR' , '_Server error has occured, please try again later' ) ; } } else { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.INVALID_LOGIN' , '_Invalid Login' ) ; } return $ response ; }
Attempt to login
57,061
public function logout ( ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; $ response [ 'session' ] = 'expired' ; $ member = Member :: currentUser ( ) ; if ( $ member ) { $ member -> logOut ( ) ; } return $ response ; }
Closes the users session
57,062
public function lostPassword ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; $ response [ 'login' ] = true ; $ SQL_email = Convert :: raw2sql ( $ data -> user ) ; $ member = Member :: get_one ( 'Member' , "\"Email\"='{$SQL_email}'" ) ; $ sng = new MemberLoginForm ( Controller :: has_curr ( ) ? Controller :: curr ( ) : singleton ( 'Controller' ) , 'LoginForm' ) ; $ results = $ sng -> extend ( 'forgotPassword' , $ member ) ; if ( $ results && is_array ( $ results ) && in_array ( false , $ results , true ) ) { $ response [ 'status' ] = 'HELO' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PASSWORD_SENT_TEXT' , "A reset link has been sent to '{email}', provided an account exists for this email address." , array ( 'email' => $ data [ 'Email' ] ) ) ; } if ( $ member ) { $ token = $ member -> generateAutologinTokenAndStoreHash ( ) ; $ e = Member_ForgotPasswordEmail :: create ( ) ; $ e -> populateTemplate ( $ member ) ; $ e -> populateTemplate ( array ( 'PasswordResetLink' => Security :: getPasswordResetLink ( $ member , $ token ) ) ) ; $ e -> setTo ( $ member -> Email ) ; $ e -> send ( ) ; $ response [ 'status' ] = 'HELO' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PASSWORD_SENT_TEXT' , "A reset link has been sent to '{email}', provided an account exists for this email address." , array ( 'email' => $ data -> user ) ) ; } else if ( ! empty ( $ data -> user ) ) { $ response [ 'status' ] = 'HELO' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PASSWORD_SENT_TEXT' , "A reset link has been sent to '{email}', provided an account exists for this email address." , array ( 'email' => $ data -> user ) ) ; } else { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'Member.ENTEREMAIL' , 'Please enter an email address to get a password reset link.' ) ; } return $ response ; }
Method for allowing a user to reset their password
57,063
public static function renderStatic ( array $ arguments , \ Closure $ renderChildrenClosure , RenderingContextInterface $ renderingContext ) { $ content = trim ( $ renderChildrenClosure ( ) ) ; return preg_match ( '%^https?\:\/\/%' , $ content ) ? htmlspecialchars ( $ content ) : '{{ path \'/' . ltrim ( $ content , '/' ) . '\' }}' ; }
Render a resource URL for Fractal possibly treated with the path view helper
57,064
protected function _addTree ( Zend_Server_Reflection_Node $ parent , $ level = 0 ) { if ( $ level >= $ this -> _sigParamsDepth ) { return ; } foreach ( $ this -> _sigParams [ $ level ] as $ value ) { $ node = new Zend_Server_Reflection_Node ( $ value , $ parent ) ; if ( ( null !== $ value ) && ( $ this -> _sigParamsDepth > $ level + 1 ) ) { $ this -> _addTree ( $ node , $ level + 1 ) ; } } }
Create signature node tree
57,065
protected function _buildTree ( ) { $ returnTree = array ( ) ; foreach ( ( array ) $ this -> _return as $ value ) { $ node = new Zend_Server_Reflection_Node ( $ value ) ; $ this -> _addTree ( $ node ) ; $ returnTree [ ] = $ node ; } return $ returnTree ; }
Build the signature tree
57,066
protected function _buildSignatures ( $ return , $ returnDesc , $ paramTypes , $ paramDesc ) { $ this -> _return = $ return ; $ this -> _returnDesc = $ returnDesc ; $ this -> _paramDesc = $ paramDesc ; $ this -> _sigParams = $ paramTypes ; $ this -> _sigParamsDepth = count ( $ paramTypes ) ; $ signatureTrees = $ this -> _buildTree ( ) ; $ signatures = array ( ) ; $ endPoints = array ( ) ; foreach ( $ signatureTrees as $ root ) { $ tmp = $ root -> getEndPoints ( ) ; if ( empty ( $ tmp ) ) { $ endPoints = array_merge ( $ endPoints , array ( $ root ) ) ; } else { $ endPoints = array_merge ( $ endPoints , $ tmp ) ; } } foreach ( $ endPoints as $ node ) { if ( ! $ node instanceof Zend_Server_Reflection_Node ) { continue ; } $ signature = array ( ) ; do { array_unshift ( $ signature , $ node -> getValue ( ) ) ; $ node = $ node -> getParent ( ) ; } while ( $ node instanceof Zend_Server_Reflection_Node ) ; $ signatures [ ] = $ signature ; } $ params = $ this -> _reflection -> getParameters ( ) ; foreach ( $ signatures as $ signature ) { $ return = new Zend_Server_Reflection_ReturnValue ( array_shift ( $ signature ) , $ this -> _returnDesc ) ; $ tmp = array ( ) ; foreach ( $ signature as $ key => $ type ) { $ param = new Zend_Server_Reflection_Parameter ( $ params [ $ key ] , $ type , ( isset ( $ this -> _paramDesc [ $ key ] ) ? $ this -> _paramDesc [ $ key ] : null ) ) ; $ param -> setPosition ( $ key ) ; $ tmp [ ] = $ param ; } $ this -> _prototypes [ ] = new Zend_Server_Reflection_Prototype ( $ return , $ tmp ) ; } }
Build method signatures
57,067
static public function createWithSafeMessage ( $ safeMessage = "" , array $ messageData = array ( ) , $ code = 0 , \ Exception $ previous = null ) { $ exception = new static ( $ safeMessage , $ code , $ previous ) ; $ exception -> setSafeMessage ( $ safeMessage , $ messageData ) ; return $ exception ; }
Helper method to create this exception and set the safe message that will be shown to the user .
57,068
public function parentStack ( ) { $ p = $ this -> owner ; while ( $ p ) { $ stack [ ] = $ p ; if ( $ p -> FolderID && $ p -> FolderID > 0 ) { $ folder = $ p -> Folder ( ) ; if ( ! empty ( $ folder ) && $ folder !== false && $ folder -> ID != 0 ) { $ p = $ folder ; } } else { $ p = $ p -> LanguageID ? $ p -> Language ( ) : null ; } } return $ stack ; }
Return an array of this page and its ancestors ordered item - > root .
57,069
public function getAncestors ( ) { $ ancestors = new ArrayList ( ) ; $ object = $ this -> owner ; while ( $ object = $ object -> Language ( ) ) { $ ancestors -> push ( $ object ) ; } return $ ancestors ; }
Return all the parents of this class in a set ordered from the lowest to highest parent .
57,070
public function naturalNext ( $ className = null , $ root = 0 , $ afterNode = null ) { if ( $ afterNode && $ afterNode -> ID != $ this -> owner -> ID ) { if ( ! $ className || ( $ className && $ this -> owner -> class == $ className ) ) { return $ this -> owner ; } } $ nextNode = null ; $ baseClass = ClassInfo :: baseDataClass ( $ this -> owner -> class ) ; $ children = DataObject :: get ( ClassInfo :: baseDataClass ( $ this -> owner -> class ) , "\"$baseClass\".\"LanguageID\"={$this->owner->ID}" . ( ( $ afterNode ) ? " AND \"Sort\" > " . sprintf ( '%d' , $ afterNode -> Sort ) : "" ) , '"Sort" ASC' ) ; if ( $ children ) { foreach ( $ children as $ node ) { if ( $ nextNode = $ node -> naturalNext ( $ className , $ node -> ID , $ this -> owner ) ) { break ; } } if ( $ nextNode ) { return $ nextNode ; } } if ( ! ( is_numeric ( $ root ) && $ root == $ this -> owner -> ID || $ root == $ this -> owner -> class ) && ( $ parent = $ this -> owner -> Language ( ) ) ) { return $ parent -> naturalNext ( $ className , $ root , $ this -> owner ) ; } return null ; }
Get the next node in the tree of the type . If there is no instance of the className descended from this node then search the parents .
57,071
public function markById ( $ id , $ open = false , $ className = null ) { if ( isset ( $ this -> markedNodes [ $ className . '_' . $ id ] ) ) { $ this -> markChildren ( $ this -> markedNodes [ $ className . '_' . $ id ] ) ; if ( $ open ) { $ this -> markedNodes [ $ className . '_' . $ id ] -> markOpened ( ) ; } return true ; } else { return false ; } }
Mark the children of the DataObject with the given ID .
57,072
protected function markingFinished ( $ numChildrenMethod = "numChildren" ) { if ( $ this -> markedNodes ) { foreach ( $ this -> markedNodes as $ id => $ node ) { if ( ! $ node -> isExpanded ( ) && ! $ node -> $ numChildrenMethod ( ) ) { $ node -> markExpanded ( ) ; } } } }
Ensure marked nodes that have children are also marked expanded . Call this after marking but before iterating over the tree .
57,073
public function markingClasses ( ) { $ classes = '' ; if ( ! $ this -> isExpanded ( ) ) { $ classes .= " unexpanded jstree-closed" ; } if ( $ this -> isTreeOpened ( ) ) { if ( $ this -> numChildren ( ) > 0 ) $ classes .= " jstree-open" ; } else { $ classes .= " closed" ; } return $ classes ; }
Return CSS classes of unexpanded closed both or neither depending on the marking of this DataObject .
57,074
public function isExpanded ( ) { $ baseClass = ClassInfo :: baseDataClass ( $ this -> owner -> class ) ; $ id = $ this -> owner -> ID ; return isset ( self :: $ expanded [ $ baseClass ] [ $ id ] ) ? self :: $ expanded [ $ baseClass ] [ $ id ] : false ; }
Check if this DataObject is expanded .
57,075
public function isTreeOpened ( ) { $ baseClass = ClassInfo :: baseDataClass ( $ this -> owner -> class ) ; $ id = $ this -> owner -> ID ; return isset ( self :: $ treeOpened [ $ baseClass ] [ $ id ] ) ? self :: $ treeOpened [ $ baseClass ] [ $ id ] : false ; }
Check if this DataObject s tree is opened .
57,076
public function partialTreeAsUL ( $ minCount = 50 ) { $ children = $ this -> owner -> AllChildren ( ) ; if ( $ children ) { if ( $ attributes ) $ attributes = " $attributes" ; $ output = "<ul$attributes>\n" ; foreach ( $ children as $ child ) { $ output .= eval ( "return $titleEval;" ) . "\n" . $ child -> getChildrenAsUL ( "" , $ titleEval , $ extraArg ) . "</li>\n" ; } $ output .= "</ul>\n" ; } return $ output ; }
Return a partial tree as an HTML UL .
57,077
public function Children ( ) { if ( ! ( isset ( $ this -> _cache_children ) && $ this -> _cache_children ) ) { $ result = $ this -> owner -> stageChildren ( false ) ; if ( isset ( $ result ) ) { $ this -> _cache_children = new ArrayList ( ) ; foreach ( $ result as $ child ) { if ( $ child -> canView ( ) ) { $ this -> _cache_children -> push ( $ child ) ; } } } } return $ this -> _cache_children ; }
Get the children for this DataObject .
57,078
public function stageChildren ( $ showAll = false ) { $ baseClass = ClassInfo :: baseDataClass ( $ this -> owner -> class ) ; if ( $ baseClass == 'SnippetPackage' ) { if ( $ this -> owner -> ID == 0 ) { $ staged = SnippetPackage :: get ( ) ; } } else if ( $ baseClass == 'SnippetLanguage' ) { if ( $ this -> owner -> ID == 0 ) { $ staged = SnippetLanguage :: get ( ) ; } else { $ staged = ArrayList :: create ( array_merge ( $ this -> owner -> Folders ( ) -> toArray ( ) , $ this -> owner -> Snippets ( ) -> filter ( 'FolderID' , 0 ) -> toArray ( ) ) ) ; } } else if ( $ baseClass == 'SnippetFolder' ) { $ staged = ArrayList :: create ( array_merge ( $ this -> owner -> Folders ( ) -> toArray ( ) , $ this -> owner -> Snippets ( ) -> toArray ( ) ) ) ; } else { $ staged = new ArrayList ( ) ; } $ this -> owner -> extend ( "augmentStageChildren" , $ staged , $ showAll ) ; return $ staged ; }
Return children from the stage site
57,079
public static function CurrentConfig ( ) { if ( empty ( self :: $ _currentConfig ) ) { self :: $ _currentConfig = CodeBankConfig :: get ( ) -> first ( ) ; } return self :: $ _currentConfig ; }
Gets the current config
57,080
private function eventsShouldExistInStore ( DomainEvent ... $ events ) { $ expected = array_map ( function ( DomainEvent $ event ) { return $ this -> serializer -> serialize ( $ event ) ; } , $ events ) ; $ existing = $ this -> eventStore -> getEvents ( ) -> map ( function ( DomainEvent $ event ) { return $ this -> serializer -> serialize ( $ event ) ; } ) -> toArray ( ) ; $ notFound = array_filter ( $ expected , function ( $ expectedEvent ) use ( $ existing ) { return ! in_array ( $ expectedEvent , $ existing ) ; } ) ; if ( empty ( $ notFound ) ) return ; throw new FailureException ( $ this -> missingEventExceptionMessage ( $ notFound ) ) ; }
internal method that throws an exception should the expected events not exist within the event store
57,081
protected function loadJsonParameters ( ) { $ reflectionObject = new \ ReflectionObject ( $ this ) ; $ componentFile = $ reflectionObject -> getFileName ( ) ; $ parameterFile = dirname ( $ componentFile ) . DIRECTORY_SEPARATOR . pathinfo ( $ componentFile , PATHINFO_FILENAME ) . '.json' ; if ( is_readable ( $ parameterFile ) ) { $ jsonParameters = file_get_contents ( $ parameterFile ) ; if ( strlen ( $ jsonParameters ) ) { $ jsonParameterObj = @ json_decode ( $ jsonParameters ) ; if ( $ jsonParameterObj && is_object ( $ jsonParameterObj ) ) { foreach ( $ jsonParameterObj as $ name => $ value ) { $ this -> setParameter ( $ name , $ value ) ; } } } } }
Load parameters provided from an external JSON file
57,082
protected function setParameter ( $ param , $ value ) { $ param = trim ( $ param ) ; if ( ! strlen ( $ param ) ) { throw new \ RuntimeException ( sprintf ( 'Invalid fluid template parameter "%s"' , $ param ) , 1481551574 ) ; } $ this -> parameters [ $ param ] = $ value ; }
Set a rendering parameter
57,083
public function addCertificatePair ( $ private_key_file , $ public_key_file , $ type = Zend_InfoCard_Cipher :: ENC_RSA_OAEP_MGF1P , $ password = null ) { return $ this -> _infoCard -> addCertificatePair ( $ private_key_file , $ public_key_file , $ type , $ password ) ; }
Add a Certificate Pair to the list of certificates searched by the component
57,084
public function authenticate ( ) { try { $ claims = $ this -> _infoCard -> process ( $ this -> getXmlToken ( ) ) ; } catch ( Exception $ e ) { return new Zend_Auth_Result ( Zend_Auth_Result :: FAILURE , null , array ( 'Exception Thrown' , $ e -> getMessage ( ) , $ e -> getTraceAsString ( ) , serialize ( $ e ) ) ) ; } if ( ! $ claims -> isValid ( ) ) { switch ( $ claims -> getCode ( ) ) { case Zend_infoCard_Claims :: RESULT_PROCESSING_FAILURE : return new Zend_Auth_Result ( Zend_Auth_Result :: FAILURE , $ claims , array ( 'Processing Failure' , $ claims -> getErrorMsg ( ) ) ) ; break ; case Zend_InfoCard_Claims :: RESULT_VALIDATION_FAILURE : return new Zend_Auth_Result ( Zend_Auth_Result :: FAILURE_CREDENTIAL_INVALID , $ claims , array ( 'Validation Failure' , $ claims -> getErrorMsg ( ) ) ) ; break ; default : return new Zend_Auth_Result ( Zend_Auth_Result :: FAILURE , $ claims , array ( 'Unknown Failure' , $ claims -> getErrorMsg ( ) ) ) ; break ; } } return new Zend_Auth_Result ( Zend_Auth_Result :: SUCCESS , $ claims ) ; }
Authenticates the XML token
57,085
public function updateAction ( ServerRequest $ request , Response $ response ) { $ script = $ GLOBALS [ 'TYPO3_CONF_VARS' ] [ 'EXT' ] [ 'extParams' ] [ 'tw_componentlibrary' ] [ 'script' ] ; $ descriptorspec = array ( 0 => array ( 'pipe' , 'r' ) , 1 => array ( 'pipe' , 'w' ) , 2 => array ( 'pipe' , 'a' ) ) ; $ process = proc_open ( $ script , $ descriptorspec , $ pipes ) ; stream_get_contents ( $ pipes [ 1 ] ) ; fclose ( $ pipes [ 1 ] ) ; $ status = proc_get_status ( $ process ) ; if ( $ status [ 'exitcode' ] ) { return $ response -> withStatus ( 500 ) ; } return $ response ; }
Update the fractal component library
57,086
public static function save ( $ filename , Zend_Server_Interface $ server ) { if ( ! is_string ( $ filename ) || ( ! file_exists ( $ filename ) && ! is_writable ( dirname ( $ filename ) ) ) ) { return false ; } $ methods = $ server -> getFunctions ( ) ; if ( $ methods instanceof Zend_Server_Definition ) { $ definition = new Zend_Server_Definition ( ) ; foreach ( $ methods as $ method ) { if ( in_array ( $ method -> getName ( ) , self :: $ _skipMethods ) ) { continue ; } $ definition -> addMethod ( $ method ) ; } $ methods = $ definition ; } if ( 0 === @ file_put_contents ( $ filename , serialize ( $ methods ) ) ) { return false ; } return true ; }
Cache a file containing the dispatch list .
57,087
public static function get ( $ filename , Zend_Server_Interface $ server ) { if ( ! is_string ( $ filename ) || ! file_exists ( $ filename ) || ! is_readable ( $ filename ) ) { return false ; } if ( false === ( $ dispatch = @ file_get_contents ( $ filename ) ) ) { return false ; } if ( false === ( $ dispatchArray = @ unserialize ( $ dispatch ) ) ) { return false ; } $ server -> loadFunctions ( $ dispatchArray ) ; return true ; }
Load server definition from a file
57,088
protected function onBeforeWrite ( ) { parent :: onBeforeWrite ( ) ; if ( $ this -> ID == 0 ) { $ this -> CreatorID = Member :: currentUserID ( ) ; } else { $ this -> LastEditorID = Member :: currentUserID ( ) ; if ( $ this -> isChanged ( 'LanguageID' ) ) { $ this -> FolderID = 0 ; } } }
Sets the creator id for new snippets and sets the last editor id for existing snippets
57,089
protected function onAfterWrite ( ) { parent :: onAfterWrite ( ) ; if ( ! empty ( $ this -> Text ) ) { $ version = new SnippetVersion ( ) ; $ version -> Text = $ this -> Text ; $ version -> ParentID = $ this -> ID ; $ version -> write ( ) ; } }
Creates the snippet version record after writing
57,090
public function equals ( self $ that ) : bool { if ( get_class ( $ this ) !== get_class ( $ that ) ) { throw new CannotCompareDifferentIds ; } return $ this -> id === $ that -> id ; }
compare two Id instances for equality
57,091
protected function onBeforeDelete ( ) { parent :: onBeforeDelete ( ) ; DB :: query ( 'UPDATE "Snippet" SET "FolderID"=' . $ this -> ParentID . ' WHERE "FolderID"=' . $ this -> ID ) ; DB :: query ( 'UPDATE "SnippetFolder" SET "ParentID"=' . $ this -> ParentID . ' WHERE "ParentID"=' . $ this -> ID ) ; }
Removes all snippets from the folder before deleting
57,092
public function negativeMatch ( string $ name , $ subject , array $ arguments ) : ? \ PhpSpec \ Wrapper \ DelayedCall { if ( $ subject -> equals ( $ arguments [ 0 ] ) ) { throw new FailureException ( '<label>' . get_class ( $ subject ) . "</label> <value>{$subject->toString()}</value> should not equal <value>{$arguments[0]->toString()}</value> but does." ) ; } }
Evaluates negative match .
57,093
public function setWebPath ( ) { $ folder_array = explode ( self :: DS , $ this -> getUploadPath ( ) ) ; $ this -> web_path = array_pop ( $ folder_array ) ; }
Set the correct web path
57,094
public function setDirPaths ( $ dir_path ) { if ( is_null ( $ dir_path ) ) { $ this -> setDir ( $ this -> getUploadPath ( ) ) ; $ this -> setDirPath ( "" ) ; } else { $ this -> setDirPath ( $ this -> DirTrim ( $ dir_path ) ) ; $ this -> setDir ( $ this -> getUploadPath ( ) . self :: DS . $ dir_path ) ; } $ path_valid = $ this -> checkPath ( $ this -> getDir ( ) ) ; if ( ! $ path_valid ) { $ this -> setDir ( $ this -> getUploadPath ( ) ) ; } }
Set the dir paths
57,095
public function checkPath ( $ path = null ) { if ( is_null ( $ path ) ) { $ path = $ this -> getDir ( ) ; } $ real_path = realpath ( $ path ) ; if ( ! $ real_path ) { $ real_path = realpath ( dirname ( $ path ) ) ; } $ upload_path = realpath ( $ this -> getUploadPath ( ) ) ; if ( strcasecmp ( $ real_path , $ upload_path ) > 0 ) { return true ; } else { throw new \ Exception ( "Directory is not in the upload path" , 403 ) ; } }
Check if the path is in the upload directory
57,096
public function resolveRequest ( Request $ request , $ action = null ) { $ this -> setDirPath ( $ request -> get ( 'dir_path' ) ) ; $ this -> setCurrentFile ( $ this -> getPath ( $ this -> getDirPath ( ) , $ request -> get ( 'filename' ) , true ) ) ; if ( $ action === self :: FILE_RENAME && ! $ this -> getCurrentFile ( ) -> isDir ( ) ) { $ extension = $ this -> getCurrentFile ( ) -> getExtension ( ) ; $ target_file = $ request -> get ( 'target_file' ) . "." . $ extension ; } elseif ( $ action === self :: FILE_PASTE ) { $ sources = $ this -> container -> get ( 'session' ) -> get ( 'copy' ) ; $ this -> setCurrentFile ( $ sources [ 'source_dir' ] . FileManager :: DS . $ sources [ 'source_file' ] ) ; $ target_file = $ request -> get ( 'target_file' ) . FileManager :: DS . $ sources [ 'source_file' ] ; } else { $ target_file = $ request -> get ( 'target_file' ) ; } if ( isset ( $ target_file ) ) { $ this -> setTargetFile ( $ target_file ) ; } }
Set the required request parameters to the object
57,097
public function getPath ( $ dir_path = null , $ filename = null , $ full_path = false ) { if ( $ full_path ) { $ path = $ this -> upload_path ; } else { $ path = $ this -> web_path ; } if ( ! is_null ( $ dir_path ) ) { $ path = self :: DS . $ this -> DirTrim ( $ path , $ dir_path ) ; } if ( ! is_null ( $ filename ) ) { $ path = self :: DS . $ this -> DirTrim ( $ path , $ filename ) ; } return $ path ; }
Get the path of the file
57,098
public function renameFile ( ) { $ this -> event ( YouweFileManagerEvents :: BEFORE_FILE_RENAMED ) ; $ target_full_path = $ this -> getTargetFile ( ) -> getFilepath ( true ) ; $ this -> getDriver ( ) -> renameFile ( $ this -> getCurrentFile ( ) , $ target_full_path ) ; $ this -> resolveImage ( ) ; $ this -> getCurrentFile ( ) -> updateFilepath ( $ target_full_path ) ; $ this -> event ( YouweFileManagerEvents :: AFTER_FILE_RENAMED ) ; }
Rename the file
57,099
public function throwError ( $ string , $ code = 500 , $ e = null ) { if ( ! $ this -> isFullException ( ) || is_null ( $ e ) ) { throw new \ Exception ( $ string , $ code ) ; } else { throw new \ Exception ( $ string . ": " . $ e -> getMessage ( ) , $ code ) ; } }
Throw the error based on the full exception config