idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
60,200
public function addPlaceholder ( $ name , $ value = null , $ recursive = false ) { list ( $ name , , $ template ) = $ this -> getParentPlaceholder ( $ name ) ; if ( ! isset ( $ template ) ) { $ template = $ this ; } if ( $ template === false ) { if ( $ this -> throwException ) { throw new TemplateException ( "Unknown scope: {$name}" ) ; } return ; } $ template -> placeholders [ $ name ] = isset ( $ template -> placeholders [ $ name ] ) && is_array ( $ template -> placeholders [ $ name ] ) ? $ this -> _merge ( $ template -> placeholders [ $ name ] , ( array ) $ value , $ recursive ) : $ value ; }
Adding placeholder .
60,201
public function addMultiPlaceholders ( array $ placeholders , $ recursive = false ) { foreach ( $ placeholders as $ name => $ placeholder ) { $ this -> addPlaceholder ( $ name , $ placeholder , $ recursive ) ; } }
Adding placeholders .
60,202
public function removePlaceholder ( $ name ) { if ( empty ( $ name ) ) { return ; } $ _name = $ name ; list ( $ name , , $ template ) = $ this -> getParentPlaceholder ( $ name ) ; if ( ! isset ( $ template ) ) { $ template = $ this ; } if ( $ template === false ) { if ( $ this -> throwException ) { throw new TemplateException ( "Unknown scope: {$name}" ) ; } return ; } if ( empty ( $ name ) ) { $ this -> removeAllPlaceholders ( $ _name ) ; return ; } unset ( $ template -> placeholders [ $ name ] ) ; }
Removing placeholder .
60,203
public function removeAllPlaceholders ( $ parent = null ) { if ( isset ( $ parent ) ) { list ( , , $ template ) = $ this -> getParentPlaceholder ( $ parent ) ; } if ( ! isset ( $ template ) ) { $ template = $ this ; } if ( $ template === false ) { if ( $ this -> throwException ) { if ( is_array ( $ parent ) ) { $ parent = implode ( '.' , $ parent ) ; } throw new TemplateException ( "Unknown scope: {$parent}" ) ; } return ; } $ template -> placeholders = [ ] ; }
Removing all placeholders
60,204
public function findPlaceholders ( array $ placeholders = [ ] , $ recursive = false ) { if ( empty ( $ placeholders ) ) { return [ ] ; } $ result = [ ] ; foreach ( $ placeholders as $ name => $ value ) { if ( is_int ( $ name ) ) { if ( $ this -> existsPlaceholder ( $ value ) ) { $ result [ $ this -> _prepareNamePlaceholder ( $ value ) ] = $ this -> getPlaceholder ( $ value , false ) ; } elseif ( $ recursive ) { foreach ( array_reverse ( $ this -> scopes , true ) as $ scope ) { if ( $ scope -> existsPlaceholder ( $ value ) ) { $ result [ $ this -> _prepareNamePlaceholder ( $ value ) ] = $ scope -> getPlaceholder ( $ value ) ; break ; } } } continue ; } $ result [ $ name ] = $ value ; } return $ result ; }
Finds a placeholders .
60,205
public function addConst ( $ name , $ value = null , $ recursive = false , $ changeable = false ) { if ( $ this -> existsConst ( $ name ) && ! $ changeable ) { if ( is_array ( $ name ) ) { $ name = implode ( '.' , $ name ) ; } throw new TemplateException ( "Constant is defined: {$name}" ) ; } static :: $ constants [ $ name ] = isset ( static :: $ constants [ $ name ] ) && is_array ( static :: $ constants [ $ name ] ) ? $ this -> _merge ( static :: $ constants [ $ name ] , ( array ) $ value , $ recursive ) : $ value ; }
Adds a constant .
60,206
public function sanitize ( $ value , $ mode = null ) { if ( $ mode === null ) { $ mode = $ this -> sanitize ; } if ( is_array ( $ value ) ) { $ hash = md5 ( json_encode ( $ value ) ) ; if ( isset ( static :: $ _sanitizeCache [ $ hash ] ) ) { return static :: $ _sanitizeCache [ $ hash ] ; } return static :: $ _sanitizeCache [ $ hash ] = ArrayHelper :: map ( $ value , function ( $ value ) use ( $ mode ) { return $ this -> sanitizeValue ( $ value , $ mode ) ; } , true ) ; } return $ this -> sanitizeValue ( $ value , $ mode ) ; }
Sanitizing value .
60,207
public function getChunk ( $ path , array $ placeholders = [ ] ) { $ template = clone $ this ; $ template -> scopes [ spl_object_hash ( $ this ) ] = $ this ; $ template -> removeAllPlaceholders ( ) ; list ( $ cacheKey , $ cacheExpire , $ cacheTags ) = $ template -> calculateCacheParams ( $ placeholders ) ; if ( ( $ resultCache = $ template -> getCacheContent ( $ cacheKey ) ) !== false ) { return $ resultCache ; } $ result = $ template -> renderInternal ( $ path , $ placeholders ) ; $ template -> setCacheContent ( $ cacheKey , $ result , $ cacheExpire , $ cacheTags ? : [ ] ) ; return $ result ; }
Rendering chunk .
60,208
public function existsChunk ( $ path ) { $ path = Alias :: getAlias ( $ path , [ 'lang' => $ this -> locale ] ) ; if ( ! pathinfo ( $ path , PATHINFO_EXTENSION ) ) { $ path .= '.' . $ this -> defaultExtension ; } return file_exists ( $ path ) ; }
Exists chunk .
60,209
public function getSnippet ( $ snippet , array $ params = [ ] , $ sanitize = null ) { $ template = clone $ this ; $ template -> scopes [ spl_object_hash ( $ this ) ] = $ this ; $ template -> removeAllPlaceholders ( ) ; $ result = $ template -> getSnippetInternal ( $ snippet , $ params , $ sanitize ) ; $ this -> cachePlaceholders = $ template -> cachePlaceholders ; return $ result ; }
Returns a snippet by name .
60,210
public function getExtension ( $ name , array $ params = [ ] , $ sanitize = null ) { $ result = $ this -> _getExtensionInternal ( $ name , $ params ) ; if ( ! empty ( $ params ) ) { $ this -> removePlaceholder ( 'params' ) ; } return $ this -> sanitize ( $ result , $ sanitize ) ; }
Returns a extansion by name .
60,211
public function replaceByPrefix ( $ value , array $ placeholders = [ ] ) { $ dataPrefix = $ this -> getNamePrefix ( $ value ) ; if ( strtolower ( $ dataPrefix [ 'prefix' ] ) === 'inline' ) { $ template = clone $ this ; $ result = $ template -> replace ( $ dataPrefix [ 'value' ] , $ placeholders ) ; return $ result ; } $ result = $ this -> getChunk ( trim ( $ value ) , $ placeholders ) ; return $ result ; }
Replaces a inline tpl .
60,212
public function getNamePrefix ( $ value ) { if ( empty ( $ value ) ) { return null ; } preg_match ( '/(?:\@(?P<prefix>INLINE))?(?P<value>.+)/is' , $ value , $ matches ) ; return [ 'prefix' => Helper :: getValue ( $ matches [ 'prefix' ] ) , 'value' => Helper :: getValue ( $ matches [ 'value' ] ) ] ; }
Returns name of prefix .
60,213
protected function renderBodyBeginHtml ( ) { $ lines = [ $ this -> body ] ; if ( ! empty ( $ this -> jsFiles [ self :: POS_BEGIN ] ) ) { $ lines [ ] = implode ( "\n" , $ this -> jsFiles [ self :: POS_BEGIN ] ) ; } if ( ! empty ( $ this -> js [ self :: POS_BEGIN ] ) ) { $ lines [ ] = Html :: script ( implode ( "\n" , $ this -> js [ self :: POS_BEGIN ] ) , [ 'type' => 'text/javascript' ] ) ; } return empty ( $ lines ) ? '' : implode ( "\n" , $ lines ) ; }
Renders the content to be inserted at the beginning of the body section . The content is rendered using the registered JS code blocks and files .
60,214
public function registerMetaTag ( $ options , $ key = null ) { if ( $ key === null ) { $ this -> metaTags [ ] = $ this -> renderWrapperTag ( Html :: tag ( 'meta' , '' , $ options ) , $ options ) ; } else { $ this -> metaTags [ $ key ] = $ this -> renderWrapperTag ( Html :: tag ( 'meta' , '' , $ options ) , $ options ) ; } }
Registers a meta tag .
60,215
public function registerLinkTag ( $ options , $ key = null ) { if ( $ key === null ) { $ this -> linkTags [ ] = $ this -> renderWrapperTag ( Html :: tag ( 'link' , '' , $ options ) , $ options ) ; } else { $ this -> linkTags [ $ key ] = $ this -> renderWrapperTag ( Html :: tag ( 'link' , '' , $ options ) , $ options ) ; } }
Registers a link tag .
60,216
private function _searchParams ( $ value , array $ dataRecursive ) { preg_match_all ( '/ \? (?P<name>\\w+) # name param \\s*\=\\s* (?P<value>\{{3}\\d+\}{3}\\s*)* # value param [^\?\[\]]* # restriction: is not "?" and not "[" "]" /iux' , $ value , $ matches ) ; $ i = 0 ; $ result = [ ] ; if ( ! isset ( $ matches [ 'name' ] ) ) { return $ result ; } foreach ( $ matches [ 'name' ] as $ nameParams ) { if ( ! isset ( $ matches [ 'value' ] [ $ i ] ) || ! isset ( $ nameParams ) ) { continue ; } $ valueParams = mb_substr ( $ dataRecursive [ trim ( $ matches [ 'value' ] [ $ i ] ) ] , 2 , - 2 , 'UTF-8' ) ; $ valueParams = $ this -> _searchPrefix ( $ nameParams , $ valueParams ) ; if ( is_string ( $ valueParams ) ) { $ valueParams = $ this -> _prepareValueOfParam ( str_replace ( '&#61;' , '=' , $ valueParams ) ) ; $ valueParams = Helper :: toType ( $ valueParams ) ; } if ( isset ( $ result [ $ nameParams ] ) ) { if ( is_array ( $ result [ $ nameParams ] ) ) { $ result [ $ nameParams ] [ ] = $ valueParams ; } else { $ result [ $ nameParams ] = [ $ result [ $ nameParams ] , $ valueParams ] ; } } else { $ result [ $ nameParams ] = $ valueParams ; } ++ $ i ; } return $ result ; }
Search placeholders is variable of template .
60,217
protected function renderBodyEndHtml ( ) { $ lines = [ ] ; if ( ! empty ( $ this -> cssFiles [ self :: POS_END ] ) ) { $ lines [ ] = implode ( "\n" , $ this -> cssFiles [ self :: POS_END ] ) ; } if ( ! empty ( $ this -> jsFiles [ self :: POS_END ] ) ) { $ lines [ ] = implode ( "\n" , $ this -> jsFiles [ self :: POS_END ] ) ; } $ scripts = [ ] ; if ( ! empty ( $ this -> js [ self :: POS_END ] ) ) { $ scripts [ ] = implode ( "\n" , $ this -> js [ self :: POS_END ] ) ; } if ( ! empty ( $ scripts ) ) { $ lines [ ] = Html :: script ( implode ( "\n" , $ scripts ) , [ 'type' => 'text/javascript' ] ) ; } $ lines [ ] = '</body>' ; return empty ( $ lines ) ? '' : implode ( "\n" , $ lines ) ; }
Renders the content to be inserted at the end of the body section . The content is rendered using the registered JS code blocks and files .
60,218
protected function getCacheContent ( $ key = null ) { if ( ! $ this -> cache instanceof CacheInterface ) { return false ; } if ( isset ( $ key ) && ( $ result = $ this -> cache -> get ( $ key ) ) !== false ) { if ( is_array ( $ result ) && isset ( $ result [ 'placeholders' ] , $ result [ 'result' ] ) ) { $ this -> addMultiPlaceholders ( $ result [ 'placeholders' ] ) ; $ result = $ result [ 'result' ] ; } return $ result ; } return false ; }
Returns the content from the cache .
60,219
protected function setCacheContent ( $ key = null , $ value = null , $ expire = 0 , array $ tags = [ ] ) { if ( $ this -> cache instanceof CacheInterface && isset ( $ key ) ) { if ( ! empty ( $ this -> cachePlaceholders ) ) { $ result = $ value ; $ value = [ ] ; $ value [ 'result' ] = $ result ; $ value [ 'placeholders' ] = $ this -> cachePlaceholders ; } $ this -> cache -> set ( $ key , $ value , $ expire , is_string ( $ tags ) ? explode ( ',' , $ tags ) : $ tags ) ; $ this -> cachePlaceholders = [ ] ; } }
Caching template .
60,220
protected function checkPath ( $ path ) { foreach ( $ this -> chroots as $ chroot ) { if ( StringHelper :: contains ( $ path , $ chroot ) ) { return true ; } } return false ; }
Check path to view .
60,221
protected function cleanFilters ( $ filters ) : array { if ( ! is_array ( $ filters ) ) { return array ( ) ; } array_walk_recursive ( $ filters , function ( & $ item , $ key ) { $ item = trim ( $ item ) ; } ) ; $ filters = array_filter ( $ filters , function ( & $ item ) { if ( is_array ( $ item ) ) { $ item = array_filter ( $ item , 'strlen' ) ; return ! empty ( $ item ) ; } return strlen ( $ item ) ; } ) ; return $ filters ; }
Clean filters values . Trim white chars and unset empty filters .
60,222
protected function getItemByHash ( $ hash ) { foreach ( $ this -> items as $ item ) { if ( $ item -> getHash ( ) === $ hash ) { return $ item ; } } return false ; }
Returns the item for the given hash or false if the hash is not available .
60,223
public function getLeftItems ( ) { if ( empty ( $ this -> leftItems ) && empty ( $ this -> rightItems ) ) { $ this -> transformItems ( ) ; } return $ this -> leftItems ; }
Returns the left items
60,224
public function getRightItems ( ) { if ( empty ( $ this -> leftItems ) && empty ( $ this -> rightItems ) ) { $ this -> transformItems ( ) ; } return $ this -> rightItems ; }
Returns the right items
60,225
protected function transformItems ( ) { $ this -> leftItems = array ( ) ; $ this -> rightItems = array ( ) ; foreach ( $ this -> items as $ hash => $ value ) { if ( array_search ( $ value -> getKey ( ) , $ this -> value ) !== false ) { $ this -> rightItems [ ] = $ value ; } else { $ this -> leftItems [ ] = $ value ; } } }
Assigns each item to one of the two lists .
60,226
public function Base_Render_Before ( $ Sender ) { if ( $ Sender -> Menu && Gdn :: Session ( ) -> IsValid ( ) ) { if ( C ( 'Plugins.AllViewed.ShowInMenu' , TRUE ) ) $ Sender -> Menu -> AddLink ( 'AllViewed' , T ( 'Mark All Viewed' ) , '/discussions/markallviewed' ) ; } }
Adds Mark All Viewed to main menu .
60,227
public function DiscussionsController_MarkCategoryViewed_Create ( $ Sender , $ CategoryID ) { if ( strlen ( $ CategoryID ) > 0 && ( int ) $ CategoryID > 0 ) { $ CategoryModel = new CategoryModel ( ) ; $ this -> MarkCategoryRead ( $ CategoryModel , $ CategoryID ) ; $ this -> RecursiveMarkCategoryRead ( $ CategoryModel , CategoryModel :: Categories ( ) , array ( $ CategoryID ) ) ; } Redirect ( Gdn :: Request ( ) -> GetValueFrom ( Gdn_Request :: INPUT_SERVER , 'HTTP_REFERER' ) ) ; }
Allows user to mark all discussions in a specified category as viewed .
60,228
private function RecursiveMarkCategoryRead ( $ CategoryModel , $ UnprocessedCategories , $ ParentIDs ) { $ CurrentUnprocessedCategories = array ( ) ; $ CurrentParentIDs = $ ParentIDs ; foreach ( $ UnprocessedCategories as $ Category ) { if ( in_array ( $ Category [ "ParentCategoryID" ] , $ ParentIDs ) ) { $ this -> MarkCategoryRead ( $ CategoryModel , $ Category [ "CategoryID" ] ) ; if ( ! in_array ( $ Category [ "CategoryID" ] , $ CurrentParentIDs ) ) { $ CurrentParentIDs [ ] = $ Category [ "CategoryID" ] ; } } else { $ CurrentUnprocessedCategories [ ] = $ Category ; } } if ( count ( $ ParentIDs ) != count ( $ CurrentParentIDs ) ) { $ this -> RecursiveMarkCategoryRead ( $ CategoryModel , $ CurrentUnprocessedCategories , $ CurrentParentIDs ) ; } }
Helper function to recursively mark categories as read based on a Category s ParentID .
60,229
public function DiscussionsController_MarkAllViewed_Create ( $ Sender ) { $ CategoryModel = new CategoryModel ( ) ; $ this -> MarkCategoryRead ( $ CategoryModel , - 1 ) ; $ this -> RecursiveMarkCategoryRead ( $ CategoryModel , CategoryModel :: Categories ( ) , array ( - 1 ) ) ; Redirect ( $ _SERVER [ "HTTP_REFERER" ] ) ; }
Allows user to mark all discussions as viewed .
60,230
public function GetCommentCountSince ( $ DiscussionID , $ DateAllViewed ) { if ( ! Gdn :: Session ( ) -> IsValid ( ) ) return ; $ DiscussionID = ( int ) $ DiscussionID ; if ( ! $ DiscussionID ) throw new Exception ( 'A valid DiscussionID is required in GetCommentCountSince.' ) ; return Gdn :: Database ( ) -> SQL ( ) -> From ( 'Comment c' ) -> Where ( 'DiscussionID' , $ DiscussionID ) -> Where ( 'DateInserted >' , Gdn_Format :: ToDateTime ( $ DateAllViewed ) ) -> GetCount ( ) ; }
Get the number of comments inserted since the given timestamp .
60,231
private function CheckDiscussionDate ( $ Discussion , $ DateAllViewed ) { if ( Gdn_Format :: ToTimestamp ( $ Discussion -> DateInserted ) > $ DateAllViewed ) { return ; } if ( Gdn_Format :: ToTimestamp ( $ Discussion -> DateLastComment ) <= $ DateAllViewed ) { $ Discussion -> CountUnreadComments = 0 ; } elseif ( Gdn_Format :: ToTimestamp ( $ Discussion -> DateLastViewed ) == $ DateAllViewed || ! $ Discussion -> DateLastViewed ) { $ Discussion -> CountUnreadComments = $ this -> GetCommentCountSince ( $ Discussion -> DiscussionID , $ DateAllViewed ) ; } }
Helper function to actually override a discussion s unread status
60,232
public function DiscussionModel_SetCalculatedFields_Handler ( $ Sender ) { if ( ! Gdn :: Session ( ) -> IsValid ( ) ) return ; $ Discussion = & $ Sender -> EventArguments [ 'Discussion' ] ; $ Category = CategoryModel :: Categories ( $ Discussion -> CategoryID ) ; $ CategoryLastDate = Gdn_Format :: ToTimestamp ( $ Category [ "DateMarkedRead" ] ) ; if ( $ CategoryLastDate != 0 ) $ this -> CheckDiscussionDate ( $ Discussion , $ CategoryLastDate ) ; }
Modify CountUnreadComments to account for DateAllViewed .
60,233
public static function getCode ( $ path , $ line ) { $ snippet = 7 ; $ code = str_replace ( '>' , '&gt' , str_replace ( '<' , '&lt;' , file_get_contents ( $ path ) ) ) ; $ codesplit = explode ( "\n" , $ code ) ; $ lines = count ( $ codesplit ) ; $ from = $ line < $ snippet ? 0 : $ line - $ snippet ; $ to = $ lines < $ line + $ snippet ? $ lines + 1 : $ line + $ snippet ; $ new = array ( ) ; for ( $ i = $ from ; $ i < $ to - 1 ; $ i ++ ) { if ( $ i + 1 == $ line ) { $ new [ ] = '<span class="highlight">' . ( $ i + 1 ) . ' ' . $ codesplit [ $ i ] . '</span>' ; } else { $ new [ ] = ( $ i + 1 ) . ' ' . $ codesplit [ $ i ] ; } } return '<pre><code>' . implode ( "\n" , $ new ) . "\n</code></pre>" ; }
Erzeugt einen Codeausschnitt einer Datei und hebt eine bestimmte Zeile hervor
60,234
public function addMenuItem ( $ options ) { foreach ( [ 'alias' , 'name' , 'priority' ] as $ attr ) { if ( ! isset ( $ options [ $ attr ] ) || ( isset ( $ options [ $ attr ] ) && $ options [ $ attr ] === '' ) ) { throw new Exception ( '$options[\'' . $ attr . '\'] is missing.' ) ; } } $ menuItem = [ 'alias' => $ options [ 'alias' ] , 'name' => $ options [ 'name' ] , 'priority' => $ options [ 'priority' ] , 'matchAction' => $ options [ 'matchAction' ] ?? false , 'doNotMatchAction' => [ ] , 'linkOptions' => $ options [ 'linkOptions' ] ?? [ ] ] ; if ( isset ( $ options [ 'name_short' ] ) ) { $ menuItem [ 'name_short' ] = $ options [ 'name_short' ] ; } if ( isset ( $ options [ 'icon' ] ) ) { $ menuItem [ 'icon' ] = $ options [ 'icon' ] ; } if ( isset ( $ options [ 'url' ] ) && is_array ( $ options [ 'url' ] ) && ! empty ( $ options [ 'url' ] ) ) { $ url = $ options [ 'url' ] ; if ( ! isset ( $ url [ 'plugin' ] ) || ( isset ( $ url [ 'plugin' ] ) && $ url [ 'plugin' ] === '' ) ) { $ url [ 'plugin' ] = null ; } if ( ! isset ( $ url [ 'controller' ] ) ) { throw new Exception ( '$options[\'url\'][\'controller\'] is missing.' ) ; } if ( ! isset ( $ url [ 'action' ] ) ) { throw new Exception ( '$options[\'url\'][\'action\'] is missing.' ) ; } $ menuItem [ 'url' ] = $ url ; } if ( isset ( $ options [ 'doNotMatchAction' ] ) ) { $ menuItem [ 'doNotMatchAction' ] = is_array ( $ options [ 'doNotMatchAction' ] ) ? $ options [ 'doNotMatchAction' ] : [ $ options [ 'doNotMatchAction' ] ] ; } if ( isset ( $ options [ 'parent' ] ) ) { if ( ! isset ( $ this -> _menuItems [ $ options [ 'parent' ] ] ) ) { throw new Exception ( 'No menu item with the alias specified in $options[\'parent\'] "' . $ options [ 'parent' ] . '"exists.' ) ; } $ menuItem [ 'parent' ] = $ options [ 'parent' ] ; $ this -> _menuItems [ $ menuItem [ 'parent' ] ] [ 'children' ] [ $ menuItem [ 'alias' ] ] = $ menuItem ; } else { $ this -> _menuItems [ $ menuItem [ 'alias' ] ] = $ menuItem ; } return $ this ; }
Add a new menu item
60,235
public function getOrderedArray ( $ items = [ ] ) { $ ordered = [ ] ; if ( empty ( $ items ) ) { $ items = $ this -> _menuItems ; } foreach ( $ items as $ item ) { $ ordered [ ] = $ item ; } $ ordered = Hash :: sort ( $ ordered , '{n}.priority' , 'ASC' ) ; foreach ( $ ordered as & $ item ) { if ( isset ( $ item [ 'children' ] ) && ! empty ( $ item [ 'children' ] ) ) { $ item [ 'children' ] = $ this -> getOrderedArray ( $ item [ 'children' ] ) ; } } return $ ordered ; }
Create and return an array clone of menu items ordered by their priority .
60,236
public function withProtocolVersion ( $ version ) { Validator :: checkProtocolVersion ( $ version ) ; $ instance = clone $ this ; $ instance -> protocol = $ version ; return $ instance ; }
Return an instance with the specified HTTP protocol version
60,237
public function withHeader ( $ name , $ value ) { $ instance = clone $ this ; $ instance -> headers -> set ( $ name , $ value ) ; return $ instance ; }
Return an instance with the provided value replacing the specified header
60,238
public function withAddedHeader ( $ name , $ value ) { $ instance = clone $ this ; $ instance -> headers -> add ( $ name , $ value ) ; return $ instance ; }
Return an instance with the specified header appended with the given value
60,239
public function withoutHeader ( $ name ) { $ instance = clone $ this ; $ instance -> headers -> remove ( $ name , $ value ) ; return $ instance ; }
Return an instance without the specified header
60,240
public function getRenderedTemplate ( ) { $ template = PO_PATH_TEMPLATES . DS . $ this -> _template [ 'folder' ] . DS . $ this -> _template [ 'name' ] . '.phtml' ; $ layout = $ this -> _layout ? PO_PATH_TEMPLATES . DS . 'layout' . DS . $ this -> _layout . '.phtml' : NULL ; return $ this -> render ( $ template , $ layout ) ; }
Renderiza la plantilla actual
60,241
public function getCoreRenderedTemplate ( $ template , $ layout = NULL ) { return $ this -> render ( POWERON_ROOT . DS . $ template , $ layout ? POWERON_ROOT . DS . $ layout : NULL ) ; }
Devuelve una plantilla renderizada del framework
60,242
private function render ( $ template , $ layout ) { if ( ! is_file ( $ template ) ) { throw new \ InvalidArgumentException ( sprintf ( 'No se encuentra la plantilla cargar en (%s).' , $ template ) ) ; } if ( $ layout && ! is_file ( $ layout ) ) { throw new \ InvalidArgumentException ( sprintf ( 'No se encuentra la plantilla principal a cargar en (%s).' , $ layout ) ) ; } ob_start ( [ 'PowerOn\View\View' , 'handleBuffer' ] ) ; try { include $ template ; } catch ( RuntimeException $ e ) { if ( DEV_ENVIRONMENT ) { $ logger = $ this -> _container [ 'Logger' ] ; $ logger -> addDebug ( 'Runtime Error: ' . $ e -> getMessage ( ) , $ e -> getContext ( ) ) ; echo $ e -> getRenderedError ( ) ; } else { ob_end_clean ( ) ; throw new InternalErrorException ( sprintf ( 'Runtime Error: %s <br /><small> %s (%d)</small>' , $ e -> getMessage ( ) , $ e -> getFile ( ) , $ e -> getLine ( ) ) ) ; } } $ this -> _content = ob_get_clean ( ) ; if ( $ layout ) { ob_start ( ) ; require_once $ layout ; return ob_get_clean ( ) ; } return $ this -> _content ; }
Renderiza y devuelve el contenido de la plantilla indicada
60,243
private function handleBuffer ( $ buffer ) { $ error = error_get_last ( ) ; if ( $ error ) { $ matches = [ ] ; preg_match ( '/\: (.*) in /' , $ error [ 'message' ] , $ matches ) ; $ message = key_exists ( 1 , $ matches ) ? $ matches [ 1 ] : $ error [ 'message' ] ; $ response = $ this -> _container [ 'Response' ] ; if ( DEV_ENVIRONMENT ) { $ response -> setHeader ( 500 ) ; return '<header>' . '<h1>Error: ' . $ message . '</h1>' . '<h2>' . $ error [ 'file' ] . ' (' . $ error [ 'line' ] . ')</h2>' . '</header>' ; } else { $ logger = $ this -> _container [ 'Logger' ] ; $ logger -> error ( $ message , [ 'type' => $ error [ 'type' ] , 'file' => $ error [ 'file' ] , 'line' => $ error [ 'line' ] ] ) ; $ router = $ this -> _container [ 'AltoRouter' ] ; $ response -> redirect ( $ router -> generate ( 'poweron_error' , [ 'error' => 500 ] ) ) ; } } return $ buffer ; }
Controla el flujo de una plantilla y procesa los errores en caso de encontrarlos
60,244
public function setLayout ( $ name ) { if ( ! $ name ) { return FALSE ; } $ path_layout = PO_PATH_TEMPLATES . DS . 'layout' . DS . $ name . '.phtml' ; if ( ! is_file ( $ path_layout ) ) { throw new LogicException ( sprintf ( 'No existe la plantilla principal (%s) en (%s).' , $ name , $ path_layout ) ) ; } $ this -> _layout = $ name ; }
Establece una plantilla principal a utilizar
60,245
private function _setDbPrefix ( ) { if ( ! Agl :: isInitialized ( ) ) { return $ this ; } $ dbPrefix = Agl :: app ( ) -> getConfig ( 'main/db/prefix' ) ; if ( $ dbPrefix ) { $ this -> _dbPrefix = $ dbPrefix ; } return $ this ; }
Set the database prefix from configuration .
60,246
private static function preg_replace_query ( $ sql , $ values ) { return preg_replace_callback ( '~{(\w+)(?::(.*))?}~U' , function ( $ matches ) use ( $ values ) { return isset ( $ values [ $ matches [ 1 ] ] ) ? $ values [ $ matches [ 1 ] ] : ( isset ( $ matches [ 2 ] ) ? $ matches [ 2 ] : null ) ; } , $ sql ) ; }
helper functions for the build scripts!
60,247
function fetch_callback ( $ sql , callable $ callback ) { $ result = null ; $ rs = $ this -> query ( $ sql , MYSQLI_USE_RESULT ) ; while ( $ row = $ rs -> fetch_assoc ( ) ) { if ( $ callback ( $ row , $ result ) === false ) break ; } $ rs -> free_result ( ) ; return $ result ; }
optionally return false ; in callback to stop processing
60,248
function get_object ( $ sql , $ class_name = 'stdClass' , array $ params = null ) { $ rs = $ this -> query ( $ sql , MYSQLI_USE_RESULT ) ; $ obj = is_null ( $ params ) ? $ rs -> fetch_object ( $ class_name ) : $ rs -> fetch_object ( $ class_name , $ params ) ; $ rs -> free_result ( ) ; return $ obj ; }
The params don t seem to be passed to the constructor so not sure what that s about
60,249
protected function escapeIdentifier ( $ word , $ escapeChar = '`' ) { if ( is_array ( $ word ) || is_object ( $ word ) || is_numeric ( $ word ) ) { return '' ; } $ spaces = explode ( ' ' , $ word ) ; foreach ( $ spaces as & $ space ) { if ( strtolower ( $ space ) == 'as' ) { $ space = 'AS' ; } else { $ periods = explode ( '.' , $ space ) ; foreach ( $ periods as & $ period ) { if ( preg_match ( '/^[A-Za-z0-9_$]*$/' , $ period ) ) { $ period = $ escapeChar . $ period . $ escapeChar ; } elseif ( ! preg_match ( '/^[A-Za-z0-9_$\*\/\+\-\(\)]*$/' , $ period ) ) { $ period = '' ; } } $ space = implode ( '.' , $ periods ) ; } } return implode ( ' ' , $ spaces ) ; }
Escapes potentially reserved keywords in identifiers by wrapping them with the escape character as necessary .
60,250
protected function parameterizeValues ( array $ values ) { foreach ( $ values as & $ value ) { $ value = $ this -> parameterize ( $ value ) ; } return '(' . implode ( ',' , $ values ) . ')' ; }
Parameterizes a list of values .
60,251
public function setLocales ( array $ locales ) { $ this -> locales = [ ] ; foreach ( $ locales as $ loc ) $ this -> addLocale ( $ loc ) ; }
Set a list of locales
60,252
private function setupProps ( $ amntStore , $ storeId ) { $ this -> uiIsWalletUsed = true ; $ amntWallet = $ this -> hlpWalletCur -> storeToWallet ( $ amntStore , $ storeId ) ; $ this -> uiAmountStore = $ this -> hlpFormat -> toNumber ( round ( $ amntStore , 2 ) ) ; $ this -> uiAmountWallet = $ this -> hlpFormat -> toNumber ( round ( $ amntWallet , 2 ) ) ; $ this -> uiCurrencyWallet = $ this -> hlpWalletCur -> getWalletCurrency ( ) ; $ this -> uiCurrencyStore = $ this -> hlpWalletCur -> getStoreCurrency ( $ storeId ) ; }
Setup block s UI properties if wallet payment is used .
60,253
public function sendRequest ( \ TYPO3 \ Flow \ Http \ Request $ request ) { $ responses = $ this -> sendRequests ( array ( $ request ) ) ; if ( isset ( $ responses [ 0 ] ) ) { return $ responses [ 0 ] ; } else { return NULL ; } }
Sends a single HTTP request
60,254
public function read ( $ length ) { $ buffer = $ this -> socket -> read ( $ length ) ; if ( $ this -> state < self :: STATE_OPEN ) { $ this -> handshakeBuffer .= $ buffer ; $ headerPos = mb_strpos ( $ this -> handshakeBuffer , "\r\n\r\n" , 0 , '8bit' ) ; if ( $ headerPos !== false ) { $ data = mb_substr ( $ this -> handshakeBuffer , 0 , $ headerPos , '8bit' ) ; try { $ this -> handleHandshake ( $ data ) ; } catch ( Net_Notifier_WebSocket_ProtocolException $ e ) { $ this -> state = self :: STATE_CLOSED ; $ this -> shutdown ( ) ; } $ length = mb_strlen ( $ this -> handshakeBuffer , '8bit' ) ; $ buffer = mb_substr ( $ this -> handshakeBuffer , $ headerPos + 4 , $ length - $ headerPos - 5 , '8bit' ) ; } } if ( $ this -> state > self :: STATE_CONNECTING ) { $ frames = $ this -> parser -> parse ( $ buffer ) ; foreach ( $ frames as $ frame ) { $ this -> handleFrame ( $ frame ) ; } } return ( count ( $ this -> textMessages ) > 0 || count ( $ this -> binaryMessages ) > 0 ) ; }
Reads data from this connection
60,255
protected function handleFrame ( Net_Notifier_WebSocket_Frame $ frame ) { switch ( $ frame -> getOpcode ( ) ) { case Net_Notifier_WebSocket_Frame :: TYPE_BINARY : $ this -> binaryBuffer .= $ frame -> getUnmaskedData ( ) ; if ( $ frame -> isFinal ( ) ) { $ this -> binaryMessages [ ] = $ this -> binaryBuffer ; $ this -> binaryBuffer = '' ; } break ; case Net_Notifier_WebSocket_Frame :: TYPE_TEXT : $ this -> textBuffer .= $ frame -> getUnmaskedData ( ) ; if ( $ frame -> isFinal ( ) ) { if ( ! $ this -> isValidUTF8 ( $ this -> textBuffer ) ) { throw new Net_Notifier_WebSocket_UTF8EncodingException ( 'Received a text message that is invalid UTF-8.' , 0 , $ this -> textBuffer ) ; } $ this -> textMessages [ ] = $ this -> textBuffer ; $ this -> textBuffer = '' ; } break ; case Net_Notifier_WebSocket_Frame :: TYPE_CLOSE : if ( $ this -> state === self :: STATE_CLOSING ) { $ this -> close ( ) ; } else { $ this -> startClose ( ) ; } break ; case Net_Notifier_WebSocket_Frame :: TYPE_PING : $ this -> pong ( $ frame -> getUnmaskedData ( ) ) ; break ; } }
Handles a completed received frame
60,256
public function writeBinary ( $ message ) { $ final = false ; $ pos = 0 ; $ totalLength = mb_strlen ( $ message , '8bit' ) ; while ( ! $ final ) { $ data = mb_substr ( $ message , $ pos , self :: FRAME_SIZE , '8bit' ) ; $ dataLength = mb_strlen ( $ data , '8bit' ) ; $ pos += $ dataLength ; $ final = ( $ pos === $ totalLength ) ; $ frame = new Net_Notifier_WebSocket_Frame ( $ data , Net_Notifier_WebSocket_Frame :: TYPE_BINARY , false , $ final ) ; $ this -> send ( $ frame -> __toString ( ) ) ; } }
Writes a binary message to this connection s socket
60,257
public function writeText ( $ message ) { if ( ! $ this -> isValidUTF8 ( $ message ) ) { throw new Net_Notifier_WebSocket_UTF8EncodingException ( 'Can not write text message that is invalid UTF8.' , 0 , $ message ) ; } $ final = false ; $ pos = 0 ; $ totalLength = mb_strlen ( $ message , '8bit' ) ; while ( ! $ final ) { $ data = mb_substr ( $ message , $ pos , self :: FRAME_SIZE , '8bit' ) ; $ dataLength = mb_strlen ( $ data , '8bit' ) ; $ pos += $ dataLength ; $ final = ( $ pos === $ totalLength ) ; $ frame = new Net_Notifier_WebSocket_Frame ( $ data , Net_Notifier_WebSocket_Frame :: TYPE_TEXT , false , $ final ) ; $ this -> send ( $ frame -> __toString ( ) ) ; } }
Writes a text message to this connection s socket
60,258
protected function handleHandshake ( $ data ) { $ handshake = new Net_Notifier_WebSocket_Handshake ( ) ; try { $ response = $ handshake -> receive ( $ data , $ this -> handshakeNonce , array ( Net_Notifier_WebSocket :: PROTOCOL ) ) ; if ( $ response !== null ) { $ this -> send ( $ response ) ; } $ this -> state = self :: STATE_OPEN ; } catch ( Net_Notifier_WebSocket_HandshakeFailureException $ e ) { $ this -> close ( ) ; throw $ e ; } }
Performs a WebSocket handshake step for this client connection
60,259
public function startHandshake ( $ host , $ port , $ resource = '/' , array $ protocols = array ( ) ) { $ this -> handshakeNonce = $ this -> getNonce ( ) ; $ handshake = new Net_Notifier_WebSocket_Handshake ( ) ; $ request = $ handshake -> start ( $ host , $ port , $ this -> handshakeNonce , $ resource , $ protocols ) ; $ this -> send ( $ request ) ; $ this -> state = self :: STATE_CONNECTING ; }
Initiates a WebSocket handshake for this client connection
60,260
public function startClose ( $ code = self :: CLOSE_NORMAL , $ reason = '' ) { if ( $ this -> state < self :: STATE_CLOSING ) { $ code = intval ( $ code ) ; $ data = pack ( 's' , $ code ) . $ reason ; $ frame = new Net_Notifier_WebSocket_Frame ( $ data , Net_Notifier_WebSocket_Frame :: TYPE_CLOSE ) ; $ this -> send ( $ frame -> __toString ( ) ) ; $ this -> state = self :: STATE_CLOSING ; $ this -> shutdown ( ) ; } }
Initiates the WebSocket closing handshake
60,261
public function pong ( $ message ) { $ frame = new Net_Notifier_WebSocket_Frame ( $ message , Net_Notifier_WebSocket_Frame :: TYPE_PONG ) ; $ this -> send ( $ frame -> __toString ( ) ) ; }
Sends a pong frame
60,262
protected function getNonce ( ) { $ nonce = '' ; for ( $ i = 0 ; $ i < 16 ; $ i ++ ) { $ nonce .= chr ( mt_rand ( 0 , 255 ) ) ; } $ nonce = base64_encode ( $ nonce ) ; return $ nonce ; }
Gets a random 16 - byte base - 64 encoded value
60,263
public function jsonDecodeOptions ( bool $ assoc = false , int $ depth = 512 , $ options = 0 ) : Request { $ this -> _jsonOptions = array ( $ assoc , $ depth , $ options ) ; return $ this ; }
Set the JSON decode mode .
60,264
public function headers ( array $ headers ) : Request { $ this -> _defaultHeaders = array_merge ( $ this -> _defaultHeaders , $ headers ) ; return $ this ; }
Set default headers to send on every request
60,265
public function header ( string $ name , string $ value ) : Request { if ( \ is_null ( $ value ) || ! \ is_string ( $ value ) ) { unset ( $ this -> _defaultHeaders [ $ name ] ) ; } $ this -> _defaultHeaders [ $ name ] = $ value ; return $ this ; }
Set a new default header to send on every request
60,266
public function curlOpts ( array $ options ) : Request { $ this -> _curlOpts = \ array_merge ( $ this -> _curlOpts , $ options ) ; return $ this ; }
Set curl options to send on every request
60,267
public function auth ( string $ username = '' , string $ password = '' , $ method = \ CURLAUTH_BASIC ) : Request { $ this -> _auth [ 'user' ] = $ username ; $ this -> _auth [ 'pass' ] = $ password ; $ this -> _auth [ 'meth' ] = $ method ; return $ this ; }
Set authentication method to use .
60,268
public function proxy ( string $ address , int $ port = 1080 , $ type = \ CURLPROXY_HTTP , bool $ tunnel = false ) : Request { $ this -> _proxy [ 'type' ] = $ type ; $ this -> _proxy [ 'port' ] = $ port ; $ this -> _proxy [ 'tunnel' ] = $ tunnel ; $ this -> _proxy [ 'address' ] = $ address ; return $ this ; }
Set proxy to use .
60,269
protected function _FromForm ( ) { $ Form = new Gdn_Form ( ) ; $ Px = $ this -> Prefix ; $ Types = ( array ) $ Form -> GetFormValue ( $ Px . 'Type' , array ( ) ) ; $ PermissionFields = ( array ) $ Form -> GetFormValue ( $ Px . 'PermissionField' , array ( ) ) ; $ RoleFields = ( array ) $ Form -> GetFormValue ( $ Px . 'RoleField' , array ( ) ) ; $ Fields = ( array ) $ Form -> GetFormValue ( $ Px . 'Field' , array ( ) ) ; $ Expressions = ( array ) $ Form -> GetFormValue ( $ Px . 'Expr' , array ( ) ) ; $ Conditions = array ( ) ; for ( $ i = 0 ; $ i < count ( $ Types ) - 1 ; $ i ++ ) { $ Condition = array ( $ Types [ $ i ] ) ; switch ( $ Types [ $ i ] ) { case Gdn_Condition :: PERMISSION : $ Condition [ 1 ] = GetValue ( $ i , $ PermissionFields , '' ) ; break ; case Gdn_Condition :: REQUEST : $ Condition [ 1 ] = GetValue ( $ i , $ Fields , '' ) ; $ Condition [ 2 ] = GetValue ( $ i , $ Expressions , '' ) ; break ; case Gdn_Condition :: ROLE : $ Condition [ 1 ] = GetValue ( $ i , $ RoleFields ) ; break ; case '' : $ Condition [ 1 ] = '' ; break ; default : continue ; } $ Conditions [ ] = $ Condition ; } return $ Conditions ; }
Grab the values from the form into the conditions array .
60,270
public function formalize ( ) { $ this -> supports ( StorageType :: OUTBOX ( ) , function ( Settings $ s ) { FeatureSettingsExtensions :: enableFeatureByDefault ( InMemoryOutboxPersistenceFeature :: class , $ s ) ; } ) ; }
This is where subclasses declare what storage types they support together with the initializers for those types .
60,271
public function controllerList ( ) { $ names = $ this -> controllerManager -> getCanonicalNames ( ) ; $ controllers = array ( ) ; foreach ( $ names as $ name ) { try { $ controllers [ $ name ] = $ this -> controllerManager -> get ( $ name ) ; } catch ( \ Exception $ e ) { continue ; } } return $ controllers ; }
Returns a list of controller names and class names .
60,272
public function loadCachedConfig ( array & $ config ) { $ cacheFilePath = $ this -> config -> getCacheFile ( ) ; if ( ! file_exists ( $ cacheFilePath ) ) { return false ; } $ cachedConfig = include $ cacheFilePath ; if ( ! is_array ( $ cachedConfig ) ) { return false ; } if ( ! isset ( $ config [ 'routes' ] ) ) { $ config [ 'routes' ] = array ( ) ; } $ this -> merger -> merge ( $ cachedConfig , $ config [ 'routes' ] ) ; return true ; }
Attempt to use cache rather than annotations .
60,273
public function getRouteConfig ( array $ controllers ) { $ routeList = new ArrayObject ( ) ; foreach ( $ controllers as $ name => $ controller ) { $ routeList = $ this -> parser -> parseReflectedController ( $ name , $ this -> parser -> getReflectedController ( $ controller ) , $ routeList ) ; } return $ routeList -> getArrayCopy ( ) ; }
Returns the config fetched from the annotations
60,274
public function updateRouteConfig ( array & $ config ) { if ( $ this -> loadCachedConfig ( $ config ) ) { return ; } $ routeList = $ this -> getRouteConfig ( $ this -> controllerList ( ) ) ; if ( ! sizeof ( $ routeList ) ) { return ; } if ( ! isset ( $ config [ 'routes' ] ) ) { $ config [ 'routes' ] = array ( ) ; } $ this -> merger -> merge ( $ routeList , $ config [ 'routes' ] ) ; }
Parses the route annotations and updates the route stack .
60,275
public function exists ( ) { if ( ! $ this -> name ) { throw new UnexpectedValueException ( 'Cannot check for existing user without a name' ) ; } if ( ! $ this -> host ) { throw new UnexpectedValueException ( 'Cannot check for existing user without a host because the result could be ambiguous' ) ; } $ row = $ this -> client -> getSingleResult ( 'SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = :user AND host = :host)' , array ( ':user' => $ this -> name , ':host' => strtolower ( $ this -> host ) == 'any' ? '%' : $ this -> host ) ) ; return ( bool ) $ row [ 0 ] ; }
Test whether or not the user exists .
60,276
public function delete ( ) { if ( ! $ this -> name ) { throw new UnexpectedValueException ( 'Cannot delete a user with no name' ) ; } $ parts = array ( 'DROP USER :user' ) ; $ params = array ( ':user' => $ this -> name ) ; if ( $ this -> host ) { $ parts [ ] = '@:host' ; $ params [ ':host' ] = strtolower ( $ this -> host ) == 'any' ? '%' : $ this -> host ; } $ this -> client -> execute ( 'FLUSH PRIVILEGES' ) ; $ this -> client -> execute ( implode ( ' ' , $ parts ) , $ params ) ; $ this -> client -> execute ( 'FLUSH PRIVILEGES' ) ; }
Delete the user .
60,277
public function create ( ) { if ( ! $ this -> name ) { throw new UnexpectedValueException ( 'Cannot create a user with no name' ) ; } $ parts = array ( 'CREATE USER :user' ) ; $ params = array ( ':user' => $ this -> name ) ; if ( $ this -> host ) { $ parts [ ] = '@:host' ; $ params [ ':host' ] = strtolower ( $ this -> host ) == 'any' ? '%' : $ this -> host ; } if ( $ this -> password ) { $ parts [ ] = 'IDENTIFIED BY :password' ; $ params [ ':password' ] = $ this -> password ; } $ this -> client -> execute ( 'FLUSH PRIVILEGES' ) ; $ this -> client -> execute ( implode ( ' ' , $ parts ) , $ params ) ; $ this -> client -> execute ( 'FLUSH PRIVILEGES' ) ; }
Create the user .
60,278
public function grant ( ) { if ( ! $ this -> name ) { throw new UnexpectedValueException ( 'Cannot grant privileges to a user with no name' ) ; } if ( ! $ this -> grants ) { throw new UnexpectedValueException ( 'Cannot grant privileges without being told what privileges to grant' ) ; } if ( ! $ this -> grantLevel ) { throw new UnexpectedValueException ( 'Cannot grant privileges without being told on what to grant them' ) ; } $ params = array ( ) ; $ parts = array ( sprintf ( 'GRANT %s ON %s' , strtolower ( $ this -> grants ) == 'all' ? 'ALL PRIVILEGES' : $ this -> grants , $ this -> grantLevel ) ) ; $ parts [ ] = 'TO :user' ; $ params [ ':user' ] = $ this -> name ; if ( $ this -> host ) { $ parts [ ] = '@:host' ; $ params [ ':host' ] = strtolower ( $ this -> host ) == 'any' ? '%' : $ this -> host ; } if ( $ this -> grantGrant ) { $ parts [ ] = 'WITH GRANT OPTION' ; } $ this -> client -> execute ( 'FLUSH PRIVILEGES' ) ; $ this -> client -> execute ( implode ( ' ' , $ parts ) , $ params ) ; $ this -> client -> execute ( 'FLUSH PRIVILEGES' ) ; }
Grant privileges to the user .
60,279
public function removeRule ( $ ruleName ) { if ( isset ( $ this -> rules [ $ ruleName ] ) ) { unset ( $ this -> rules [ $ ruleName ] ) ; return true ; } return false ; }
Removes a single rule by name
60,280
public function check ( $ input ) { $ this -> lastValue = $ input ; $ anyFailed = false ; foreach ( $ this -> rules as $ ruleName => & $ rule ) { if ( $ rule -> check ( $ input ) ) { if ( $ this -> matchAny || $ rule -> isSufficient ( ) ) { return true ; } } elseif ( ! $ this -> matchAny ) { $ this -> failedRule = & $ rule ; return false ; } else { if ( ! $ anyFailed ) { $ this -> failedRule = & $ rule ; } $ anyFailed = true ; } } return ! $ anyFailed ; }
Check all rules of this attribyte against input
60,281
public function determineDependents ( $ input , array & $ required ) { if ( $ this -> hasError ( ) ) { return ; } $ this -> lastValue = $ input ; $ foundRequired = false ; foreach ( $ this -> dependent as $ onInput => $ requiredNames ) { if ( $ onInput === '*' ) { continue ; } elseif ( $ input === $ onInput ) { $ foundRequired = true ; foreach ( $ requiredNames as $ attribName ) { $ required [ $ attribName ] = true ; } } } if ( $ input && ! $ foundRequired && isset ( $ this -> dependent [ '*' ] ) ) { foreach ( $ this -> dependent [ '*' ] as $ attribName ) { $ required [ $ attribName ] = true ; } } foreach ( $ this -> dependentRegex as $ onRegex => $ requiredNames ) { if ( preg_match ( $ onRegex , $ input ) ) { foreach ( $ requiredNames as $ attribName ) { $ required [ $ attribName ] = true ; } } } }
Adds possible requireds to list if . Only if not have error .
60,282
public function getMissingText ( ) { $ missing = $ this -> missing ? : $ this -> dataFilter -> getMissingTemplate ( ) ; return U :: formatString ( $ missing , array ( 'attrib' => $ this -> name ) ) ; }
Returns formatted missing text
60,283
public function setHeaders ( $ name , $ value = null ) { if ( is_array ( $ name ) ) { foreach ( $ name as $ k => $ v ) { if ( is_string ( $ k ) ) { $ this -> setHeaders ( $ k , $ v ) ; } else { $ this -> setHeaders ( $ v , null ) ; } } } else { if ( $ value === null && ( strpos ( $ name , ':' ) > 0 ) ) { list ( $ name , $ value ) = explode ( ':' , $ name , 2 ) ; } if ( $ this -> config [ 'strict' ] && ( ! preg_match ( '/^[a-zA-Z0-9-]+$/' , $ name ) ) ) { throw new Zend_Http_Client_Exception ( "{$name} is not a valid HTTP header name" ) ; } $ normalized_name = strtolower ( $ name ) ; if ( $ value === null || $ value === false ) { unset ( $ this -> headers [ $ normalized_name ] ) ; } else { if ( is_string ( $ value ) ) { $ value = trim ( $ value ) ; } $ this -> headers [ $ normalized_name ] = array ( $ name , $ value ) ; } } return $ this ; }
Set one or more request headers
60,284
public function setCookie ( $ cookie , $ value = null ) { Zend_Loader :: loadClass ( 'Zend_Http_Cookie' ) ; if ( is_array ( $ cookie ) ) { foreach ( $ cookie as $ c => $ v ) { if ( is_string ( $ c ) ) { $ this -> setCookie ( $ c , $ v ) ; } else { $ this -> setCookie ( $ v ) ; } } return $ this ; } if ( $ value !== null && $ this -> config [ 'encodecookies' ] ) { $ value = urlencode ( $ value ) ; } if ( isset ( $ this -> cookiejar ) ) { if ( $ cookie instanceof Zend_Http_Cookie ) { $ this -> cookiejar -> addCookie ( $ cookie ) ; } elseif ( is_string ( $ cookie ) && $ value !== null ) { $ cookie = Zend_Http_Cookie :: fromString ( "{$cookie}={$value}" , $ this -> uri , $ this -> config [ 'encodecookies' ] ) ; $ this -> cookiejar -> addCookie ( $ cookie ) ; } } else { if ( $ cookie instanceof Zend_Http_Cookie ) { $ name = $ cookie -> getName ( ) ; $ value = $ cookie -> getValue ( ) ; $ cookie = $ name ; } if ( preg_match ( "/[=,; \t\r\n\013\014]/" , $ cookie ) ) { throw new Zend_Http_Client_Exception ( "Cookie name cannot contain these characters: =,; \t\r\n\013\014 ({$cookie})" ) ; } $ value = addslashes ( $ value ) ; if ( ! isset ( $ this -> headers [ 'cookie' ] ) ) { $ this -> headers [ 'cookie' ] = array ( 'Cookie' , '' ) ; } $ this -> headers [ 'cookie' ] [ 1 ] .= $ cookie . '=' . $ value . '; ' ; } return $ this ; }
Add a cookie to the request . If the client has no Cookie Jar the cookies will be added directly to the headers array as Cookie headers .
60,285
protected function _openTempStream ( ) { $ this -> _stream_name = $ this -> config [ 'output_stream' ] ; if ( ! is_string ( $ this -> _stream_name ) ) { $ this -> _stream_name = tempnam ( isset ( $ this -> config [ 'stream_tmp_dir' ] ) ? $ this -> config [ 'stream_tmp_dir' ] : sys_get_temp_dir ( ) , 'Zend_Http_Client' ) ; } if ( false === ( $ fp = @ fopen ( $ this -> _stream_name , "w+b" ) ) ) { if ( $ this -> adapter instanceof Zend_Http_Client_Adapter_Interface ) { $ this -> adapter -> close ( ) ; } throw new Zend_Http_Client_Exception ( "Could not open temp file {$this->_stream_name}" ) ; } return $ fp ; }
Create temporary stream
60,286
public static function _getUserIpAddr ( ) { $ ip = 'unknown.ip.address' ; if ( isset ( $ _SERVER ) ) { if ( ! empty ( $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) ) { $ ip = $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ; } elseif ( ! empty ( $ _SERVER [ 'REMOTE_ADDR' ] ) ) { $ ip = $ _SERVER [ 'REMOTE_ADDR' ] ; } } return $ ip ; }
Gets the current user s IP address
60,287
public function GetNew ( $ DiscussionID , $ LastCommentID = 0 ) { $ this -> SetData ( 'Discussion' , $ this -> DiscussionModel -> GetID ( $ DiscussionID ) , TRUE ) ; $ this -> Permission ( 'Vanilla.Discussions.View' , TRUE , 'Category' , $ this -> Discussion -> PermissionCategoryID ) ; $ this -> SetData ( 'CategoryID' , $ this -> CategoryID = $ this -> Discussion -> CategoryID , TRUE ) ; $ Comments = $ this -> CommentModel -> GetNew ( $ DiscussionID , $ LastCommentID ) -> Result ( ) ; $ this -> SetData ( 'Comments' , $ Comments , TRUE ) ; if ( count ( $ Comments ) > 0 ) { $ LastComment = $ Comments [ count ( $ Comments ) - 1 ] ; $ this -> SetData ( 'Offset' , $ this -> Discussion -> CountComments , TRUE ) ; $ this -> CommentModel -> SetWatch ( $ this -> Discussion , $ this -> Discussion -> CountComments , $ this -> Discussion -> CountComments , $ this -> Discussion -> CountComments ) ; $ LastCommentID = $ this -> Json ( 'LastCommentID' ) ; if ( is_null ( $ LastCommentID ) || $ LastComment -> CommentID > $ LastCommentID ) { $ this -> Json ( 'LastCommentID' , $ LastComment -> CommentID ) ; } } else { $ this -> SetData ( 'Offset' , $ this -> CommentModel -> GetOffset ( $ LastCommentID ) , TRUE ) ; } $ this -> View = 'comments' ; $ this -> Render ( ) ; }
Display comments in a discussion since a particular CommentID .
60,288
public function Comment ( $ CommentID ) { $ Comment = $ this -> CommentModel -> GetID ( $ CommentID ) ; if ( ! $ Comment ) throw NotFoundException ( 'Comment' ) ; $ DiscussionID = $ Comment -> DiscussionID ; $ Offset = $ this -> CommentModel -> GetOffset ( $ Comment ) ; $ Limit = Gdn :: Config ( 'Vanilla.Comments.PerPage' , 30 ) ; $ PageNumber = PageNumber ( $ Offset , $ Limit , TRUE ) ; $ this -> SetData ( 'Page' , $ PageNumber ) ; $ this -> View = 'index' ; $ this -> Index ( $ DiscussionID , 'x' , $ PageNumber ) ; }
Display discussion page starting with a particular comment .
60,289
public function DismissAnnouncement ( $ DiscussionID = '' ) { if ( ! C ( 'Vanilla.Discussions.Dismiss' , 1 ) ) { throw PermissionException ( 'Vanilla.Discussions.Dismiss' ) ; } if ( ! $ this -> Request -> IsPostBack ( ) ) throw PermissionException ( 'Javascript' ) ; $ Session = Gdn :: Session ( ) ; if ( is_numeric ( $ DiscussionID ) && $ DiscussionID > 0 && $ Session -> UserID > 0 ) $ this -> DiscussionModel -> DismissAnnouncement ( $ DiscussionID , $ Session -> UserID ) ; if ( $ this -> _DeliveryType === DELIVERY_TYPE_ALL ) Redirect ( 'discussions' ) ; $ this -> JsonTarget ( "#Discussion_$DiscussionID" , NULL , 'SlideUp' ) ; $ this -> Render ( 'Blank' , 'Utility' , 'Dashboard' ) ; }
Allows user to remove announcement .
60,290
public function Bookmark ( $ DiscussionID ) { if ( ! $ this -> Request -> IsPostBack ( ) ) throw PermissionException ( 'Javascript' ) ; $ Session = Gdn :: Session ( ) ; if ( $ Session -> UserID == 0 ) throw PermissionException ( 'SignedIn' ) ; $ Discussion = $ this -> DiscussionModel -> GetID ( $ DiscussionID ) ; if ( ! $ Discussion ) throw NotFoundException ( 'Discussion' ) ; $ State = $ this -> DiscussionModel -> BookmarkDiscussion ( $ DiscussionID , $ Session -> UserID , $ Discussion ) ; $ CountBookmarks = $ this -> DiscussionModel -> SetUserBookmarkCount ( $ Session -> UserID ) ; $ this -> JsonTarget ( '.User-CountBookmarks' , ( string ) $ CountBookmarks ) ; require_once $ this -> FetchViewLocation ( 'helper_functions' , 'Discussions' ) ; $ Html = BookmarkButton ( $ Discussion ) ; $ this -> JsonTarget ( "!element" , $ Html , 'ReplaceWith' ) ; if ( $ State ) { $ Bookmarks = new BookmarkedModule ( $ this ) ; if ( $ CountBookmarks == 1 ) { $ Target = '#Panel' ; $ Type = 'Append' ; $ Bookmarks -> GetData ( ) ; $ Data = $ Bookmarks -> ToString ( ) ; } else { $ Target = '#Bookmark_List' ; $ Type = 'Prepend' ; $ Loc = $ Bookmarks -> FetchViewLocation ( 'discussion' ) ; ob_start ( ) ; include ( $ Loc ) ; $ Data = ob_get_clean ( ) ; } $ this -> JsonTarget ( $ Target , $ Data , $ Type ) ; } else { if ( $ CountBookmarks == 0 ) { $ this -> JsonTarget ( '#Bookmarks' , NULL , 'Remove' ) ; } else { $ this -> JsonTarget ( '#Bookmark_' . $ DiscussionID , NULL , 'Remove' ) ; } } $ this -> Render ( 'Blank' , 'Utility' , 'Dashboard' ) ; }
Allows user to bookmark or unbookmark a discussion .
60,291
public function Announce ( $ DiscussionID = '' , $ Target = '' ) { $ Discussion = $ this -> DiscussionModel -> GetID ( $ DiscussionID ) ; if ( ! $ Discussion ) throw NotFoundException ( 'Discussion' ) ; $ this -> Permission ( 'Vanilla.Discussions.Announce' , TRUE , 'Category' , $ Discussion -> PermissionCategoryID ) ; if ( $ this -> Form -> IsPostBack ( ) ) { $ CacheKeys = array ( 'Announcements' , 'Announcements_' . GetValue ( 'CategoryID' , $ Discussion ) ) ; $ this -> DiscussionModel -> SQL -> Cache ( $ CacheKeys ) ; $ this -> DiscussionModel -> SetProperty ( $ DiscussionID , 'Announce' , ( int ) $ this -> Form -> GetFormValue ( 'Announce' , 0 ) ) ; if ( $ Target ) $ this -> RedirectUrl = Url ( $ Target ) ; } else { if ( ! $ Discussion -> Announce ) $ Discussion -> Announce = 2 ; $ this -> Form -> SetData ( $ Discussion ) ; } $ Discussion = ( array ) $ Discussion ; $ Category = CategoryModel :: Categories ( $ Discussion [ 'CategoryID' ] ) ; $ this -> SetData ( 'Discussion' , $ Discussion ) ; $ this -> SetData ( 'Category' , $ Category ) ; $ this -> Title ( T ( 'Announce' ) ) ; $ this -> Render ( ) ; }
Allows user to announce or unannounce a discussion .
60,292
public function Sink ( $ DiscussionID = '' , $ Sink = TRUE , $ From = 'list' ) { if ( ! $ this -> Request -> IsPostBack ( ) ) throw PermissionException ( 'Javascript' ) ; $ Discussion = $ this -> DiscussionModel -> GetID ( $ DiscussionID ) ; if ( ! $ Discussion ) throw NotFoundException ( 'Discussion' ) ; $ this -> Permission ( 'Vanilla.Discussions.Sink' , TRUE , 'Category' , $ Discussion -> PermissionCategoryID ) ; $ this -> DiscussionModel -> SetField ( $ DiscussionID , 'Sink' , $ Sink ) ; $ Discussion -> Sink = $ Sink ; if ( $ this -> _DeliveryType === DELIVERY_TYPE_ALL ) { $ Target = GetIncomingValue ( 'Target' , 'discussions' ) ; Redirect ( $ Target ) ; } $ this -> SendOptions ( $ Discussion ) ; $ this -> JsonTarget ( "#Discussion_$DiscussionID" , NULL , 'Highlight' ) ; $ this -> JsonTarget ( ".Discussion #Item_0" , NULL , 'Highlight' ) ; $ this -> Render ( 'Blank' , 'Utility' , 'Dashboard' ) ; }
Allows user to sink or unsink a discussion .
60,293
public function Close ( $ DiscussionID = '' , $ Close = TRUE , $ From = 'list' ) { if ( ! $ this -> Request -> IsPostBack ( ) ) throw PermissionException ( 'Javascript' ) ; $ Discussion = $ this -> DiscussionModel -> GetID ( $ DiscussionID ) ; if ( ! $ Discussion ) throw NotFoundException ( 'Discussion' ) ; $ this -> Permission ( 'Vanilla.Discussions.Close' , TRUE , 'Category' , $ Discussion -> PermissionCategoryID ) ; $ this -> DiscussionModel -> SetField ( $ DiscussionID , 'Closed' , $ Close ) ; $ Discussion -> Closed = $ Close ; if ( $ this -> _DeliveryType === DELIVERY_TYPE_ALL ) { $ Target = GetIncomingValue ( 'Target' , 'discussions' ) ; Redirect ( $ Target ) ; } $ this -> SendOptions ( $ Discussion ) ; if ( $ Close ) { require_once $ this -> FetchViewLocation ( 'helper_functions' , 'Discussions' ) ; $ this -> JsonTarget ( ".Section-DiscussionList #Discussion_$DiscussionID .Meta-Discussion" , Tag ( $ Discussion , 'Closed' , 'Closed' ) , 'Prepend' ) ; $ this -> JsonTarget ( ".Section-DiscussionList #Discussion_$DiscussionID" , 'Closed' , 'AddClass' ) ; } else { $ this -> JsonTarget ( ".Section-DiscussionList #Discussion_$DiscussionID .Tag-Closed" , NULL , 'Remove' ) ; $ this -> JsonTarget ( ".Section-DiscussionList #Discussion_$DiscussionID" , 'Closed' , 'RemoveClass' ) ; } $ this -> JsonTarget ( "#Discussion_$DiscussionID" , NULL , 'Highlight' ) ; $ this -> JsonTarget ( ".Discussion #Item_0" , NULL , 'Highlight' ) ; $ this -> Render ( 'Blank' , 'Utility' , 'Dashboard' ) ; }
Allows user to close or re - open a discussion .
60,294
public function Delete ( $ DiscussionID , $ Target = '' ) { $ Discussion = $ this -> DiscussionModel -> GetID ( $ DiscussionID ) ; if ( ! $ Discussion ) throw NotFoundException ( 'Discussion' ) ; $ this -> Permission ( 'Vanilla.Discussions.Delete' , TRUE , 'Category' , $ Discussion -> PermissionCategoryID ) ; if ( $ this -> Form -> IsPostBack ( ) ) { if ( ! $ this -> DiscussionModel -> Delete ( $ DiscussionID ) ) $ this -> Form -> AddError ( 'Failed to delete discussion' ) ; if ( $ this -> Form -> ErrorCount ( ) == 0 ) { if ( $ this -> _DeliveryType === DELIVERY_TYPE_ALL ) Redirect ( $ Target ) ; if ( $ Target ) $ this -> RedirectUrl = Url ( $ Target ) ; $ this -> JsonTarget ( ".Section-DiscussionList #Discussion_$DiscussionID" , NULL , 'SlideUp' ) ; } } $ this -> SetData ( 'Title' , T ( 'Delete Discussion' ) ) ; $ this -> Render ( ) ; }
Allows user to delete a discussion .
60,295
public function DeleteComment ( $ CommentID = '' , $ TransientKey = '' ) { $ Session = Gdn :: Session ( ) ; $ DefaultTarget = '/discussions/' ; $ ValidCommentID = is_numeric ( $ CommentID ) && $ CommentID > 0 ; $ ValidUser = $ Session -> UserID > 0 && $ Session -> ValidateTransientKey ( $ TransientKey ) ; if ( $ ValidCommentID && $ ValidUser ) { $ Comment = $ this -> CommentModel -> GetID ( $ CommentID ) ; $ DiscussionID = GetValue ( 'DiscussionID' , $ Comment ) ; $ Discussion = $ this -> DiscussionModel -> GetID ( $ DiscussionID ) ; if ( $ Comment && $ Discussion ) { $ DefaultTarget = DiscussionUrl ( $ Discussion ) ; if ( $ Comment -> InsertUserID != $ Session -> UserID ) $ this -> Permission ( 'Vanilla.Comments.Delete' , TRUE , 'Category' , $ Discussion -> PermissionCategoryID ) ; $ EditContentTimeout = C ( 'Garden.EditContentTimeout' , - 1 ) ; $ CanEdit = $ EditContentTimeout == - 1 || strtotime ( $ Comment -> DateInserted ) + $ EditContentTimeout > time ( ) ; if ( ! $ CanEdit ) $ this -> Permission ( 'Vanilla.Comments.Delete' , TRUE , 'Category' , $ Discussion -> PermissionCategoryID ) ; if ( ! $ this -> CommentModel -> Delete ( $ CommentID ) ) $ this -> Form -> AddError ( 'Failed to delete comment' ) ; } else { $ this -> Form -> AddError ( 'Invalid comment' ) ; } } else { $ this -> Form -> AddError ( 'ErrPermission' ) ; } if ( $ this -> _DeliveryType == DELIVERY_TYPE_ALL ) { $ Target = GetIncomingValue ( 'Target' , $ DefaultTarget ) ; Redirect ( $ Target ) ; } if ( $ this -> Form -> ErrorCount ( ) > 0 ) { $ this -> SetJson ( 'ErrorMessage' , $ this -> Form -> Errors ( ) ) ; } else { $ this -> JsonTarget ( "#Comment_$CommentID" , '' , 'SlideUp' ) ; } $ this -> Render ( ) ; }
Allows user to delete a comment .
60,296
protected function RedirectDiscussion ( $ Discussion ) { $ Body = Gdn_Format :: To ( GetValue ( 'Body' , $ Discussion ) , GetValue ( 'Format' , $ Discussion ) ) ; if ( preg_match ( '`href="([^"]+)"`i' , $ Body , $ Matches ) ) { $ Url = $ Matches [ 1 ] ; Redirect ( $ Url , 301 ) ; } }
Redirect to the url specified by the discussion .
60,297
public function RefetchPageInfo ( $ DiscussionID ) { if ( ! $ this -> Request -> IsPostBack ( ) ) throw PermissionException ( 'Javascript' ) ; $ Discussion = $ this -> DiscussionModel -> GetID ( $ DiscussionID ) ; if ( ! $ Discussion ) throw NotFoundException ( 'Discussion' ) ; $ this -> Permission ( 'Vanilla.Discussions.Edit' , TRUE , 'Category' , $ Discussion -> PermissionCategoryID ) ; $ ForeignUrl = GetValueR ( 'Attributes.ForeignUrl' , $ Discussion ) ; if ( ! $ ForeignUrl ) { throw new Gdn_UserException ( T ( "This discussion isn't associated with a url." ) ) ; } $ Stub = $ this -> DiscussionModel -> FetchPageInfo ( $ ForeignUrl , TRUE ) ; $ this -> DiscussionModel -> SetField ( $ DiscussionID , ( array ) $ Stub ) ; if ( isset ( $ Stub [ 'Name' ] ) ) $ this -> JsonTarget ( '.PageTitle h1' , Gdn_Format :: Text ( $ Stub [ 'Name' ] ) ) ; if ( isset ( $ Stub [ 'Body' ] ) ) $ this -> JsonTarget ( "#Discussion_$DiscussionID .Message" , Gdn_Format :: To ( $ Stub [ 'Body' ] , $ Stub [ 'Format' ] ) ) ; $ this -> InformMessage ( 'The page was successfully fetched.' ) ; $ this -> Render ( 'Blank' , 'Utility' , 'Dashboard' ) ; }
Re - fetch a discussion s content based on its foreign url .
60,298
public function build ( $ className ) { $ footprint = $ this -> _footprintRegistry -> get ( $ className ) ; $ parentClass = $ footprint -> getParent ( ) ; if ( ! $ parentClass ) { $ parentClass = $ this -> _baseClassRegistry -> find ( $ className ) ; } if ( $ footprint -> isInterface ( ) ) { $ generator = new InterfaceGenerator ( ) ; } else { $ traits = $ this -> _traitRegistry -> findByClass ( $ className ) ; $ generator = new ClassGenerator ( ) ; $ generator -> useTraits ( $ traits ) ; } $ generator -> setName ( $ className ) ; $ generator -> setExtendedClass ( $ parentClass ) ; $ generator -> setImplementedInterfaces ( $ footprint -> getInterfaces ( ) ) ; foreach ( $ footprint -> getConstants ( ) as $ name => $ value ) { $ generator -> addConstant ( $ name , $ value ) ; } $ file = new FileGenerator ( ) ; $ file -> setClass ( $ generator ) ; return $ file ; }
Generate class using any given references or traits
60,299
public function getMinValue ( ) { $ values = $ this -> values -> toArray ( ) ; uasort ( $ values , $ this -> cmpValues ( 'getName' ) ) ; return reset ( $ values ) ; }
Get minimum value