idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
10,900
public function build ( array $ filters = [ ] ) { $ assets = [ ] ; foreach ( array_keys ( $ this -> _queued ) as $ alias ) { $ this -> _resolveDependencies ( $ this -> _collection -> get ( $ alias ) , $ assets ) ; } $ result = [ Asset :: TYPE_JS_FILE => [ ] , Asset :: TYPE_JS_CODE => [ ] , Asset :: TYPE_JSX_FILE => [ ] , Asset :: TYPE_JSX_CODE => [ ] , Asset :: TYPE_CSS_FILE => [ ] , Asset :: TYPE_CSS_CODE => [ ] , Asset :: TYPE_CALLBACK => [ ] , ] ; foreach ( $ assets as $ asset ) { $ source = $ asset -> load ( $ filters ) ; if ( Asset :: TYPE_COLLECTION === $ source [ 0 ] ) { $ source = $ source [ 1 ] ; } else { $ source = [ $ source ] ; } foreach ( $ source as $ sourceItem ) { $ type = $ sourceItem [ 0 ] ; $ src = $ sourceItem [ 1 ] ; if ( $ src && ! Arr :: in ( $ src , $ result [ $ type ] ) ) { $ result [ $ type ] [ ] = $ src ; } } } return $ result ; }
Build assets .
10,901
protected function _resolveDependencies ( Asset $ asset , & $ resolved = [ ] , & $ unresolved = [ ] ) { $ unresolved [ $ asset -> getAlias ( ) ] = $ asset ; foreach ( $ asset -> getDependencies ( ) as $ dependency ) { if ( ! Arr :: key ( $ dependency , $ resolved ) ) { if ( isset ( $ unresolved [ $ dependency ] ) ) { throw new Exception ( sprintf ( 'Circular asset dependency "%s > %s" detected.' , $ asset -> getAlias ( ) , $ dependency ) ) ; } if ( $ dep = $ this -> _collection -> get ( $ dependency ) ) { $ this -> _resolveDependencies ( $ dep , $ resolved , $ unresolved ) ; } else { throw new Exception ( "Undefined depends: $dependency" ) ; } } } $ resolved [ $ asset -> getAlias ( ) ] = $ asset ; unset ( $ unresolved [ $ asset -> getAlias ( ) ] ) ; return $ resolved ; }
Resolves asset dependencies .
10,902
public function init ( $ sourceId , $ resourceId , $ resource ) { $ this -> resourceId = $ resourceId ; $ this -> sourceId = $ sourceId ; if ( ! $ resource instanceof ZendMessage ) { throw new BadResourceConfigurationException ( sprintf ( 'Remote resource handler is expected to be an instance of \'\Zend\Mail\Storage\Message\', but got \'%s\'.' , get_class ( $ resource ) ) ) ; } $ this -> message = $ resource ; }
Initializes a Resource object
10,903
public function moveToOutputFolder ( $ outputFolder ) { try { if ( $ this -> message -> isMultipart ( ) ) { $ contentPart = $ this -> message -> getPart ( 1 ) ; $ content = $ contentPart -> getContent ( ) ; $ part = $ this -> message -> getPart ( 2 ) ; if ( $ part -> getHeaders ( ) -> has ( 'Content-Disposition' ) ) { $ fileName = $ part -> getHeaderField ( 'Content-Disposition' , 'filename' ) ; $ attachment = base64_decode ( $ part -> getContent ( ) ) ; $ attachmentFileName = $ this -> getAttachmentFileName ( $ fileName , $ outputFolder ) ; $ finalAttOutputDirectory = $ this -> getAttachmentFileFolder ( $ outputFolder ) ; if ( ! file_exists ( $ finalAttOutputDirectory ) ) { mkdir ( $ finalAttOutputDirectory , 0775 , true ) ; } file_put_contents ( $ attachmentFileName , $ attachment ) ; } } else { $ content = $ this -> message -> getContent ( ) ; } $ outputFileName = $ this -> getContentFileName ( $ outputFolder ) ; $ finalOutputDirectory = $ this -> getContentFileFolder ( $ outputFolder ) ; if ( ! file_exists ( $ finalOutputDirectory ) ) { mkdir ( $ finalOutputDirectory , 0775 , true ) ; } file_put_contents ( $ outputFileName , $ content ) ; } catch ( \ Exception $ e ) { throw new Exception \ ResourceMoveContentException ( sprintf ( 'Error while moving the content of resource \'%s\' to the output folder \'%s\'. Error message is: \'%s\'.' , $ this -> toString ( ) , $ outputFolder , $ e -> getMessage ( ) ) ) ; } return true ; }
Saves the current resource to the given path . Returns true if move action was successful ; false otherwise .
10,904
protected function getContentFileName ( $ outputFolder ) { return sprintf ( "%s%s%s_%s" , $ this -> getContentFileFolder ( $ outputFolder ) , DIRECTORY_SEPARATOR , $ this -> toString ( ) , time ( ) ) ; }
Returns the content file name as the concatenation of the given output folder + message sub folder + current object string representation + timestamp .
10,905
protected function getAttachmentFileName ( $ originalAttachmentFileName , $ baseOutputFolder ) { $ pathInfo = pathinfo ( $ originalAttachmentFileName ) ; $ extension = '' ; if ( isset ( $ pathInfo [ 'extension' ] ) ) { $ extension = $ pathInfo [ 'extension' ] ; } $ attachmentFileName = sprintf ( "%s%s%s_%s_%s.%s" , $ this -> getAttachmentFileFolder ( $ baseOutputFolder ) , DIRECTORY_SEPARATOR , $ pathInfo [ 'filename' ] , $ this -> toString ( ) , time ( ) , $ extension ) ; return rtrim ( $ attachmentFileName , '.' ) ; }
Returns the attachment file name as the concatenation of the given output folder + message sub folder + current object string representation + timestamp .
10,906
public function findFile ( $ class ) { if ( false === $ file = wincache_ucache_get ( $ this -> prefix . $ class ) ) { wincache_ucache_set ( $ this -> prefix . $ class , $ file = $ this -> decorated -> findFile ( $ class ) , 0 ) ; } return $ file ; }
Finds a file by class name while caching lookups to WinCache .
10,907
public function render ( ItemInterface $ item , array $ options = array ( ) ) { $ options = array_merge ( $ this -> defaultOptions , $ options ) ; $ options [ 'rootLevel' ] = $ item -> getLevel ( ) ; return $ this -> getMenu ( $ item , $ options ) ? : '' ; }
Renders menu tree .
10,908
public function setParentControl ( Control $ parentControl = null ) { $ this -> parentControl = $ parentControl ; $ this -> matcher -> setParentControl ( $ parentControl ) ; }
Sets the parent control - this is important for link generation
10,909
public function concat ( ) { $ args = func_get_args ( ) ; $ cols = ezcQuerySelect :: arrayFlatten ( $ args ) ; if ( count ( $ cols ) < 1 ) { throw new ezcQueryVariableParameterException ( 'concat' , count ( $ args ) , 1 ) ; } $ cols = $ this -> getIdentifiers ( $ cols ) ; return join ( ' + ' , $ cols ) ; }
Returns a series of strings concatinated
10,910
public function register ( ) { $ that = $ this ; set_error_handler ( function ( $ errno , $ errstr , $ errfile , $ errline ) use ( $ that ) { if ( ! ( $ errno & error_reporting ( ) ) ) { return ; } $ options = [ 'type' => $ errno , 'message' => $ errstr , 'file' => $ errfile , 'line' => $ errline , 'isError' => true , ] ; $ that -> handle ( new ErrorPayload ( $ options ) ) ; } ) ; set_exception_handler ( function ( $ e ) use ( $ that ) { $ options = [ 'type' => $ e -> getCode ( ) , 'message' => $ e -> getMessage ( ) , 'file' => $ e -> getFile ( ) , 'line' => $ e -> getLine ( ) , 'isException' => true , 'exception' => $ e , ] ; $ that -> handle ( new ErrorPayload ( $ options ) ) ; } ) ; register_shutdown_function ( function ( ) use ( $ that ) { if ( null !== ( $ options = error_get_last ( ) ) ) { $ that -> handle ( new ErrorPayload ( $ options ) ) ; } } ) ; }
Registers itself as error and exception handler .
10,911
public function mapErrorsToLogType ( $ code ) { switch ( $ code ) { case E_ERROR : case E_RECOVERABLE_ERROR : case E_CORE_ERROR : case E_COMPILE_ERROR : case E_USER_ERROR : case E_PARSE : return Logger :: ERROR ; case E_WARNING : case E_USER_WARNING : case E_CORE_WARNING : case E_COMPILE_WARNING : return Logger :: WARNING ; case E_NOTICE : case E_USER_NOTICE : return Logger :: NOTICE ; case E_STRICT : case E_DEPRECATED : case E_USER_DEPRECATED : return Logger :: INFO ; } return Logger :: ERROR ; }
Maps error code to a log type .
10,912
protected function fire ( Model $ model ) : array { $ recipient = $ this -> getRecipient ( ) ; if ( $ recipient -> phone === null ) { $ recipient -> phone = config ( 'antares/notifications::default.sms' ) ; } $ params = [ 'variables' => [ 'user' => $ recipient ] , 'recipients' => [ $ recipient ] ] ; return event ( $ model -> event , $ params ) ; }
Fires notification events
10,913
protected function getRecipient ( ) { if ( Input :: get ( 'test' ) ) { return user ( ) ; } $ route = app ( 'router' ) -> getRoutes ( ) -> match ( app ( 'request' ) -> create ( url ( ) -> previous ( ) ) ) ; return ( in_array ( 'users' , $ route -> parameterNames ( ) ) && $ uid = $ route -> parameter ( 'users' ) ) ? user ( ) -> newQuery ( ) -> findOrFail ( $ uid ) : user ( ) ; }
Gets recipient for notification
10,914
public static function emoticonsToHtml ( $ str ) { $ str = str_replace ( " :)" , ' <img src="/media/emot/icon_biggrin.gif" alt="big_grin" />' , $ str ) ; $ str = str_replace ( " :(" , ' <img src="/media/emot/icon_cry.gif" alt="cry" />' , $ str ) ; $ str = str_replace ( " ;)" , ' <img src="/media/emot/icon_wink.gif" alt="wink" />' , $ str ) ; $ str = str_replace ( " 8*" , ' <img src="/media/emot/icon_eek.gif" alt="eek" />' , $ str ) ; return $ str ; }
Converts emoticons shortcuts to images
10,915
public static function clean ( $ str , $ allow_email = false ) { $ str = self :: typoFix ( $ str ) ; $ str = \ sb \ String \ HTML :: escape ( $ str ) ; $ str = self :: convertQuotes ( $ str ) ; $ str = self :: listsToHtml ( $ str ) ; $ str = self :: tablesToHtml ( $ str ) ; $ str = self :: linksToHtml ( $ str , $ allow_email ) ; $ str = self :: colorizeInstantMessages ( $ str ) ; $ str = self :: textStyles ( $ str ) ; $ str = self :: parseCss ( $ str ) ; $ str = self :: addSearches ( $ str ) ; $ str = self :: miscTags ( $ str ) ; $ str = str_replace ( "\t" , "&nbsp;&nbsp;&nbsp;&nbsp;" , $ str ) ; return $ str ; }
Clean up the text according to the textBling rules
10,916
public static function miscTags ( $ str ) { $ str = str_replace ( '[hr]' , '<hr style="clear:both;" />' , $ str ) ; $ str = str_replace ( '[br]' , '<br />' , $ str ) ; $ str = preg_replace ( "~\[box\]\n?(.*?)\n?\[\/box\]\n{1,}?~is" , "<div class=\"box\">\\1</div>" , $ str ) ; return $ str ; }
Parses out misc tags such as horizontal rule and a scrolling box
10,917
public static function linksToHtml ( $ str , $ allow_email = false , $ link_markup = null ) { if ( ! $ allow_email ) { $ str = preg_replace ( "#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i" , '<b> \\2 AT \\3 </b>' , $ str ) ; } else { $ str = preg_replace ( "#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i" , ' <a href="mailto:\\2@\\3">\\2@\\3</a>' , $ str ) ; } $ str = preg_replace ( "~\[(?:url|link)=(http.*?)\](.*?)\[\/(?:url|link)\]~" , "<a class=\"blank\" href=\"\\1\">\\2</a>" , $ str ) ; $ link = $ link_markup ? $ link_markup : '(LINK)' ; $ str = preg_replace_callback ( "#(^|\s)([a-z]+?://[\w\-\.,\?!%\*\#:;~\\&$@\/=\+]+)#i" , function ( $ match ) use ( $ link ) { $ href = $ match [ 2 ] ; $ end_punct = '' ; if ( preg_match ( "~[\.\?\!]$~" , $ href , $ matchx ) ) { $ end_punct = $ matchx [ 0 ] ; $ href = substr ( $ href , 0 , - 1 ) ; } return $ match [ 1 ] . '<a href="' . $ href . '" title="' . $ href . '">' . $ link . '</a>' . $ end_punct ; } , $ str ) ; return $ str ; }
Converts email and http links to HTML links
10,918
public static function addSearches ( $ str ) { preg_match_all ( "/\[google\](.*?)\[\/google\]/s" , $ str , $ matches ) ; $ match = $ matches [ 0 ] ; $ data = $ matches [ 1 ] ; $ count = count ( $ match ) ; for ( $ x = 0 ; $ x < $ count ; $ x ++ ) { $ query = str_replace ( " " , "+" , $ data [ $ x ] ) ; $ query = str_replace ( '"' , "%22" , $ query ) ; $ str = str_replace ( $ match [ $ x ] , '<a class="blank" href="http://www.google.com/search?hl=en&amp;ie=UTF-8&amp;q=' . $ query . '" title="click to search google for ' . $ data [ $ x ] . '" >(GOOGLE - ' . $ data [ $ x ] . ')</a>' , $ str ) ; } $ str = preg_replace ( "~\[wikipedia\](.*?)\[\/wikipedia\]~s" , '<a class="blank" href="http://en.wikipedia.org/wiki/Special:Search?search=' . str_replace ( " " , "_" , "\\1" ) . '&amp;go=Go" title="click to search wikipedia for \\1" >(WIKIPEDIA - \\1)</a>' , $ str ) ; $ str = preg_replace ( "~\[wiktionary\](.*?)\[\/wiktionary\]~s" , '<a class="blank" href="http://en.wiktionary.org/wiki/Special:Search?search=' . str_replace ( " " , "_" , "\\1" ) . '&amp;go=Go" title="click to search wiktionary for \\1">(WIKTIONARY - \\1)</a>' , $ str ) ; return $ str ; }
Adds search tags to link text to searches both on and off site
10,919
public static function convertQuotes ( $ str ) { $ r = "/\[q(?:uote)?\](.*?)\[\/q(?:uote)?\]/is" ; while ( preg_match ( $ r , $ str ) ) { $ str = preg_replace ( $ r , '<blockquote class="quote"><p>\\1</p></blockquote>' , $ str ) ; } return $ str ; }
Converts quotes into quoted text blocks
10,920
public static function stripAll ( $ str ) { $ str = stripslashes ( $ str ) ; $ str = strip_tags ( $ str ) ; $ str = \ sb \ Strings :: unicodeUrldecode ( $ str ) ; $ str = self :: stripBling ( $ str ) ; $ str = \ sb \ Strings :: stripMicrosoftChars ( $ str ) ; return $ str ; }
Strips everything including textBlng tags this is useful for RSS feed and text summaries in search results
10,921
public static function typoFix ( $ str ) { $ common_typos = array ( "adn" => "and" , "agian" => "again" , "ahve" => "have" , "ahd" => "had" , "alot" => "a lot" , "amke" => "make" , "arent" => "aren't" , "beleif" => "belief" , "beleive" => "believe" , "broswer" => "browser" , "cant" => "can't" , "cheif" => "chief" , "couldnt" => "couldn't" , "comming" => "coming" , "didnt" => "didn't" , "doesnt" => "doesn't" , "dont" => "don't" , "ehr" => "her" , "esle" => "else" , "eyt" => "yet" , "feild" => "field" , "goign" => "going" , "hadnt" => "hadn't" , "hasnt" => "hasn't" , "hda" => "had" , "hed" => "he'd" , "hel" => "he'll" , "heres" => "here's" , "hes" => "he's" , "hows" => "how's" , "hsa" => "has" , "hte" => "the" , "htere" => "there" , "i'll" => "I'll" , "infromation" => "information" , "i'm" => "I'm" , "isnt" => "isn't" , "itll" => "it'll" , "itsa" => "its a" , "ive" => "I've" , "mkae" => "make" , "peice" => "piece" , "seh" => "she" , "shouldnt" => "shouldn't" , "shouldve" => "should've" , "shoudl" => "should" , "somethign" => "something" , "taht" => "that" , "tahn" => "than" , "Teh" => "The" , "teh" => "the" , "taht" => "that" , "thier" => "their" , "weve" => "we've" , "workign" => "working" ) ; foreach ( $ common_typos as $ typo => $ correction ) { $ str = preg_replace ( "~\b" . $ typo . "\b~" , $ correction , $ str ) ; } $ str = str_replace ( "n;t" , "n't" , $ str ) ; return $ str ; }
Fixed common typos can be used directly as it is a static property
10,922
public static function textStyles ( $ str ) { $ str = preg_replace ( "~\[b\](.*?)\[/b\]~is" , '<strong class="tb_b">$1</strong>' , $ str ) ; $ str = preg_replace ( "~\[sup\](.*?)\[/sup\]~is" , '<sup class="tb_sup">$1</sup>' , $ str ) ; $ str = preg_replace ( "~\[sub\](.*?)\[/sub\]~is" , '<sub class="tb_sub">$1</sub>' , $ str ) ; $ str = preg_replace ( "~\[i\](.*?)\[/i\]~is" , '<em class="tb_i">$1</em>' , $ str ) ; $ str = preg_replace ( "~\[u\](.*?)\[/u\]~is" , '<u class="tb_u">$1</u>' , $ str ) ; $ str = preg_replace ( "~\[cite\](.*?)\[/cite\]~is" , '<cite class="tb_cite">$1</cite>' , $ str ) ; $ str = preg_replace ( "~\[h(?:ilite)?\](.*?)\[/h(?:ilite)?\]~is" , '<span class="tb_hilite">$1</span>' , $ str ) ; $ str = preg_replace ( "~\[strike](.*?)\[/strike]~is" , '<del class="tb_strike">$1</del>' , $ str ) ; $ str = preg_replace ( "~\[caps](.*?)\[/caps]~is" , '<span class="tb_caps">$1</span>' , $ str ) ; $ str = preg_replace ( "~\[center](.*?)\[/center]~is" , '<center class="tb_center">$1</center>' , $ str ) ; $ str = preg_replace ( "~\[code](.*?)\[/code]~is" , '<pre style="background-color:black;color:green;overflow:auto;">$1</pre>' , $ str ) ; $ r = "~\[size=([\d(?:\.\d+)]+(?:em|px)?)\](.*?)\[\/size\]~is" ; while ( preg_match ( $ r , $ str ) ) { $ str = preg_replace ( $ r , '<span style="font-size:\\1;">\\2</span>' , $ str ) ; } $ r = "~\[size=(small|medium|large)\](.*?)\[\/size\]~is" ; while ( preg_match ( $ r , $ str ) ) { $ str = preg_replace ( $ r , '<span style="font-size:\\1;">\\2</span>' , $ str ) ; } $ r = "~\[color=(.*?)\](.*?)\[\/color\]~is" ; while ( preg_match ( $ r , $ str ) ) { $ str = preg_replace ( $ r , '<span style="color:\\1;">\\2</span>' , $ str ) ; } return $ str ; }
Converts text style tags
10,923
public function getCss ( ) { if ( isset ( $ this -> _themeConfig [ 'css' ] ) ) { return array_merge ( $ this -> _themeConfig [ 'css' ] , $ this -> _data [ 'css' ] ) ; } else { return $ this -> _data [ 'css' ] ; } }
Get array of css files to include in theme
10,924
public function getJs ( ) { if ( isset ( $ this -> _themeConfig [ 'js' ] ) ) { return array_merge ( $ this -> _themeConfig [ 'js' ] , $ this -> _data [ 'js' ] ) ; } else { return $ this -> _data [ 'js' ] ; } }
Get array of js files to include
10,925
public function addJs ( $ name , $ jsFile , $ order = 10 , $ active = 1 ) { $ this -> _data [ 'js' ] [ $ name ] = array ( 'file' => $ jsFile , 'order' => $ order , 'active' => $ active ) ; }
Add js file to page
10,926
public function getTemplateHtml ( $ partial ) { $ config = $ this -> getThemeConfig ( ) ; $ filename = $ this -> getTemplateFolder ( ) . $ config [ 'templates' ] [ $ partial ] [ 'file' ] ; $ html = $ this -> getTemplateFile ( $ filename , $ this -> getContextConfig ( ) ) ; return $ html ; }
Get template file populated by the config
10,927
public function toHtml ( ) { $ this -> getContextConfig ( ) ; $ this -> getThemeConfig ( ) ; $ filename = $ this -> getTemplateFolder ( ) . $ this -> getTemplate ( ) ; $ html = $ this -> getTemplateFile ( $ filename , $ this ) ; return $ html ; }
Output content to html
10,928
protected function processDir ( $ dir ) { $ dir = $ this -> replacePattern ( $ dir ) ; if ( Path :: isRelative ( $ dir ) ) { $ dir = Path :: makeAbsolute ( $ dir , dirname ( $ this -> configFile ) ) ; } return rtrim ( $ dir , '/' ) ; }
Process given dir with replacements and makes it absolute .
10,929
protected function replacePattern ( $ pattern ) { $ replace = array ( '$DIR' => dirname ( $ this -> configFile ) , '$CWD' => getcwd ( ) , ) ; return str_replace ( array_keys ( $ replace ) , array_values ( $ replace ) , $ pattern ) ; }
Helper to replace certain patterns with actual values .
10,930
public function hasEnabledUsername ( ) { if ( $ this -> usernameClass === false || ! is_string ( $ this -> usernameClass ) || ! class_exists ( $ this -> usernameClass ) ) { return false ; } return true ; }
Check whether this user enables the username feature or not .
10,931
public function getUsername ( ) { if ( ! $ this -> hasEnabledUsername ( ) ) { return null ; } $ usernameClass = $ this -> usernameClass ; $ noInit = $ usernameClass :: buildNoInitModel ( ) ; return $ this -> hasOne ( $ usernameClass , [ $ noInit -> createdByAttribute => $ this -> guidAttribute ] ) ; }
Get username . This method may return null please consider processing the abnormal conditions .
10,932
public function createUsername ( $ username ) { if ( ! $ this -> hasEnabledUsername ( ) ) { return null ; } $ usernameClass = $ this -> usernameClass ; $ model = $ usernameClass :: findOne ( $ this -> getGUID ( ) ) ; if ( ! $ model ) { $ model = $ this -> create ( $ usernameClass ) ; $ model -> setGUID ( $ this -> getGUID ( ) ) ; } $ model -> content = $ username ; return $ model ; }
Create or get username .
10,933
public function setUsername ( $ username = null ) { if ( $ username === null && ( $ model = $ this -> getUsername ( ) -> one ( ) ) ) { return $ model -> delete ( ) > 0 ; } if ( $ username instanceof Username ) { $ username = $ username -> content ; } $ model = $ this -> createUsername ( $ username ) ; return $ model -> save ( ) ; }
Set username .
10,934
public function profileShow ( ) { if ( ! $ this -> isAuthenticated ( ) ) { return $ this -> redirect ( '/login' ) ; } $ userModel = $ this -> session ( ) -> get ( 'user' ) ; return $ this -> twig ( ) -> render ( 'User\profile.twig' , array ( 'user' => $ userModel ) ) ; }
Shows the profile page .
10,935
public function loginShow ( ) { if ( $ this -> isAuthenticated ( ) ) { $ this -> setMessage ( 'warning' , 'you are already logged in' ) ; return $ this -> redirect ( '/' ) ; } return $ this -> twig ( ) -> render ( 'user\login.twig' ) ; }
Shows the login form .
10,936
public function loginAction ( $ request ) { $ data = $ request -> get ( 'data' ) ; $ userModel = new ModelUser ( ) ; $ validUser = $ userModel -> validateLogin ( $ data [ 'email' ] , $ data [ 'password' ] ) ; if ( ! $ validUser ) { $ this -> setMessage ( 'danger' , 'Not valid user / password combination' ) ; return $ this -> redirect ( url ( 'login' ) ) ; } $ this -> session ( ) -> set ( 'user' , $ userModel -> record ) ; $ this -> sessionClearMessages ( ) ; return $ this -> redirect ( '/' ) ; }
Handles the login action .
10,937
public function logoutAction ( ) { if ( $ this -> isAuthenticated ( ) ) { $ this -> session ( ) -> set ( 'user' , null ) ; } $ this -> setMessage ( 'success' , 'Bye Bye !' ) ; return $ this -> redirect ( '/' ) ; }
Handles the logout actions .
10,938
public function registerAction ( $ request ) { $ modelUser = new ModelUser ( ) ; $ data = $ request -> get ( 'data' ) ; $ error = false ; if ( $ this -> isAuthenticated ( ) ) { $ this -> setMessage ( 'error' , 'You are logged in' ) ; $ error = true ; } if ( ! filter_var ( $ data [ 'model' ] [ 'email' ] , FILTER_VALIDATE_EMAIL ) ) { $ this -> setMessage ( 'error' , 'That is not an Email' ) ; $ error = true ; } if ( $ modelUser -> findByName ( $ data [ 'model' ] [ 'username' ] ) ) { $ this -> setMessage ( 'error' , 'Your account exists' ) ; $ error = true ; } if ( $ modelUser -> findByEmail ( $ data [ 'model' ] [ 'email' ] ) ) { $ this -> setMessage ( 'error' , 'Your Email is already registered' ) ; $ error = true ; } if ( empty ( $ data [ 'model' ] [ 'password' ] ) ) { $ this -> setMessage ( 'error' , 'You need to select a password' ) ; $ error = true ; } if ( empty ( $ data [ 'model' ] [ 'email' ] ) ) { $ this -> setMessage ( 'error' , 'You need to select an email' ) ; $ error = true ; } if ( empty ( $ data [ 'model' ] [ 'username' ] ) ) { $ this -> setMessage ( 'error' , 'You need to select an User Name' ) ; $ error = true ; } if ( ! $ error ) { $ modelUser -> resetObject ( ) ; $ modelUser -> username = $ data [ 'model' ] [ 'username' ] ; $ modelUser -> password = md5 ( $ data [ 'model' ] [ 'password' ] ) ; $ modelUser -> email = $ data [ 'model' ] [ 'email' ] ; $ modelUser -> address = $ data [ 'model' ] [ 'address' ] ; $ modelUser -> phone = $ data [ 'model' ] [ 'phone' ] ; $ modelUser -> save ( ) ; return $ this -> twig ( ) -> render ( 'user\registerAction.twig' ) ; } else { return $ this -> twig ( ) -> render ( 'user\register.twig' , array ( 'data' => $ data ) ) ; } }
Shows register form .
10,939
public function recoverAction ( $ request ) { $ data = $ request -> get ( 'data' ) ; $ modelUser = new ModelUser ; if ( $ this -> isAuthenticated ( ) ) { $ this -> setMessage ( 'error' , 'Your are already authenticated.' ) ; return $ this -> redirect ( '/' ) ; } if ( ! filter_var ( $ data [ 'model' ] [ 'email' ] , FILTER_VALIDATE_EMAIL ) ) { $ this -> setMessage ( 'error' , 'Thats is not an email' ) ; return $ this -> redirect ( '/user/recover' ) ; } if ( ! $ modelUser -> findByEmail ( $ data [ 'model' ] [ 'email' ] ) ) { $ this -> setMessage ( 'error' , 'Your are not registered' ) ; return $ this -> redirect ( '/user/register' ) ; } $ password = $ modelUser -> regeneratePassword ( ) ; $ to = $ modelUser -> email ; $ subject = 'Password from Reader' ; $ message = 'Your new password is ' . $ password ; $ this -> sendMail ( $ to , $ subject , $ message ) ; return $ this -> twig ( ) -> render ( 'user\recoverAction.twig' ) ; }
Handles the recover action .
10,940
public function initializeClass ( ) { if ( ! isset ( $ this -> options [ 'services' ] ) || ! is_array ( $ this -> options [ 'services' ] ) ) { return ; } if ( $ this -> getPersistence ( ) && $ this -> getCache ( ) !== null && ( $ definition = $ this -> getCache ( ) -> getItem ( 'jrpc-definition' ) ) !== null && ( $ serviceMap = $ this -> getCache ( ) -> getItem ( 'jrpc-serviceMap' ) ) !== null ) { $ this -> table = $ definition ; $ this -> serviceMap = $ serviceMap ; return ; } foreach ( $ this -> options [ 'services' ] as $ c ) { $ this -> setClass ( $ c , ( ( isset ( $ c [ 'namespace' ] ) ) ? $ c [ 'namespace' ] : '' ) ) ; } if ( $ this -> getPersistence ( ) && $ this -> getCache ( ) !== null ) { $ this -> getCache ( ) -> setItem ( 'jrpc-definition' , $ this -> table ) ; $ this -> getCache ( ) -> setItem ( 'jrpc-serviceMap' , $ this -> serviceMap ) ; } }
Initialize all class .
10,941
public function getPersistence ( ) { if ( null === $ this -> persistence ) { $ this -> persistence = ( isset ( $ this -> options [ 'persistence' ] ) && $ this -> options [ 'persistence' ] == true ) ; } return $ this -> persistence ; }
Check persistance .
10,942
public function getCache ( ) { if ( null === $ this -> cache ) { if ( isset ( $ this -> options [ 'cache' ] ) && is_string ( $ this -> options [ 'cache' ] ) ) { $ this -> cache = $ this -> container -> get ( $ this -> options [ 'cache' ] ) ; } } return $ this -> cache ; }
Get Storage if define in config .
10,943
public function setEventManager ( \ Zend \ EventManager \ EventManagerInterface $ events ) { $ this -> events = $ events ; $ this -> events -> setIdentifiers ( [ __CLASS__ , get_called_class ( ) ] ) ; return $ this ; }
Inject an EventManager instance .
10,944
public function getCacheTag ( ) { return $ this -> cacheTagPrefix . ( $ this -> isAttributeChanged ( $ this -> idAttribute ) ? $ this -> getOldAttribute ( $ this -> idAttribute ) : $ this -> getID ( ) ) ; }
Get cache tag . The cache tag ends with the user ID but after the user ID is modified the old ID will prevail .
10,945
public static function fromEnv ( $ configFilename , Version $ version ) { if ( null === $ configFilename ) { $ configFilename = getenv ( 'ZFILE' ) ? getenv ( 'ZFILE' ) : 'z.yml' ; } return new self ( $ configFilename , new PathDefaultFileLocator ( 'ZPATH' , array ( getcwd ( ) , getenv ( 'HOME' ) . '/.config/z' ) ) , new FileLoader ( new PathDefaultFileLocator ( 'ZPLUGINPATH' , array ( ZPREFIX . '/vendor/zicht/z-plugins/' , getcwd ( ) ) ) , $ version ) ) ; }
Create the configuration loader based the current shell environment variables .
10,946
public function processConfiguration ( ) { Debug :: enterScope ( 'config' ) ; Debug :: enterScope ( 'load' ) ; try { $ zfiles = ( array ) $ this -> configLocator -> locate ( $ this -> configFilename , null , false ) ; } catch ( \ InvalidArgumentException $ e ) { $ zfiles = array ( ) ; } foreach ( $ zfiles as $ file ) { Debug :: enterScope ( $ file ) ; $ this -> sourceFiles [ ] = $ file ; $ this -> loader -> load ( $ file ) ; Debug :: exitScope ( $ file ) ; } foreach ( $ this -> loader -> getPlugins ( ) as $ name => $ file ) { Debug :: enterScope ( $ file ) ; $ this -> sourceFiles [ ] = $ file ; $ this -> loadPlugin ( $ name , $ file ) ; Debug :: exitScope ( $ file ) ; } Debug :: exitScope ( 'load' ) ; Debug :: enterScope ( 'process' ) ; $ processor = new Processor ( ) ; $ ret = $ processor -> processConfiguration ( new Configuration ( $ this -> plugins ) , $ this -> loader -> getConfigs ( ) ) ; Debug :: exitScope ( 'process' ) ; Debug :: exitScope ( 'config' ) ; return $ ret ; }
Processes the configuration contents
10,947
protected function loadPlugin ( $ name , $ file ) { require_once $ file ; $ className = sprintf ( 'Zicht\Tool\Plugin\%s\Plugin' , ucfirst ( basename ( $ name ) ) ) ; $ class = new \ ReflectionClass ( $ className ) ; if ( ! $ class -> implementsInterface ( 'Zicht\Tool\PluginInterface' ) ) { throw new \ UnexpectedValueException ( "The class $className is not a 'Zicht\\Tool\\PluginInterface'" ) ; } $ this -> plugins [ $ name ] = $ class -> newInstance ( ) ; }
Load the specified plugin instance .
10,948
public function getTemplateFile ( $ filename , $ data ) { $ data [ 'getRegion' ] = function ( $ name ) { return $ this -> getRegion ( $ name ) ; } ; return parent :: getTemplateFile ( $ filename , $ data ) ; }
Get template file
10,949
public function getRegion ( $ name ) { if ( array_key_exists ( $ name , $ this -> _regions ) ) { $ html = ( is_subclass_of ( $ this -> _regions [ $ name ] , 'erdiko\core\Container' ) ) ? $ this -> _regions [ $ name ] -> toHtml ( ) : $ this -> _regions [ $ name ] ; } else { throw new \ Exception ( "Template region '{$name}' does not exits." ) ; } return $ html ; }
get rendered region
10,950
public function getAddresses ( CoordinatesInterface $ coordinates ) : AddressCollection { $ url = $ this -> coordinatesQuery ( $ coordinates ) ; $ json = $ this -> fetchUrl ( $ url ) ; $ results = [ ] ; foreach ( $ json -> results as $ result ) { $ address = AddressBuild :: create ( $ result ) ; $ address -> setCoordinates ( $ coordinates ) ; $ results [ ] = $ address ; } return new AddressCollection ( $ results ) ; }
Get possible addresses using CoordinatesInterface
10,951
public function getCoordinatesByObject ( AddressInterface $ address ) : CoordinatesInterface { $ url = $ this -> addressQuery ( $ address -> getFormattedAddress ( ) ) ; $ json = $ this -> fetchUrl ( $ url ) ; $ coordinates = CoordinatesBuild :: create ( $ json -> results [ 0 ] ) ; return $ coordinates ; }
Get coordinates using AddressInterface
10,952
public function getCoordinatesByString ( string $ address ) : CoordinatesInterface { $ url = $ this -> addressQuery ( $ address ) ; $ json = $ this -> fetchUrl ( $ url ) ; $ coordinates = CoordinatesBuild :: create ( $ json -> results [ 0 ] ) ; return $ coordinates ; }
Get coordinates using string
10,953
private function coordinatesQuery ( CoordinatesInterface $ coordinates ) : string { $ url = sprintf ( self :: API_COORDINATES_URL_SSL , $ coordinates -> getLatitude ( ) , $ coordinates -> getLongitude ( ) ) ; $ url = $ this -> buildQuery ( $ url , $ this -> apiKey , $ this -> locale , $ this -> region ) ; return $ url ; }
Build coordinates query
10,954
private function addressQuery ( string $ formattedAddress ) : string { $ url = sprintf ( self :: API_ADDRESS_URL_SSL , rawurlencode ( $ formattedAddress ) ) ; $ url = $ this -> buildQuery ( $ url , $ this -> apiKey , $ this -> locale , $ this -> region ) ; return $ url ; }
Build address query
10,955
private function buildQuery ( string $ url , string $ apiKey , string $ locale = null , string $ region = null ) : string { if ( null !== $ apiKey ) { $ url = sprintf ( '%s&key=%s' , $ url , $ apiKey ) ; } if ( null !== $ locale ) { $ url = sprintf ( '%s&language=%s' , $ url , $ locale ) ; } if ( null !== $ region ) { $ url = sprintf ( '%s&region=%s' , $ url , $ region ) ; } return $ url ; }
build query with extra params
10,956
public function validate ( $ model , $ validators = null ) { if ( isset ( $ validators ) && is_array ( $ validators ) ) { $ validation = $ this -> validateArray ( $ model , $ validators ) ; } else { $ validation = $ this -> validateModel ( $ model ) ; } if ( $ validation ) { $ errors = $ validation -> validate ( $ model ) ; if ( count ( $ errors ) ) { throw new ValidationException ( $ errors ) ; } } }
Validate model object
10,957
public function createForm ( $ model , $ formClass = null ) { if ( is_string ( $ model ) ) { return $ this -> createFormInternal ( $ model , new $ model , $ formClass ) ; } else { return $ this -> createFormInternal ( get_class ( $ model ) , $ model , $ formClass ) ; } }
Create form object
10,958
private function getLabels ( $ annotations ) { $ it = $ this -> getAnnotations ( ) -> filter ( $ annotations ) -> is ( Label :: class ) -> onProperties ( ) ; $ labels = [ ] ; foreach ( $ it as $ annotation ) { $ labels [ $ annotation -> getPropertyName ( ) ] = $ annotation -> value ; } return $ labels ; }
Gets property labels
10,959
private function getValidators ( $ annotations , $ class ) { $ validators = [ ] ; $ it = $ this -> getAnnotations ( ) -> filter ( $ annotations ) -> is ( ValidatorInterface :: class ) -> onProperties ( ) ; foreach ( $ it as $ annotation ) { $ property = $ annotation -> getPropertyName ( ) ; if ( ! isset ( $ validators [ $ property ] ) ) { $ validators [ $ property ] = [ 'required' => false , 'validators' => [ ] , ] ; } $ validators [ $ property ] [ 'validators' ] [ ] = $ annotation -> getValidator ( $ this ) ; if ( $ annotation instanceof Required ) { $ validators [ $ property ] [ 'required' ] = true ; } } return $ validators ; }
Gets all validators
10,960
private function getElements ( $ annotations , $ formClass ) { $ labels = $ this -> getLabels ( $ annotations ) ; $ reflection = new \ ReflectionClass ( $ formClass ) ; $ defaultValues = $ reflection -> getDefaultProperties ( ) ; $ elements = [ ] ; $ it = $ this -> getAnnotations ( ) -> filter ( $ annotations ) -> is ( InputInterface :: class ) -> onProperties ( ) ; foreach ( $ it as $ annotation ) { $ property = $ annotation -> getPropertyName ( ) ; if ( ! isset ( $ annotation -> name ) ) { $ annotation -> name = $ property ; } $ elem = $ annotation -> getElement ( $ this ) ; if ( $ annotation -> label ) { $ label = $ annotation -> label ; } elseif ( isset ( $ labels [ $ property ] ) ) { $ label = $ labels [ $ property ] ; } else { $ label = str_replace ( '_' , ' ' , ucfirst ( $ property ) ) ; } $ elem -> setLabel ( $ label ) ; if ( isset ( $ defaultValues [ $ property ] ) ) { $ elem -> setDefault ( $ defaultValues [ $ property ] ) ; } $ elements [ $ property ] = $ elem ; } return $ elements ; }
Gets all form elements
10,961
public function getSingle ( $ key , $ forClientId = null ) { $ params = array ( 'key' => $ key ) ; if ( $ forClientId ) { $ params [ 'for_client_id' ] = $ forClientId ; } return $ this -> post ( 'settings/get' , $ params ) ; }
Get the value associated with a key for a particular client_id . If the key has not value for that client then return the key s default value for the application or if they key has not default value then return null .
10,962
public function items ( $ forClientId = null ) { $ params = array ( ) ; if ( $ forClientId ) { $ params [ 'for_client_id' ] = $ forClientId ; } return $ this -> post ( 'settings/items' , $ params ) ; }
Get all settings for a particular client including those from the application - wide default settings . If a key is defined in both the client and application settings only the client - specific value is returned .
10,963
public function keys ( $ forClientId = null ) { $ params = array ( ) ; if ( $ forClientId ) { $ params [ 'for_client_id' ] = $ forClientId ; } return $ this -> post ( 'settings/keys' , $ params ) ; }
Get all keys for a particular client including those from the application - wide default settings . Returns an array of the keys .
10,964
public function set ( $ key , $ value , $ forClientId = null ) { $ params = array ( 'key' => $ key , 'value' => $ value ) ; if ( is_array ( $ value ) ) { $ params [ 'value' ] = json_encode ( $ value ) ; } if ( $ forClientId ) { $ params [ 'for_client_id' ] = $ forClientId ; } return $ this -> post ( 'settings/set' , $ params ) ; }
Assign a key - value pair for a particular client_id . If the key does not exist it will be created . If they key already exists this call overwrites the existing value .
10,965
public function setMulti ( array $ items , $ forClientId = null ) { $ params = array ( 'items' => json_encode ( $ items ) ) ; if ( $ forClientId ) { $ params [ 'for_client_id' ] = $ forClientId ; } return $ this -> post ( 'settings/set_multi' , $ params ) ; }
Assign multiple settings for a particular client_id . Returns a JSON object in which each key is mapped to a boolean that indicates whether the key already existed . True indicates that a previous key did exist and has been overwritten . False indicates that there were no previous key and a new key has been created . Does not modify application - wide settings .
10,966
public function setDefault ( $ key , $ value ) { $ params = array ( 'key' => $ key , 'value' => $ value ) ; if ( is_array ( $ value ) ) { $ params [ 'value' ] = json_encode ( $ value ) ; } return $ this -> post ( 'settings/set_default' , $ params ) ; }
Set the application - wide default value for a key . This will create a new key with a default value if the key does not yet exist in the application . If the key does exist the value will be overwritten .
10,967
public function delete ( $ key , $ forClientId = null ) { $ params = array ( 'key' => $ key ) ; if ( $ forClientId ) { $ params [ 'for_client_id' ] = $ forClientId ; } return $ this -> post ( 'settings/delete' , $ params ) ; }
Delete a key from the settings for a particular client . Returns a boolean indicating whether the key existed . This does not modify the application - wide default value for a key .
10,968
public function setOptions ( $ options ) { if ( is_array ( $ options ) ) { $ this -> options -> merge ( $ options ) ; } else if ( $ options instanceof ezcTranslationTsBackendOptions ) { $ this -> options = $ options ; } else { throw new ezcBaseValueException ( "options" , $ options , "instance of ezcTranslationTsBackendOptions" ) ; } }
Set new options . This method allows you to change the options of the translation backend .
10,969
public function deinitWriter ( ) { if ( is_null ( $ this -> dom ) ) { throw new ezcTranslationWriterNotInitializedException ( ) ; } $ filename = $ this -> buildTranslationFileName ( $ this -> writeLocale ) ; $ this -> dom -> save ( $ filename ) ; }
Deinitializes the writer
10,970
public function next ( ) { if ( is_null ( $ this -> xmlParser ) ) { throw new ezcTranslationReaderNotInitializedException ( ) ; } $ valid = $ this -> xmlParser -> valid ( ) ; if ( $ valid ) { $ newContext = array ( trim ( $ this -> xmlParser -> getChildren ( ) -> name ) , array ( ) ) ; foreach ( $ this -> xmlParser -> getChildren ( ) -> message as $ data ) { $ translationItem = $ this -> parseSimpleXMLMessage ( $ data ) ; if ( ! is_null ( $ translationItem ) ) { $ newContext [ 1 ] [ ] = $ translationItem ; } } $ this -> currentContext = $ newContext ; $ this -> xmlParser -> next ( ) ; } else { $ this -> currentContext = null ; } }
Advanced to the next context .
10,971
public function create ( $ basePath ) { $ parts = explode ( '.' , $ this -> loadVersion ( $ basePath ) -> getShortVersion ( ) ) ; while ( ! empty ( $ parts ) ) { $ version = implode ( 'Dot' , $ parts ) ; $ classname = __NAMESPACE__ . '\\Joomla' . $ version . 'Driver' ; if ( class_exists ( $ classname ) ) { return new $ classname ; } array_pop ( $ parts ) ; } throw new \ RuntimeException ( 'No driver found' ) ; }
Create a version specific driver to Joomla
10,972
private function loadVersion ( $ basePath ) { static $ locations = array ( '/libraries/cms/version/version.php' , '/libraries/joomla/version.php' , ) ; define ( '_JEXEC' , 1 ) ; foreach ( $ locations as $ location ) { if ( file_exists ( $ basePath . $ location ) ) { $ code = file_get_contents ( $ basePath . $ location ) ; $ code = str_replace ( "defined('JPATH_BASE')" , "defined('_JEXEC')" , $ code ) ; eval ( '?>' . $ code ) ; return new \ JVersion ; } } throw new \ RuntimeException ( 'Unable to locate version information' ) ; }
Load the Joomla version
10,973
public function getSiblings ( $ active = '1' ) { $ stage = \ Nblum \ FlexibleContent \ FlexibleContentVersionedDataObject :: get_live_stage ( ) ; $ results = \ Nblum \ FlexibleContent \ FlexibleContentVersionedDataObject :: get_by_stage ( \ ContentElement :: class , $ stage , [ 'Active' => $ active ] , [ 'Sort' => 'ASC' ] ) ; return $ results ; }
returns all content element of the same page
10,974
protected function bindInstancesInContainer ( ) { $ this -> app -> instance ( "view-control.path" , $ this -> path ( ) ) ; $ this -> app -> instance ( "view-control.path.base" , $ this -> basePath ( ) ) ; }
Bind all of the instances in the container .
10,975
public function basePath ( $ path = '' ) { return $ this -> getFilesystem ( ) -> dirname ( $ this -> path ( ) ) . ( $ path ? DIRECTORY_SEPARATOR . $ path : $ path ) ; }
Get the base path of the plugin installation .
10,976
public static function countMaxDepth ( array $ array ) { $ maxDepth = 1 ; foreach ( $ array as $ element ) { $ depth = 1 ; if ( is_array ( $ element ) ) { $ depth += self :: countMaxDepth ( $ element ) ; } if ( $ depth > $ maxDepth ) $ maxDepth = $ depth ; } return $ maxDepth ; }
Counts maximum array depth recursively
10,977
public static function countMaxDepthIterative ( array $ array ) { $ copy = $ array ; $ maxDepth = 1 ; foreach ( $ copy as $ element ) { $ depth = 1 ; while ( ! empty ( $ element ) ) { if ( is_array ( $ element ) ) { ++ $ depth ; $ tmp = array_shift ( $ element ) ; if ( is_array ( $ tmp ) ) { array_push ( $ element , array_shift ( $ tmp ) ) ; } } else { break ; } } if ( $ depth > $ maxDepth ) { $ maxDepth = $ depth ; } } return $ maxDepth ; }
Counts maximum array depth iteratively
10,978
public static function countMinDepth ( $ potentialArray , $ depth = 0 ) { if ( ! self :: isLogicallyCastableToInt ( $ depth ) ) { throw new InvalidArgumentException ( 'Depth parameter must be non-negative integer' ) ; } if ( $ depth < 0 ) { throw new InvalidArgumentException ( 'Depth parameter must be non-negative integer' ) ; } $ return = $ depth ; if ( is_array ( $ potentialArray ) ) { $ return ++ ; $ childrenDepths = array ( ) ; foreach ( $ potentialArray as $ element ) { $ childrenDepths [ ] = self :: countMinDepth ( $ element , $ return ) ; } $ return = empty ( $ childrenDepths ) ? $ return : min ( $ childrenDepths ) ; } return $ return ; }
Counts maximum array depth
10,979
public function getParent ( ) { $ depth = $ this -> iterator -> getDepth ( ) ; return $ depth === 0 ? $ this -> id : $ this -> iterator -> getSubIterator ( $ depth - 1 ) -> key ( ) ; }
Return the parent element
10,980
public function loadProviderFiles ( ) { $ lastWeek = time ( ) - ( 7 * 24 * 60 * 60 ) ; if ( false === $ this -> allowUrlOpen ) { $ this -> logMessage ( 'ProviderCommunication::loadProviderFiles allowUrlOpen = false!' , 'botdetection_debug' ) ; return false ; } foreach ( $ this -> referrerProvider as $ source => $ url ) { if ( false === file_exists ( $ this -> cachePath . '/' . strtolower ( $ source ) . '.txt' ) || $ lastWeek > filemtime ( $ this -> cachePath . '/' . strtolower ( $ source ) . '.txt' ) ) { $ fileProvider = fopen ( $ this -> cachePath . '/' . strtolower ( $ source ) . '.txt' , 'wb+' ) ; fwrite ( $ fileProvider , file_get_contents ( $ url ) ) ; fclose ( $ fileProvider ) ; } } return true ; }
Load Referrer Provider Files if - provider files to old
10,981
private function parse ( \ SimpleXMLElement $ xmldata ) { if ( ! isset ( $ xmldata -> title ) ) { throw new OpdsParserNoTitleException ( ) ; } if ( $ xmldata -> getName ( ) === 'entry' ) { return $ this -> parseEntry ( $ xmldata ) ; } return $ this -> parseFeed ( $ xmldata ) ; }
Parse an OPDS flux .
10,982
private function parsePagination ( \ SimpleXMLElement $ xmldata ) { $ pagination = new Pagination ( ) ; $ paginated = false ; foreach ( $ xmldata -> children ( 'opensearch' , true ) as $ key => $ value ) { switch ( $ key ) { case 'totalResults' : $ pagination -> setNumberOfItem ( ( int ) $ value ) ; $ paginated = true ; break ; case 'itemsPerPage' : $ pagination -> setItemsPerPage ( ( int ) $ value ) ; $ paginated = true ; break ; } } return $ paginated ? $ pagination : null ; }
Met en forme la pagination si elle existe
10,983
protected function _writeFile ( $ destination , $ data ) { $ destination = trim ( $ destination ) ; if ( false === file_put_contents ( $ destination , $ data ) ) { throw new Mage_Exception ( "Can't write to file: " . $ destination ) ; } return true ; }
Write data to file . If file can t be opened - throw exception
10,984
protected function _readFile ( $ source ) { $ data = '' ; if ( is_file ( $ source ) && is_readable ( $ source ) ) { $ data = @ file_get_contents ( $ source ) ; if ( $ data === false ) { throw new Mage_Exception ( "Can't get contents from: " . $ source ) ; } } return $ data ; }
Read data from file . If file can t be opened throw to exception .
10,985
protected function _initWriter ( ) { $ this -> _writer = new Mage_Archive_Helper_File ( $ this -> _destinationFilePath ) ; $ this -> _writer -> open ( 'w' ) ; return $ this ; }
Initialize tarball writer
10,986
protected function _destroyWriter ( ) { if ( $ this -> _writer instanceof Mage_Archive_Helper_File ) { $ this -> _writer -> close ( ) ; $ this -> _writer = null ; } return $ this ; }
Destroy tarball writer
10,987
protected function _initReader ( ) { $ this -> _reader = new Mage_Archive_Helper_File ( $ this -> _getCurrentFile ( ) ) ; $ this -> _reader -> open ( 'r' ) ; return $ this ; }
Initialize tarball reader
10,988
protected function _destroyReader ( ) { if ( $ this -> _reader instanceof Mage_Archive_Helper_File ) { $ this -> _reader -> close ( ) ; $ this -> _reader = null ; } return $ this ; }
Destroy tarball reader
10,989
protected function _setCurrentFile ( $ file ) { $ this -> _currentFile = $ file . ( ( ! is_link ( $ file ) && is_dir ( $ file ) && substr ( $ file , - 1 ) != DS ) ? DS : '' ) ; return $ this ; }
Set file which is packing .
10,990
protected function _setCurrentPath ( $ path ) { if ( $ this -> _skipRoot && is_dir ( $ path ) ) { $ this -> _currentPath = $ path . ( substr ( $ path , - 1 ) != DS ? DS : '' ) ; } else { $ this -> _currentPath = dirname ( $ path ) . DS ; } return $ this ; }
Set path to file which is packing .
10,991
protected function _packToTar ( $ skipRoot = false ) { $ file = $ this -> _getCurrentFile ( ) ; $ header = '' ; $ data = '' ; if ( ! $ skipRoot ) { $ header = $ this -> _composeHeader ( ) ; $ data = $ this -> _readFile ( $ file ) ; $ data = str_pad ( $ data , floor ( ( ( is_dir ( $ file ) ? 0 : filesize ( $ file ) ) + 512 - 1 ) / 512 ) * 512 , "\0" ) ; } $ sub = '' ; if ( is_dir ( $ file ) ) { $ treeDir = scandir ( $ file ) ; if ( empty ( $ treeDir ) ) { throw new Mage_Exception ( 'Can\'t scan dir: ' . $ file ) ; } array_shift ( $ treeDir ) ; array_shift ( $ treeDir ) ; foreach ( $ treeDir as $ item ) { $ sub .= $ this -> _setCurrentFile ( $ file . $ item ) -> _packToTar ( false ) ; } } $ tarData = $ header . $ data . $ sub ; $ tarData = str_pad ( $ tarData , floor ( ( strlen ( $ tarData ) - 1 ) / 1536 ) * 1536 , "\0" ) ; return $ tarData ; }
Walk through directory and add to tar file or directory . Result is packed string on TAR format .
10,992
protected function _createTar ( $ skipRoot = false , $ finalize = false ) { if ( ! $ skipRoot ) { $ this -> _packAndWriteCurrentFile ( ) ; } $ file = $ this -> _getCurrentFile ( ) ; if ( is_dir ( $ file ) ) { $ dirFiles = scandir ( $ file ) ; if ( false === $ dirFiles ) { throw new Mage_Exception ( 'Can\'t scan dir: ' . $ file ) ; } array_shift ( $ dirFiles ) ; array_shift ( $ dirFiles ) ; foreach ( $ dirFiles as $ item ) { $ this -> _setCurrentFile ( $ file . $ item ) -> _createTar ( ) ; } } if ( $ finalize ) { $ this -> _getWriter ( ) -> write ( str_repeat ( "\0" , self :: TAR_BLOCK_SIZE * 12 ) ) ; } }
Recursively walk through file tree and create tarball
10,993
protected function _packAndWriteCurrentFile ( ) { $ archiveWriter = $ this -> _getWriter ( ) ; $ archiveWriter -> write ( $ this -> _composeHeader ( ) ) ; $ currentFile = $ this -> _getCurrentFile ( ) ; $ fileSize = 0 ; if ( is_file ( $ currentFile ) && ! is_link ( $ currentFile ) ) { $ fileReader = new Mage_Archive_Helper_File ( $ currentFile ) ; $ fileReader -> open ( 'r' ) ; while ( ! $ fileReader -> eof ( ) ) { $ archiveWriter -> write ( $ fileReader -> read ( ) ) ; } $ fileReader -> close ( ) ; $ fileSize = filesize ( $ currentFile ) ; } $ appendZerosCount = ( self :: TAR_BLOCK_SIZE - $ fileSize % self :: TAR_BLOCK_SIZE ) % self :: TAR_BLOCK_SIZE ; $ archiveWriter -> write ( str_repeat ( "\0" , $ appendZerosCount ) ) ; }
Write current file to tarball
10,994
protected function _unpackCurrentTar ( $ destination ) { $ archiveReader = $ this -> _getReader ( ) ; $ list = array ( ) ; while ( ! $ archiveReader -> eof ( ) ) { $ header = $ this -> _extractFileHeader ( ) ; if ( ! $ header ) { continue ; } $ currentFile = $ destination . $ header [ 'name' ] ; $ dirname = dirname ( $ currentFile ) ; if ( in_array ( $ header [ 'type' ] , array ( "0" , chr ( 0 ) , '' ) ) ) { if ( ! file_exists ( $ dirname ) ) { $ mkdirResult = @ mkdir ( $ dirname , 0777 , true ) ; if ( false === $ mkdirResult ) { throw new Mage_Exception ( 'Failed to create directory ' . $ dirname ) ; } } $ this -> _extractAndWriteFile ( $ header , $ currentFile ) ; $ list [ ] = $ currentFile ; } elseif ( $ header [ 'type' ] == '5' ) { if ( ! file_exists ( $ dirname ) ) { $ mkdirResult = @ mkdir ( $ currentFile , $ header [ 'mode' ] , true ) ; if ( false === $ mkdirResult ) { throw new Mage_Exception ( 'Failed to create directory ' . $ currentFile ) ; } } $ list [ ] = $ currentFile . DS ; } elseif ( $ header [ 'type' ] == '2' ) { @ symlink ( $ header [ 'symlink' ] , $ currentFile ) ; } } return $ list ; }
Read TAR string from file and unpacked it . Create files and directories information about discribed in the string .
10,995
protected function _parseHeader ( & $ pointer ) { $ firstLine = fread ( $ pointer , 512 ) ; if ( strlen ( $ firstLine ) < 512 ) { return false ; } $ fmt = self :: _getFormatParseHeader ( ) ; $ header = unpack ( $ fmt , $ firstLine ) ; $ header [ 'mode' ] = $ header [ 'mode' ] + 0 ; $ header [ 'uid' ] = octdec ( $ header [ 'uid' ] ) ; $ header [ 'gid' ] = octdec ( $ header [ 'gid' ] ) ; $ header [ 'size' ] = octdec ( $ header [ 'size' ] ) ; $ header [ 'mtime' ] = octdec ( $ header [ 'mtime' ] ) ; $ header [ 'checksum' ] = octdec ( $ header [ 'checksum' ] ) ; if ( $ header [ 'type' ] == "5" ) { $ header [ 'size' ] = 0 ; } $ checksum = 0 ; $ firstLine = substr_replace ( $ firstLine , ' ' , 148 , 8 ) ; for ( $ i = 0 ; $ i < 512 ; $ i ++ ) { $ checksum += ord ( substr ( $ firstLine , $ i , 1 ) ) ; } $ isUstar = 'ustar' == strtolower ( substr ( $ header [ 'magic' ] , 0 , 5 ) ) ; $ checksumOk = $ header [ 'checksum' ] == $ checksum ; if ( isset ( $ header [ 'name' ] ) && $ checksumOk ) { if ( $ header [ 'name' ] == '././@LongLink' && $ header [ 'type' ] == 'L' ) { $ realName = substr ( fread ( $ pointer , floor ( ( $ header [ 'size' ] + 512 - 1 ) / 512 ) * 512 ) , 0 , $ header [ 'size' ] ) ; $ headerMain = $ this -> _parseHeader ( $ pointer ) ; $ headerMain [ 'name' ] = $ realName ; return $ headerMain ; } else { if ( $ header [ 'size' ] > 0 ) { $ header [ 'data' ] = substr ( fread ( $ pointer , floor ( ( $ header [ 'size' ] + 512 - 1 ) / 512 ) * 512 ) , 0 , $ header [ 'size' ] ) ; } else { $ header [ 'data' ] = '' ; } return $ header ; } } return false ; }
Get header from TAR string and unpacked it by format .
10,996
protected function _extractFileHeader ( ) { $ archiveReader = $ this -> _getReader ( ) ; $ headerBlock = $ archiveReader -> read ( self :: TAR_BLOCK_SIZE ) ; if ( strlen ( $ headerBlock ) < self :: TAR_BLOCK_SIZE ) { return false ; } $ header = unpack ( self :: _getFormatParseHeader ( ) , $ headerBlock ) ; $ header [ 'mode' ] = octdec ( $ header [ 'mode' ] ) ; $ header [ 'uid' ] = octdec ( $ header [ 'uid' ] ) ; $ header [ 'gid' ] = octdec ( $ header [ 'gid' ] ) ; $ header [ 'size' ] = octdec ( $ header [ 'size' ] ) ; $ header [ 'mtime' ] = octdec ( $ header [ 'mtime' ] ) ; $ header [ 'checksum' ] = octdec ( $ header [ 'checksum' ] ) ; if ( $ header [ 'type' ] == "5" ) { $ header [ 'size' ] = 0 ; } $ checksum = 0 ; $ headerBlock = substr_replace ( $ headerBlock , ' ' , 148 , 8 ) ; for ( $ i = 0 ; $ i < 512 ; $ i ++ ) { $ checksum += ord ( substr ( $ headerBlock , $ i , 1 ) ) ; } $ checksumOk = $ header [ 'checksum' ] == $ checksum ; if ( isset ( $ header [ 'name' ] ) && $ checksumOk ) { if ( ! ( $ header [ 'name' ] == '././@LongLink' && $ header [ 'type' ] == 'L' ) ) { $ header [ 'name' ] = trim ( $ header [ 'name' ] ) ; return $ header ; } $ realNameBlockSize = floor ( ( $ header [ 'size' ] + self :: TAR_BLOCK_SIZE - 1 ) / self :: TAR_BLOCK_SIZE ) * self :: TAR_BLOCK_SIZE ; $ realNameBlock = $ archiveReader -> read ( $ realNameBlockSize ) ; $ realName = substr ( $ realNameBlock , 0 , $ header [ 'size' ] ) ; $ headerMain = $ this -> _extractFileHeader ( ) ; $ headerMain [ 'name' ] = trim ( $ realName ) ; return $ headerMain ; } return false ; }
Read and decode file header information from tarball
10,997
public function grep ( array $ subjects , int $ flags = 0 ) : array { $ result = preg_grep ( $ this -> pattern -> getPattern ( ) . $ this -> modifier , $ subjects , $ flags ) ; if ( ( $ errno = preg_last_error ( ) ) !== PREG_NO_ERROR ) { $ message = array_flip ( get_defined_constants ( true ) [ 'pcre' ] ) [ $ errno ] ; switch ( $ errno ) { case PREG_INTERNAL_ERROR : throw new InternalException ( "{$message} using pattern: {$this->pattern->getPattern()}" , $ errno ) ; case PREG_BACKTRACK_LIMIT_ERROR : throw new BacktrackLimitException ( "{$message} using pattern: {$this->pattern->getPattern()}" , $ errno ) ; case PREG_RECURSION_LIMIT_ERROR : throw new RecursionLimitException ( "{$message} using pattern: {$this->pattern->getPattern()}" , $ errno ) ; case PREG_BAD_UTF8_ERROR : throw new BadUtf8Exception ( "{$message} using pattern: {$this->pattern->getPattern()}" , $ errno ) ; case PREG_BAD_UTF8_OFFSET_ERROR : throw new BadUtf8OffsetException ( "{$message} using pattern: {$this->pattern->getPattern()}" , $ errno ) ; case PREG_JIT_STACKLIMIT_ERROR : throw new JitStackLimitException ( "{$message} using pattern: {$this->pattern->getPattern()}" , $ errno ) ; } } return $ result ; }
Retrieve grepped subjects array
10,998
protected function executeSchemaCommand ( InputInterface $ input , OutputInterface $ output , SchemaTool $ schemaTool , array $ metadata , SymfonyStyle $ ui ) { $ merger = new MetadataMerger ( ) ; $ metadata = $ merger -> merge ( $ metadata ) ; return parent :: executeSchemaCommand ( $ input , $ output , $ schemaTool , $ metadata , $ ui ) ; }
Executes the Drop command .
10,999
public function jQuery ( string $ sSelector , string $ sContext = '' ) { return $ this -> getResponse ( ) -> plugin ( 'jquery' ) -> element ( $ sSelector , $ sContext ) ; }
Create a JQuery Element with a given selector and link it to the response attribute .