idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
3,100
protected static function determineHintLocation ( $ hint ) { if ( is_string ( $ hint ) && file_exists ( $ hint ) ) { $ path = $ hint ; } elseif ( is_object ( $ hint ) || class_exists ( $ hint ) ) { $ r = new \ ReflectionClass ( $ hint ) ; $ path = $ r -> getFileName ( ) ; } $ path = realpath ( $ path ) ; if ( false === $ path ) { throw new ExceptionPackageInfo ( 'Is it real? Could not determine real location of hint.' ) ; } return static :: sanitisePaths ( $ path ) ; }
Convert whatever hint we got into a usable file path .
3,101
public function get ( $ name ) { if ( ! is_string ( $ name ) ) { throw new \ InvalidArgumentException ( self :: MSG_EXTENSION_NAME , 220 ) ; } if ( ! $ this -> offsetExists ( strtolower ( $ name ) ) ) { throw new \ LogicException ( sprintf ( self :: MSG_NO_EXTENSION_TOGET , $ name ) , 221 ) ; } return parent :: offsetGet ( strtolower ( $ name ) ) ; }
Get a new extension method
3,102
public function add ( $ collection ) { if ( ! is_array ( $ collection ) and ! ( $ collection instanceof \ Traversable ) ) { throw new \ InvalidArgumentException ( self :: MSG_NOT_ITERABLE , 230 ) ; } foreach ( $ collection as $ name => $ closure ) { $ this -> set ( $ name , $ closure ) ; } return $ this ; }
Add a list of extension
3,103
public function onKernelRequest ( ) { foreach ( $ this -> kernel -> getBundles ( ) as $ bundle ) { $ bundlePathPackage = new BundlePathPackage ( $ this -> versionStrategy ) ; $ bundlePathPackage -> setBundlePath ( $ bundle -> getName ( ) ) ; $ this -> assetsPackages -> addPackage ( $ bundle -> getName ( ) , $ bundlePathPackage ) ; } }
Inject custom Asset package to Kernel assets helper
3,104
public function getRows ( EntityDescriptor $ ed ) { $ r = array ( ) ; foreach ( $ ed -> getFieldsName ( ) as $ field ) { $ r += $ this -> getErrorsForField ( $ ed , $ field ) ; } return array_unique ( $ r ) ; }
Get all exception string this entity could generate
3,105
public function getErrorsForField ( EntityDescriptor $ ed , $ field ) { $ r = array ( ) ; foreach ( static :: $ testedValues as $ value ) { try { $ ed -> validateFieldValue ( $ field , $ value ) ; } catch ( InvalidFieldException $ e ) { $ r [ $ e -> getKey ( ) ] = $ e ; } } return $ r ; }
Get all exception this field could generate
3,106
public function all ( ) : array { $ result = [ ] ; foreach ( $ this -> headers as $ header ) { $ result [ $ header -> getName ( ) ] = $ header -> getValuesAsArray ( ) ; } return $ result ; }
Returns all values of all headers as array indexed by header name .
3,107
public function get ( string $ name , $ default = null ) { $ key = strtolower ( $ name ) ; if ( ! array_key_exists ( $ key , $ this -> headers ) ) { return $ default ; } return $ this -> headers [ $ key ] -> getValuesAsString ( ) ; }
Returns the value of a header as string .
3,108
public function getValues ( string $ name , array $ default = [ ] ) : array { $ key = strtolower ( $ name ) ; if ( ! array_key_exists ( $ key , $ this -> headers ) ) { return $ default ; } return $ this -> headers [ $ key ] -> getValuesAsArray ( ) ; }
Returns the value of a header as an array .
3,109
public function set ( string $ name , $ value , bool $ replace = true ) { $ key = strtolower ( $ name ) ; if ( $ replace || ! array_key_exists ( $ key , $ this -> headers ) ) { $ this -> headers [ $ key ] = new Header ( $ name , $ value ) ; } else { $ this -> headers [ $ key ] -> addValue ( $ value ) ; } }
Sets the value of a header .
3,110
protected function parseHeader ( $ relation , $ default = false ) { if ( false !== $ this -> header ) { $ attributes = explode ( '.' , $ this -> header ) ; foreach ( $ attributes as $ attribute ) { if ( isset ( $ relation -> { $ attribute } ) ) { $ relation = $ relation -> { $ attribute } ; } } } if ( ! is_string ( $ relation ) ) { if ( $ default !== false ) { return $ default ; } return $ relation -> primaryKey ; } return $ relation ; }
Parses and retrieves header based on given template
3,111
public function validate ( $ subject ) : bool { if ( \ is_array ( $ this -> schema [ 'dependencies' ] ) && count ( $ this -> schema [ 'dependencies' ] ) > 0 ) { foreach ( $ this -> schema [ 'dependencies' ] as $ propertyName => $ dependentProperties ) { if ( \ is_int ( \ array_keys ( $ dependentProperties ) [ 0 ] ) ) { if ( ! $ this -> validateClassicDependencies ( $ subject , $ propertyName , $ dependentProperties ) ) { return false ; } } elseif ( \ is_string ( \ array_keys ( $ dependentProperties ) [ 0 ] ) ) { if ( ! $ this -> validateSchemaDependencies ( $ subject , $ propertyName , $ dependentProperties ) ) { return false ; } } } } return true ; }
Validates subject against dependencies
3,112
private function validateClassicDependencies ( array $ subject , string $ propertyName , array $ dependentProperties ) : bool { if ( \ is_string ( $ propertyName ) && \ is_array ( $ dependentProperties ) ) { if ( \ array_key_exists ( $ propertyName , $ subject ) ) { foreach ( $ dependentProperties as $ propertyName ) { if ( \ is_string ( $ propertyName ) && ! \ array_key_exists ( $ propertyName , $ subject ) ) { return false ; } } } } return true ; }
Checks classic dependencies
3,113
private function validateSchemaDependencies ( array $ subject , string $ propertyName , array $ dependencySchema ) : bool { if ( \ is_string ( $ propertyName ) && \ is_array ( $ dependencySchema ) ) { if ( \ array_key_exists ( $ propertyName , $ subject ) ) { $ dependencySchema [ 'type' ] = 'object' ; $ nodeValidator = new NodeValidator ( $ dependencySchema , $ this -> rootSchema ) ; if ( ! $ nodeValidator -> validate ( $ subject ) ) { return false ; } } } return true ; }
Checks schema dependencies
3,114
public function set_config ( $ key , $ value ) { \ Arr :: set ( $ this -> config , $ key , $ value ) ; return $ this ; }
Set a driver config setting .
3,115
public function html_body ( $ html , $ generate_alt = null , $ auto_attach = null ) { $ this -> config [ 'is_html' ] = true ; $ generate_alt = is_bool ( $ generate_alt ) ? $ generate_alt : $ this -> config [ 'generate_alt' ] ; $ auto_attach = is_bool ( $ auto_attach ) ? $ auto_attach : $ this -> config [ 'auto_attach' ] ; $ remove_html_comments = ! empty ( $ this -> config [ 'remove_html_comments' ] ) ? $ this -> config [ 'remove_html_comments' ] : true ; if ( $ remove_html_comments ) { $ html = preg_replace ( '/<!--(.*) , '' , ( string ) $ html ) ; } if ( $ auto_attach ) { preg_match_all ( "/(src|background)=\"(.*)\"/Ui" , $ html , $ images ) ; if ( ! empty ( $ images [ 2 ] ) ) { foreach ( $ images [ 2 ] as $ i => $ image_url ) { if ( ! preg_match ( '/(^http\:\/\/|^https\:\/\/|^\/\/|^cid\:|^data\:|^#)/Ui' , $ image_url ) ) { $ cid = 'cid:' . md5 ( pathinfo ( $ image_url , PATHINFO_BASENAME ) ) ; if ( ! isset ( $ this -> attachments [ 'inline' ] [ $ cid ] ) ) { $ this -> attach ( $ image_url , true , $ cid ) ; } $ html = preg_replace ( "/" . $ images [ 1 ] [ $ i ] . "=\"" . preg_quote ( $ image_url , '/' ) . "\"/Ui" , $ images [ 1 ] [ $ i ] . "=\"" . $ cid . "\"" , $ html ) ; } elseif ( $ scheme = $ this -> get_config ( 'relative_protocol_replacement' , false ) and strpos ( $ image_url , '//' ) === 0 ) { $ html = preg_replace ( "/" . $ images [ 1 ] [ $ i ] . "=\"" . preg_quote ( $ image_url , '/' ) . "\"/Ui" , $ images [ 1 ] [ $ i ] . "=\"" . $ scheme . substr ( $ image_url , 2 ) . "\"" , $ html ) ; } } } } $ this -> body = $ html ; $ generate_alt and $ this -> alt_body = static :: generate_alt ( $ html , $ this -> config [ 'wordwrap' ] , $ this -> config [ 'newline' ] ) ; return $ this ; }
Sets the html body and optionally a generated alt body .
3,116
public function subject ( $ subject ) { if ( $ this -> config [ 'encode_headers' ] ) { $ subject = $ this -> encode_mimeheader ( ( string ) $ subject ) ; } $ this -> subject = ( string ) $ subject ; return $ this ; }
Sets the message subject
3,117
public function from ( $ email , $ name = false ) { $ this -> config [ 'from' ] [ 'email' ] = ( string ) $ email ; $ this -> config [ 'from' ] [ 'name' ] = ( is_string ( $ name ) ) ? $ name : false ; if ( $ this -> config [ 'encode_headers' ] and $ this -> config [ 'from' ] [ 'name' ] ) { $ this -> config [ 'from' ] [ 'name' ] = $ this -> encode_mimeheader ( ( string ) $ this -> config [ 'from' ] [ 'name' ] ) ; } return $ this ; }
Sets the from address and name
3,118
protected function add_to_list ( $ list , $ email , $ name = false ) { if ( ! is_array ( $ email ) ) { $ email = ( is_string ( $ name ) ) ? array ( $ email => $ name ) : array ( $ email ) ; } foreach ( $ email as $ _email => $ name ) { if ( is_numeric ( $ _email ) ) { $ _email = $ name ; $ name = false ; } if ( $ this -> config [ 'encode_headers' ] and $ name ) { $ name = $ this -> encode_mimeheader ( $ name ) ; } $ this -> { $ list } [ $ _email ] = array ( 'name' => $ name , 'email' => $ _email , ) ; } }
Add to a recipients list .
3,119
protected function clear_list ( $ list ) { is_array ( $ list ) or $ list = array ( $ list ) ; foreach ( $ list as $ _list ) { $ this -> { $ _list } = array ( ) ; } }
Clear the a recipient list .
3,120
public function header ( $ header , $ value = null ) { if ( is_array ( $ header ) ) { foreach ( $ header as $ _header => $ _value ) { empty ( $ _value ) or $ this -> extra_headers [ $ _header ] = $ _value ; } } else { empty ( $ value ) or $ this -> extra_headers [ $ header ] = $ value ; } return $ this ; }
Sets custom headers .
3,121
protected function find_attachment ( $ file ) { foreach ( $ this -> get_config ( 'attach_paths' ) as $ path ) { if ( is_file ( $ path . $ file ) ) { return $ path . $ file ; } } throw new \ AttachmentNotFoundException ( 'Email attachment not found: ' . $ file ) ; }
Finds an attachment .
3,122
public function string_attach ( $ contents , $ filename , $ cid = null , $ inline = false , $ mime = null ) { $ disp = ( $ inline ) ? 'inline' : 'attachment' ; $ cid = empty ( $ cid ) ? 'cid:' . md5 ( $ filename ) : trim ( $ cid ) ; $ cid = strpos ( $ cid , 'cid:' ) === 0 ? $ cid : 'cid:' . $ cid ; $ mime or $ mime = static :: attachment_mime ( $ filename ) ; $ this -> attachments [ $ disp ] [ $ cid ] = array ( 'file' => array ( 1 => $ filename ) , 'contents' => static :: encode_string ( $ contents , 'base64' , $ this -> config [ 'newline' ] ) , 'mime' => $ mime , 'disp' => $ disp , 'cid' => $ cid , ) ; return $ this ; }
Attach a file using string input
3,123
protected static function attachment_mime ( $ file ) { static $ mimes = false ; if ( ! $ mimes ) { $ mimes = \ Config :: load ( 'mimes' ) ; } $ ext = pathinfo ( $ file , PATHINFO_EXTENSION ) ; $ mime = \ Arr :: get ( $ mimes , $ ext , 'application/octet-stream' ) ; is_array ( $ mime ) and $ mime = reset ( $ mime ) ; return $ mime ; }
Get the mimetype for an attachment
3,124
protected function validate_addresses ( ) { $ failed = array ( ) ; foreach ( array ( 'to' , 'cc' , 'bcc' ) as $ list ) { foreach ( $ this -> { $ list } as $ recipient ) { if ( ! filter_var ( $ recipient [ 'email' ] , FILTER_VALIDATE_EMAIL ) ) { $ failed [ $ list ] [ ] = $ recipient ; } } } if ( count ( $ failed ) === 0 ) { return true ; } return $ failed ; }
Validates all the email addresses .
3,125
protected function set_boundaries ( ) { $ uniq_id = md5 ( uniqid ( microtime ( true ) ) ) ; $ this -> boundaries [ 0 ] = 'B1_' . $ uniq_id ; $ this -> boundaries [ 1 ] = 'B2_' . $ uniq_id ; $ this -> boundaries [ 2 ] = 'B3_' . $ uniq_id ; }
Sets unique message boundaries
3,126
protected function get_header ( $ header = null , $ formatted = true ) { if ( $ header === null ) { return $ this -> headers ; } if ( array_key_exists ( $ header , $ this -> headers ) ) { $ prefix = ( $ formatted ) ? $ header . ': ' : '' ; $ suffix = ( $ formatted ) ? $ this -> config [ 'newline' ] : '' ; return $ prefix . $ this -> headers [ $ header ] . $ suffix ; } return '' ; }
Gets the header
3,127
protected function encode_mimeheader ( $ header ) { $ transfer_encoding = ( $ this -> config [ 'encoding' ] === 'quoted-printable' ) ? 'Q' : 'B' ; return mb_encode_mimeheader ( $ header , $ this -> config [ 'charset' ] , $ transfer_encoding , $ this -> config [ 'newline' ] ) ; }
Encodes a mimeheader .
3,128
protected function get_attachment_headers ( $ type , $ boundary ) { $ return = '' ; $ newline = $ this -> config [ 'newline' ] ; foreach ( $ this -> attachments [ $ type ] as $ attachment ) { $ return .= '--' . $ boundary . $ newline ; $ return .= 'Content-Type: ' . $ attachment [ 'mime' ] . '; name="' . $ attachment [ 'file' ] [ 1 ] . '"' . $ newline ; $ return .= 'Content-Transfer-Encoding: base64' . $ newline ; $ type === 'inline' and $ return .= 'Content-ID: <' . substr ( $ attachment [ 'cid' ] , 4 ) . '>' . $ newline ; $ return .= 'Content-Disposition: ' . $ type . '; filename="' . $ attachment [ 'file' ] [ 1 ] . '"' . $ newline . $ newline ; $ return .= $ attachment [ 'contents' ] . $ newline . $ newline ; } return $ return ; }
Get the attachment headers
3,129
protected function get_mail_type ( ) { $ return = $ this -> config [ 'is_html' ] ? 'html' : 'plain' ; $ alt = trim ( $ this -> alt_body ) ; $ return .= ( $ this -> config [ 'is_html' ] and ! empty ( $ alt ) ) ? '_alt' : '' ; $ return .= ( $ this -> config [ 'is_html' ] and count ( $ this -> attachments [ 'inline' ] ) ) ? '_inline' : '' ; $ return .= ( count ( $ this -> attachments [ 'attachment' ] ) ) ? '_attach' : '' ; return $ return ; }
Returns the mail s type
3,130
protected function get_content_type ( $ mail_type , $ boundary ) { $ related = $ this -> config [ 'force_mixed' ] ? 'multipart/mixed; ' : 'multipart/related; ' ; switch ( $ mail_type ) { case 'plain' : return 'text/plain' ; case 'plain_attach' : case 'html_attach' : return $ related . $ boundary ; case 'html' : return 'text/html' ; case 'html_alt_attach' : case 'html_alt_inline_attach' : return 'multipart/mixed; ' . $ boundary ; case 'html_alt_inline' : case 'html_alt' : case 'html_inline' : return 'multipart/alternative; ' . $ boundary ; default : throw new \ FuelException ( 'Invalid content-type' . $ mail_type ) ; } }
Returns the content type
3,131
protected static function wrap_text ( $ message , $ length , $ newline , $ is_html = true ) { $ length = ( $ length > 76 ) ? 76 : $ length ; $ is_html and $ message = preg_replace ( '/[\r|\n|\t]/m' , '' , $ message ) ; $ message = wordwrap ( $ message , $ length , $ newline , false ) ; return $ message ; }
Wraps the body or alt text
3,132
protected static function prep_newlines ( $ string , $ newline = null ) { $ newline or $ newline = \ Config :: get ( 'email.defaults.newline' , "\n" ) ; $ replace = array ( "\r\n" => "\n" , "\n\r" => "\n" , "\r" => "\n" , "\n" => $ newline , ) ; foreach ( $ replace as $ from => $ to ) { $ string = str_replace ( $ from , $ to , $ string ) ; } return $ string ; }
Standardize newlines .
3,133
protected static function encode_string ( $ string , $ encoding , $ newline = null ) { $ newline or $ newline = \ Config :: get ( 'email.defaults.newline' , "\n" ) ; switch ( $ encoding ) { case 'quoted-printable' : return quoted_printable_encode ( $ string ) ; case '7bit' : case '8bit' : return static :: prep_newlines ( rtrim ( $ string , $ newline ) , $ newline ) ; case 'base64' : return chunk_split ( base64_encode ( $ string ) , 76 , $ newline ) ; default : throw new \ InvalidEmailStringEncoding ( $ encoding . ' is not a supported encoding method.' ) ; } }
Encodes a string in the given encoding .
3,134
protected static function format_addresses ( $ addresses ) { $ return = array ( ) ; foreach ( $ addresses as $ recipient ) { $ recipient [ 'name' ] and $ recipient [ 'email' ] = '"' . $ recipient [ 'name' ] . '" <' . $ recipient [ 'email' ] . '>' ; $ return [ ] = $ recipient [ 'email' ] ; } return join ( ', ' , $ return ) ; }
Returns a formatted string of email addresses .
3,135
protected static function generate_alt ( $ html , $ wordwrap , $ newline ) { $ html = preg_replace ( '/[ | ]{2,}/m' , ' ' , $ html ) ; $ html = trim ( strip_tags ( preg_replace ( '/<(head|title|style|script)[^>]*>.*?<\/\\1>/s' , '' , $ html ) ) ) ; $ lines = explode ( $ newline , $ html ) ; $ result = array ( ) ; $ first_newline = true ; foreach ( $ lines as $ line ) { $ line = trim ( $ line ) ; if ( ! empty ( $ line ) or $ first_newline ) { $ first_newline = false ; $ result [ ] = $ line ; } else { $ first_newline = true ; } } $ html = join ( $ newline , $ result ) ; if ( ! $ wordwrap ) { return $ html ; } return wordwrap ( $ html , $ wordwrap , $ newline , true ) ; }
Generates an alt body
3,136
public function selectChild ( $ name ) { if ( isset ( $ this -> stack [ $ this -> index ] -> value [ $ name ] ) === false ) { return false ; } $ this -> stack [ $ this -> index + 1 ] = ( object ) [ 'key' => $ name , 'value' => & $ this -> stack [ $ this -> index ] -> value [ $ name ] ] ; $ this -> index ++ ; return true ; }
Select a child of the current context by name .
3,137
public static function forge ( $ name = 'default' , array $ config = array ( ) ) { if ( $ exists = static :: instance ( $ name ) ) { \ Error :: notice ( 'Fieldset with this name exists already, cannot be overwritten.' ) ; return $ exists ; } static :: $ _instances [ $ name ] = new static ( $ name , $ config ) ; if ( $ name == 'default' ) { static :: $ _instance = static :: $ _instances [ $ name ] ; } return static :: $ _instances [ $ name ] ; }
Create Fieldset object
3,138
public function validation ( $ instance = true ) { if ( $ instance instanceof Validation ) { $ this -> validation = $ instance ; return $ instance ; } if ( empty ( $ this -> validation ) and $ instance === true ) { $ this -> validation = \ Validation :: forge ( $ this ) ; } return $ this -> validation ; }
Get related Validation instance or create it
3,139
public function form ( $ instance = true ) { if ( $ instance instanceof Form ) { $ this -> form = $ instance ; return $ instance ; } if ( empty ( $ this -> form ) and $ instance === true ) { $ this -> form = \ Form :: forge ( $ this ) ; } return $ this -> form ; }
Get related Form instance or create it
3,140
public function set_parent ( Fieldset $ fieldset ) { if ( ! empty ( $ this -> fieldset_parent ) ) { throw new \ RuntimeException ( 'Fieldset already has a parent, belongs to "' . $ this -> parent ( ) -> name . '".' ) ; } $ children = $ fieldset -> children ( ) ; while ( $ child = array_shift ( $ children ) ) { if ( $ child === $ this ) { throw new \ RuntimeException ( 'Circular reference detected, adding a Fieldset that\'s already a child as a parent.' ) ; } $ children = array_merge ( $ child -> children ( ) , $ children ) ; } $ this -> fieldset_parent = $ fieldset ; $ fieldset -> add_child ( $ this ) ; return $ this ; }
Set the parent Fieldset instance
3,141
protected function add_child ( Fieldset $ fieldset ) { if ( is_null ( $ fieldset -> fieldset_tag ) ) { $ fieldset -> fieldset_tag = 'fieldset' ; } $ this -> fieldset_children [ $ fieldset -> name ] = $ fieldset ; return $ this ; }
Add a child Fieldset instance
3,142
public function add ( $ name , $ label = '' , array $ attributes = array ( ) , array $ rules = array ( ) ) { if ( $ name instanceof Fieldset_Field ) { if ( $ name -> name == '' or $ this -> field ( $ name -> name ) !== false ) { throw new \ RuntimeException ( 'Fieldname empty or already exists in this Fieldset: "' . $ name -> name . '".' ) ; } $ name -> set_fieldset ( $ this ) ; $ this -> fields [ $ name -> name ] = $ name ; return $ name ; } elseif ( $ name instanceof Fieldset ) { if ( empty ( $ name -> name ) or $ this -> field ( $ name -> name ) !== false ) { throw new \ RuntimeException ( 'Fieldset name empty or already exists in this Fieldset: "' . $ name -> name . '".' ) ; } $ name -> set_parent ( $ this ) ; $ this -> fields [ $ name -> name ] = $ name ; return $ name ; } if ( empty ( $ name ) || ( is_array ( $ name ) and empty ( $ name [ 'name' ] ) ) ) { throw new \ InvalidArgumentException ( 'Cannot create field without name.' ) ; } if ( is_array ( $ name ) ) { $ attributes = $ name ; $ label = isset ( $ name [ 'label' ] ) ? $ name [ 'label' ] : '' ; $ rules = isset ( $ name [ 'rules' ] ) ? $ name [ 'rules' ] : array ( ) ; $ name = $ name [ 'name' ] ; } if ( $ field = $ this -> field ( $ name ) ) { \ Error :: notice ( 'Field with this name exists already in this fieldset: "' . $ name . '".' ) ; return $ field ; } $ this -> fields [ $ name ] = new \ Fieldset_Field ( $ name , $ label , $ attributes , $ rules , $ this ) ; return $ this -> fields [ $ name ] ; }
Factory for Fieldset_Field objects
3,143
public function add_before ( $ name , $ label = '' , array $ attributes = array ( ) , array $ rules = array ( ) , $ fieldname = null ) { $ field = $ this -> add ( $ name , $ label , $ attributes , $ rules ) ; unset ( $ this -> fields [ $ field -> name ] ) ; if ( ! \ Arr :: insert_before_key ( $ this -> fields , array ( $ field -> name => $ field ) , $ fieldname , true ) ) { throw new \ RuntimeException ( 'Field "' . $ fieldname . '" does not exist in this Fieldset. Field "' . $ name . '" can not be added.' ) ; } return $ field ; }
Add a new Fieldset_Field before an existing field in a Fieldset
3,144
public function add_after ( $ name , $ label = '' , array $ attributes = array ( ) , array $ rules = array ( ) , $ fieldname = null ) { $ field = $ this -> add ( $ name , $ label , $ attributes , $ rules ) ; unset ( $ this -> fields [ $ field -> name ] ) ; if ( ! \ Arr :: insert_after_key ( $ this -> fields , array ( $ field -> name => $ field ) , $ fieldname , true ) ) { throw new \ RuntimeException ( 'Field "' . $ fieldname . '" does not exist in this Fieldset. Field "' . $ name . '" can not be added.' ) ; } return $ field ; }
Add a new Fieldset_Field after an existing field in a Fieldset
3,145
public function delete ( $ name ) { if ( isset ( $ this -> field [ $ name ] ) ) { unset ( $ this -> field [ $ name ] ) ; } return $ this ; }
Delete a field instance
3,146
public function field ( $ name = null , $ flatten = false , $ tabular_form = true ) { if ( $ name === null ) { $ fields = $ this -> fields ; if ( $ flatten ) { foreach ( $ this -> fieldset_children as $ fs_name => $ fieldset ) { if ( $ tabular_form or ! $ fieldset -> get_tabular_form ( ) ) { \ Arr :: insert_after_key ( $ fields , $ fieldset -> field ( null , true ) , $ fs_name ) ; } unset ( $ fields [ $ fs_name ] ) ; } } return $ fields ; } if ( ! array_key_exists ( $ name , $ this -> fields ) ) { if ( $ flatten ) { foreach ( $ this -> fieldset_children as $ fieldset ) { if ( ( $ field = $ fieldset -> field ( $ name ) ) !== false ) { return $ field ; } } } return false ; } return $ this -> fields [ $ name ] ; }
Get Field instance
3,147
public function add_model ( $ class , $ instance = null , $ method = 'set_form_fields' ) { $ this -> validation ( ) -> add_callable ( $ class ) ; if ( ( is_string ( $ class ) and is_callable ( $ callback = array ( '\\' . $ class , $ method ) ) ) || is_callable ( $ callback = array ( $ class , $ method ) ) ) { $ instance ? call_user_func ( $ callback , $ this , $ instance ) : call_user_func ( $ callback , $ this ) ; } return $ this ; }
Add a model s fields The model must have a method set_form_fields that takes this Fieldset instance and adds fields to it .
3,148
public function populate ( $ input , $ repopulate = false ) { $ fields = $ this -> field ( null , true , false ) ; foreach ( $ fields as $ f ) { if ( is_array ( $ input ) or $ input instanceof \ ArrayAccess ) { $ name = str_replace ( array ( '[' , ']' ) , array ( '.' , '' ) , $ f -> name ) ; $ value = \ Arr :: get ( $ input , $ name , null ) ; $ value === null and $ value = \ Arr :: get ( $ input , $ f -> basename , null ) ; $ value !== null and $ f -> set_value ( $ value , true ) ; } elseif ( is_object ( $ input ) and property_exists ( $ input , $ f -> basename ) ) { $ f -> set_value ( $ input -> { $ f -> basename } , true ) ; } } if ( $ repopulate ) { $ this -> repopulate ( ) ; } return $ this ; }
Populate the form s values using an input array or object
3,149
public function build ( $ action = null ) { $ attributes = $ this -> get_config ( 'form_attributes' ) ; if ( $ action and ( $ this -> fieldset_tag == 'form' or empty ( $ this -> fieldset_tag ) ) ) { $ attributes [ 'action' ] = $ action ; } $ open = ( $ this -> fieldset_tag == 'form' or empty ( $ this -> fieldset_tag ) ) ? $ this -> form ( ) -> open ( $ attributes ) . PHP_EOL : $ this -> form ( ) -> { $ this -> fieldset_tag . '_open' } ( $ attributes ) ; $ fields_output = '' ; if ( $ this -> tabular_form_relation ) { $ properties = call_user_func ( $ this -> tabular_form_model . '::properties' ) ; $ primary_keys = call_user_func ( $ this -> tabular_form_model . '::primary_key' ) ; $ fields_output .= '<thead><tr>' . PHP_EOL ; foreach ( $ properties as $ field => $ settings ) { if ( ( isset ( $ settings [ 'skip' ] ) and $ settings [ 'skip' ] ) or in_array ( $ field , $ primary_keys ) ) { continue ; } if ( isset ( $ settings [ 'form' ] [ 'type' ] ) and ( $ settings [ 'form' ] [ 'type' ] === false or $ settings [ 'form' ] [ 'type' ] === 'hidden' ) ) { continue ; } $ fields_output .= "\t" . '<th class="' . $ this -> tabular_form_relation . '_col_' . $ field . '">' . ( isset ( $ settings [ 'label' ] ) ? \ Lang :: get ( $ settings [ 'label' ] , array ( ) , $ settings [ 'label' ] ) : '' ) . '</th>' . PHP_EOL ; } $ fields_output .= "\t" . '<th>' . \ Config :: get ( 'form.tabular_delete_label' , 'Delete?' ) . '</th>' . PHP_EOL ; $ fields_output .= '</tr></thead>' . PHP_EOL ; } foreach ( $ this -> field ( ) as $ f ) { in_array ( $ f -> name , $ this -> disabled ) or $ fields_output .= $ f -> build ( ) . PHP_EOL ; } $ close = ( $ this -> fieldset_tag == 'form' or empty ( $ this -> fieldset_tag ) ) ? $ this -> form ( ) -> close ( $ attributes ) . PHP_EOL : $ this -> form ( ) -> { $ this -> fieldset_tag . '_close' } ( $ attributes ) ; $ template = $ this -> form ( ) -> get_config ( ( empty ( $ this -> fieldset_tag ) ? 'form' : $ this -> fieldset_tag ) . '_template' , "\n\t\t{open}\n\t\t<table>\n{fields}\n\t\t</table>\n\t\t{close}\n" ) ; $ template = str_replace ( array ( '{form_open}' , '{open}' , '{fields}' , '{form_close}' , '{close}' ) , array ( $ open , $ open , $ fields_output , $ close , $ close ) , $ template ) ; return $ template ; }
Build the fieldset HTML
3,150
public function enable ( $ name = null ) { if ( ! $ this -> field ( $ name ) ) { throw new \ RuntimeException ( 'Field "' . $ name . '" does not exist in this Fieldset.' ) ; } if ( isset ( $ this -> disabled [ $ name ] ) ) { unset ( $ this -> disabled [ $ name ] ) ; } return $ this ; }
Enable a disabled field from being build
3,151
public function disable ( $ name = null ) { if ( ! $ this -> field ( $ name ) ) { throw new \ RuntimeException ( 'Field "' . $ name . '" does not exist in this Fieldset.' ) ; } isset ( $ this -> disabled [ $ name ] ) or $ this -> disabled [ $ name ] = $ name ; return $ this ; }
Disable a field from being build
3,152
public function signinAction ( Request $ request ) { try { $ data = $ this -> getAuthClientIdentifiers ( $ request ) ; extract ( $ data ) ; if ( ! ( ( $ client = $ this -> clientProvider -> getClient ( $ client_id ) ) && $ this -> clientProvider -> isValid ( $ client , $ redirect_uri ) ) ) { throw new SoauthException ( sprintf ( 'No client found with id %s' , $ client_id ) ) ; } $ data [ 'client' ] = $ client ; $ this -> info ( '> Sign in request' , [ 'method' => $ request -> getMethod ( ) , 'query' => $ data ] ) ; $ response = new Response ( $ this -> renderer -> renderSignInForm ( $ data ) ) ; } catch ( BadDataException $ e ) { $ this -> error ( 'Bad Data Exception: ' . $ e -> getMessage ( ) , [ 'errors' => $ e -> getErrors ( ) , 'exception' => $ e ] ) ; $ response = $ this -> getBadRequestResponse ( ) ; } catch ( SoauthException $ e ) { $ this -> error ( 'Soauth Exception: ' . $ e -> getMessage ( ) , [ 'exception' => $ e ] ) ; $ response = $ this -> getBadRequestResponse ( ) ; } $ this -> info ( '< Response' , [ 'status_code' => $ response -> getStatusCode ( ) ] ) ; return $ response ; }
verify authentication request and display entry point to authenticate
3,153
public function generate ( ) { $ alphabetLastIndex = strlen ( $ this -> alphabet ) - 1 ; $ code = '' ; for ( $ i = 0 ; $ i < $ this -> length ; $ i ++ ) { $ code .= $ this -> alphabet [ rand ( 0 , $ alphabetLastIndex ) ] ; } return $ code ; }
Returns pseudo - random code consisting of this generator alphabet letters and it s length
3,154
public static function EndsWithValidTldString ( string & $ stringToCheck , bool $ convertUniCode = false ) : bool { if ( $ convertUniCode ) { $ stringToCheck = idnToASCII ( $ stringToCheck ) ; } return ( bool ) \ preg_match ( '~\.(' . static :: DOUBLE_TLDS . '|' . static :: KNOWN_FORMAT . ')\.?$~i' , $ stringToCheck ) ; }
Returns if the defined string ends with a substring defined by characters usable as a TLD .
3,155
public function getModelPersister ( $ modelName ) { if ( ! isset ( $ this -> persisters [ $ modelName ] ) ) { $ class = $ this -> manager -> getClassMetadata ( $ modelName ) ; $ this -> persisters [ $ modelName ] = new ModelPersister ( $ this -> manager , $ this , $ class ) ; } return $ this -> persisters [ $ modelName ] ; }
Get the multi - model persister instance for the given multi - model name .
3,156
protected function saveSpecificModel ( $ model , $ managerName , $ id ) { $ class = $ this -> manager -> getClassMetadata ( get_class ( $ model ) ) ; $ pool = $ this -> manager -> getPool ( ) ; $ modelManager = call_user_func ( array ( $ model , 'get' . ucfirst ( $ managerName ) ) ) ; call_user_func ( array ( $ modelManager , 'set' . ucfirst ( $ class -> getIdentifierReference ( $ managerName ) -> referenceField ) ) , $ id ) ; try { $ pool -> getManager ( $ managerName ) -> persist ( $ modelManager ) ; $ pool -> getManager ( $ managerName ) -> flush ( ) ; } catch ( \ Exception $ e ) { throw new \ RuntimeException ( sprintf ( 'Error : %s WITH Model %s and manager %s' , $ e -> getMessage ( ) , $ managerName , get_class ( $ modelManager ) ) ) ; } }
Persist a model his manager doctrine .
3,157
public function Gdn_Dispatcher_AfterAnalyzeRequest_Handler ( $ Sender ) { if ( in_array ( $ Sender -> Application ( ) , array ( 'vanilla' , 'conversations' ) ) || ( $ Sender -> Application ( ) == 'dashboard' && in_array ( $ Sender -> Controller ( ) , array ( 'Activity' , 'Profile' , 'Search' ) ) ) ) { Gdn :: PluginManager ( ) -> RemoveMobileUnfriendlyPlugins ( ) ; } SaveToConfig ( 'Garden.Format.EmbedSize' , '240x135' , FALSE ) ; }
Remove plugins that are not mobile friendly!
3,158
public function Base_Render_Before ( $ Sender ) { if ( IsMobile ( ) && is_object ( $ Sender -> Head ) ) { $ Sender -> Head -> AddTag ( 'meta' , array ( 'name' => 'viewport' , 'content' => "width=device-width,minimum-scale=1.0,maximum-scale=1.0" ) ) ; $ Sender -> Head -> AddString ( '<script type="text/javascript"> // If not looking for a specific comment, hide the address bar in iphone var hash = window.location.href.split("#")[1]; if (typeof(hash) == "undefined") { setTimeout(function () { window.scrollTo(0, 1); }, 1000); }</script>' ) ; } }
Add mobile meta info . Add script to hide iPhone browser bar on pageload .
3,159
private function DiscussionsClickable ( $ Sender ) { if ( property_exists ( $ Sender , 'Head' ) && is_object ( $ Sender -> Head ) ) { $ Sender -> Head -> AddString ( '<script type="text/javascript"> jQuery(document).ready(function($) { $("ul.DataList li.Item").click(function() { var href = $(this).find(".Title a").attr("href"); if (typeof href != "undefined") document.location = href; }); });</script>' ) ; } }
Increases clickable area on a discussions list .
3,160
public function startBar ( $ originalTable , $ newTable , $ collection , $ new = false ) { static $ even = false ; $ this -> bar = $ this -> output -> createProgressBar ( count ( $ collection ) ) ; $ this -> setUpLabel ( $ originalTable , $ newTable , $ new , $ even ) ; $ even = ! $ even ; }
Set up the bar and the label .
3,161
private function setUpLabel ( $ originalTable , $ newTable , $ new , $ even ) { $ bgColor = $ this -> getRowColor ( $ even ) ; $ new = $ new ? '<fg=green;bg=' . $ bgColor . '>NEW</> ' : '' ; $ name = $ originalTable . ' -> ' . $ newTable ; $ tabs = $ this -> getTabs ( $ name , $ new ) ; $ label = '<fg=black;bg=' . $ bgColor . ';options=bold>' . $ new . $ name . $ tabs . '</>' ; $ this -> bar -> setFormat ( $ label . ' %current:6s%/%max:-6s% [%bar%] %percent:3s%%' ) ; }
Set up the format for the progress bar .
3,162
private function getTabs ( $ string , $ new ) { $ length = strlen ( $ string ) ; $ max = $ new ? 56 : 60 ; $ range = range ( 1 , $ max - $ length ) ; $ tabs = '' ; foreach ( $ range as $ item ) { $ tabs .= " " ; } return $ tabs ; }
Determine the spacing needed after the label for the bars to appear in line .
3,163
public function save ( $ object ) { if ( is_array ( $ object ) ) { $ objectData = $ object ; if ( isset ( $ object [ 'id' ] ) && $ object [ 'id' ] > 0 ) { $ object = $ this -> find ( $ object [ 'id' ] ) ; } else { $ object = new Forum ( ) ; } if ( isset ( $ objectData [ 'parent' ] ) ) { $ parent = $ this -> find ( $ objectData [ 'parent' ] ) ; if ( $ parent ) { $ object -> setParent ( $ parent ) ; } unset ( $ objectData [ 'parent' ] ) ; } $ this -> assignArrayToObject ( $ object , $ objectData ) ; } else if ( ! ( $ object instanceof Forum ) ) { $ this -> addErrorMessage ( self :: ERROR_WRONG_OBJECT ) ; } if ( ! $ this -> hasError ( ) ) { $ check = $ this -> forumManager -> update ( $ object ) ; if ( $ check === true ) { $ this -> addSuccessMessage ( self :: SUCCESS_SAVED ) ; } } return $ object ; }
save a Forum you can pass the Site object or an array with the fields if you pass an array the keys must be with underscore and not with CamelCase
3,164
public function Base_AfterReactions_Handler ( $ Sender , $ Args ) { if ( ! $ this -> SocialReactions ( ) ) return ; echo Gdn_Theme :: BulletItem ( 'Share' ) ; $ this -> AddReactButton ( $ Sender , $ Args ) ; }
Add Facebook option to the row .
3,165
protected function AddReactButton ( $ Sender , $ Args ) { if ( $ this -> AccessToken ( ) ) { $ CssClass = 'ReactButton Hijack' ; } else { $ CssClass = 'ReactButton PopupWindow' ; } echo ' ' . Anchor ( Sprite ( 'ReactFacebook' , 'ReactSprite' ) , Url ( "post/facebook/{$Args['RecordType']}?id={$Args['RecordID']}" , TRUE ) , $ CssClass ) . ' ' ; }
Output Quote link .
3,166
public function registerHandler ( string $ queryClass , string $ serviceName ) : void { if ( ! Validate :: implementsInterface ( $ queryClass , Query :: class ) ) { $ message = sprintf ( 'Invalid query class: %s' , $ queryClass ) ; throw new DomainException ( $ message ) ; } $ type = Type :: create ( $ queryClass ) -> toString ( ) ; $ this -> handlers [ $ type ] = $ serviceName ; }
Registers a query handler
3,167
private function resolveFilename ( $ file ) { if ( empty ( $ file ) ) { return null ; } if ( ( $ file instanceof UploadedFileInterface && $ file -> getError ( ) === 0 ) || $ file instanceof StreamableInterface ) { return StreamWrapper :: getFilename ( $ file -> getStream ( ) ) ; } if ( is_array ( $ file ) ) { if ( ! isset ( $ file [ 'tmp_name' ] ) ) { return null ; } $ file = $ file [ 'tmp_name' ] ; } if ( ! is_string ( $ file ) || ! $ this -> files -> exists ( $ file ) ) { return null ; } return $ file ; }
Internal method to fetch filename using multiple input formats .
3,168
private function isUploaded ( $ file ) : bool { if ( is_string ( $ file ) ) { return is_uploaded_file ( $ file ) ; } if ( is_array ( $ file ) ) { return isset ( $ file [ 'tmp_name' ] ) && ( is_uploaded_file ( $ file [ 'tmp_name' ] ) || isset ( $ file [ 'uploaded' ] ) ) ; } if ( $ file instanceof UploadedFileInterface ) { return empty ( $ file -> getError ( ) ) ; } return false ; }
Check if file being uploaded .
3,169
public function findSupportedModelTransformer ( $ object , $ targetClass , ContextInterface $ context = null ) { if ( is_object ( $ object ) && ( $ objectTransformer = $ this -> findSupportedObjectTransformer ( get_class ( $ object ) , $ targetClass ) ) ) { return $ objectTransformer ; } foreach ( $ this -> getModelTransformers ( ) as $ modelTransformer ) { if ( ( $ modelTransformer instanceof ContextualModelTransformerInterface ) && $ modelTransformer -> supports ( $ object , $ targetClass , $ context ) ) { return $ modelTransformer ; } if ( ( $ modelTransformer instanceof ModelTransformerInterface ) && $ modelTransformer -> supports ( $ object , $ targetClass ) ) { return $ modelTransformer ; } if ( $ modelTransformer instanceof ObjectTransformerInterface ) { continue ; } } return null ; }
Finds and returns model transformer which supports specified object and target class .
3,170
private function findSupportedObjectTransformer ( $ supportedClass , $ targetClass ) { $ objectTransformers = $ this -> getObjectTransformers ( ) ; if ( isset ( $ objectTransformers [ $ supportedClass ] ) && isset ( $ objectTransformers [ $ supportedClass ] [ $ targetClass ] ) ) { return $ objectTransformers [ $ supportedClass ] [ $ targetClass ] ; } $ supportedReflectionClass = new \ ReflectionClass ( $ supportedClass ) ; if ( $ supportedReflectionClass -> getParentClass ( ) && ( $ objectTransformer = $ this -> findSupportedObjectTransformer ( $ supportedReflectionClass -> getParentClass ( ) -> getName ( ) , $ targetClass ) ) ) { return $ objectTransformer ; } $ targetReflectionClass = new \ ReflectionClass ( $ targetClass ) ; if ( $ targetReflectionClass -> getParentClass ( ) && ( $ objectTransformer = $ this -> findSupportedObjectTransformer ( $ supportedClass , $ targetReflectionClass -> getParentClass ( ) -> getName ( ) ) ) ) { return $ objectTransformer ; } return null ; }
Tries to find supported object transformer .
3,171
public static function json ( $ index = null , $ default = null ) { static :: $ json === null and static :: hydrate_raw_input ( 'json' ) ; return ( func_num_args ( ) === 0 ) ? static :: $ json : \ Arr :: get ( static :: $ json , $ index , $ default ) ; }
Get the request body interpreted as JSON .
3,172
public static function xml ( $ index = null , $ default = null ) { static :: $ xml === null and static :: hydrate_raw_input ( 'xml' ) ; return ( func_num_args ( ) === 0 ) ? static :: $ xml : \ Arr :: get ( static :: $ xml , $ index , $ default ) ; }
Get the request body interpreted as XML .
3,173
public static function real_ip ( $ default = '0.0.0.0' , $ exclude_reserved = false ) { static $ server_keys = null ; if ( empty ( $ server_keys ) ) { $ server_keys = array ( 'HTTP_CLIENT_IP' , 'REMOTE_ADDR' ) ; if ( \ Config :: get ( 'security.allow_x_headers' , false ) ) { $ server_keys = array_merge ( array ( 'HTTP_X_CLUSTER_CLIENT_IP' , 'HTTP_X_FORWARDED_FOR' ) , $ server_keys ) ; } } foreach ( $ server_keys as $ key ) { if ( ! static :: server ( $ key ) ) { continue ; } $ ips = explode ( ',' , static :: server ( $ key ) ) ; array_walk ( $ ips , function ( & $ ip ) { $ ip = trim ( $ ip ) ; } ) ; $ ips = array_filter ( $ ips , function ( $ ip ) use ( $ exclude_reserved ) { return filter_var ( $ ip , FILTER_VALIDATE_IP , $ exclude_reserved ? FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE : null ) ; } ) ; if ( $ ips ) { return reset ( $ ips ) ; } } return \ Fuel :: value ( $ default ) ; }
Get the real ip address of the user . Even if they are using a proxy .
3,174
public static function protocol ( ) { if ( static :: server ( 'HTTPS' ) == 'on' or static :: server ( 'HTTPS' ) == 1 or static :: server ( 'SERVER_PORT' ) == 443 or ( \ Config :: get ( 'security.allow_x_headers' , false ) and static :: server ( 'HTTP_X_FORWARDED_PROTO' ) == 'https' ) or ( \ Config :: get ( 'security.allow_x_headers' , false ) and static :: server ( 'HTTP_X_FORWARDED_PORT' ) == 443 ) ) { return 'https' ; } return 'http' ; }
Return s the protocol that the request was made with
3,175
public static function get ( $ index = null , $ default = null ) { return ( func_num_args ( ) === 0 ) ? $ _GET : \ Arr :: get ( $ _GET , $ index , $ default ) ; }
Gets the specified GET variable .
3,176
public static function file ( $ index = null , $ default = null ) { return ( func_num_args ( ) === 0 ) ? $ _FILES : \ Arr :: get ( $ _FILES , $ index , $ default ) ; }
Fetch an item from the FILE array
3,177
public static function param ( $ index = null , $ default = null ) { static :: $ input === null and static :: hydrate ( ) ; return \ Arr :: get ( static :: $ input , $ index , $ default ) ; }
Fetch an item from either the GET POST PUT PATCH or DELETE array
3,178
public static function server ( $ index = null , $ default = null ) { return ( func_num_args ( ) === 0 ) ? $ _SERVER : \ Arr :: get ( $ _SERVER , strtoupper ( $ index ) , $ default ) ; }
Fetch an item from the SERVER array
3,179
public static function headers ( $ index = null , $ default = null ) { static $ headers = null ; if ( $ headers === null ) { if ( ! function_exists ( 'getallheaders' ) ) { $ server = \ Arr :: filter_prefixed ( static :: server ( ) , 'HTTP_' , true ) ; foreach ( $ server as $ key => $ value ) { $ key = join ( '-' , array_map ( 'ucfirst' , explode ( '_' , strtolower ( $ key ) ) ) ) ; $ headers [ $ key ] = $ value ; } $ value = static :: server ( 'Content_Type' , static :: server ( 'Content-Type' ) ) and $ headers [ 'Content-Type' ] = $ value ; $ value = static :: server ( 'Content_Length' , static :: server ( 'Content-Length' ) ) and $ headers [ 'Content-Length' ] = $ value ; } else { $ headers = getallheaders ( ) ; } } return empty ( $ headers ) ? $ default : ( ( func_num_args ( ) === 0 ) ? $ headers : \ Arr :: get ( $ headers , $ index , $ default ) ) ; }
Fetch a item from the HTTP request headers
3,180
protected static function hydrate ( ) { static :: $ input = array_merge ( $ _GET , $ _POST ) ; if ( \ Input :: method ( ) == 'PUT' or \ Input :: method ( ) == 'PATCH' or \ Input :: method ( ) == 'DELETE' ) { static :: $ php_input === null and static :: $ php_input = file_get_contents ( 'php://input' ) ; if ( strpos ( static :: headers ( 'Content-Type' ) , 'www-form-urlencoded' ) > 0 and \ Config :: get ( 'security.form-double-urlencoded' , false ) ) { static :: $ php_input = urldecode ( static :: $ php_input ) ; } parse_str ( static :: $ php_input , static :: $ put_patch_delete ) ; static :: $ input = array_merge ( static :: $ input , static :: $ put_patch_delete ) ; } else { static :: $ put_patch_delete = array ( ) ; } }
Hydrates the input array
3,181
public function all ( string $ identifier = '' ) : array { if ( $ identifier && ! $ this -> exists ( $ identifier ) ) { return [ ] ; } return $ identifier ? $ this -> menus [ $ identifier ] : $ this -> menus ; }
Get all registered menus .
3,182
public function register ( string $ identifier , $ title , string $ url = '' , array $ children = [ ] , array $ fields = [ ] ) : Menu { $ this -> menus [ $ identifier ] [ ] = $ this -> parseMenuItems ( $ title , $ url , $ children , $ fields ) ; return $ this ; }
Register a new menu .
3,183
public function build ( string $ identifier , callable $ items ) : Menu { $ builder = new Builder ( $ identifier ) ; $ items ( $ builder ) ; if ( isset ( $ this -> menus [ $ identifier ] ) ) { $ this -> menus [ $ identifier ] = array_merge ( $ this -> menus [ $ identifier ] , $ builder -> getMenu ( ) ) ; return $ this ; } $ this -> menus [ $ identifier ] = $ builder -> getMenu ( ) ; return $ this ; }
Build a complex menu .
3,184
public function count ( string $ identifier = '' ) : int { if ( $ identifier ) { return $ this -> countItems ( $ identifier ) ; } $ menus = $ this -> all ( ) ; $ counter = 0 ; foreach ( $ menus as $ identifier => $ menu ) { $ counter += $ this -> countItems ( $ identifier ) ; } return $ counter ; }
Count all registered menus and their elements .
3,185
public function toArray ( $ values = [ ] ) : array { if ( ! $ values ) { $ values = $ this -> all ( ) ; } $ array = [ ] ; if ( is_array ( $ values ) ) { foreach ( $ values as $ key => $ value ) { $ array [ $ key ] = is_array ( $ value ) ? $ this -> toArray ( $ value ) : $ value ; if ( is_object ( $ value ) ) { $ array [ $ key ] = [ 'title' => $ value -> title , 'url' => $ value -> url , 'children' => $ value -> children , 'fields' => $ value -> fields ] ; if ( $ value -> children ) { $ array [ $ key ] [ 'children' ] = $ this -> toArray ( $ value -> children ) ; } } } } return $ array ; }
Convert all registered menus to nested arrays .
3,186
private function countItems ( string $ identifier , array $ array = [ ] ) : int { if ( ! $ array ) { $ array = $ this -> toArray ( $ this -> all ( $ identifier ) ) ; $ counter = count ( $ array ) ; } else { $ counter = 0 ; } foreach ( $ array as $ value ) { $ counter += count ( $ value [ 'children' ] ) ; if ( $ value [ 'children' ] ) { $ counter += $ this -> countItems ( $ identifier , $ value [ 'children' ] ) ; } } return $ counter ; }
Count all specified menu s items including their child elements .
3,187
public function init ( ) { if ( $ this -> language === null ) { $ this -> language = App :: $ Request -> getLanguage ( ) ; } if ( $ this -> targetClass === null ) { $ this -> targetClass = 'wysiwyg' ; } if ( $ this -> config === null || ! Arr :: in ( $ this -> config , [ 'config-small' , 'config-full' , 'config-medium' ] ) ) { $ this -> config = 'config-default' ; } $ this -> baseUrl = App :: $ Alias -> scriptUrl . '/vendor/phpffcms/ffcms-ckeditor/assets' ; }
Pass init params
3,188
public function display ( ) { App :: $ Alias -> setCustomLibrary ( 'js' , $ this -> baseUrl . '/ckeditor.js' ) ; App :: $ Alias -> setCustomLibrary ( 'js' , $ this -> baseUrl . '/adapters/jquery.js' ) ; $ jsInitializeCode = "$('.{$this->targetClass}').ckeditor({" ; $ jsInitializeCode .= "language: '{$this->language}', customConfig: '{$this->config}.js', " ; if ( $ this -> jsConfig !== null && Any :: isArray ( $ this -> jsConfig ) ) { foreach ( $ this -> jsConfig as $ obj => $ value ) { $ jsInitializeCode .= $ obj . ": '" . $ value . "', " ; } } $ jsInitializeCode .= "});" ; App :: $ Alias -> addPlainCode ( 'js' , $ jsInitializeCode ) ; return null ; }
Add ckeditor library s to lazyload
3,189
public function getContentModules ( ) { return array_filter ( $ this -> getModules ( ) , function ( ModuleInterface $ module ) { return ! ( $ module instanceof AdministrationModuleInterface ) && ! ( $ module instanceof SubmoduleInterface ) ; } ) ; }
Get all modules that handle content .
3,190
public function getCategories ( ) { $ items = array ( array ( 'label' => Yii :: t ( 'ciims.models.theme' , 'All Posts' ) , 'url' => Yii :: app ( ) -> createUrl ( '/blog' ) ) ) ; $ categories = Yii :: app ( ) -> cache -> get ( 'CiiMS::Categories::list' ) ; if ( $ categories == false ) { $ criteria = new CDbCriteria ( ) ; $ criteria -> addCondition ( 'type_id = 2' ) -> addCondition ( 'status = 1' ) ; $ criteria -> with = 'content' ; $ criteria -> select = 't.id, t.slug, t.name' ; $ categories = Categories :: model ( ) -> findAll ( $ criteria ) ; Yii :: app ( ) -> cache -> set ( 'CiiMS::Categories::list' , $ categories ) ; } foreach ( $ categories as $ k => $ v ) { if ( $ v [ 'name' ] != 'Uncategorized' ) $ items [ ] = array ( 'label' => $ v -> name , 'url' => Yii :: app ( ) -> createUrl ( '/' . $ v -> slug ) ) ; } return $ items ; }
Retrieves all categories to display int he footer
3,191
public function getRecentPosts ( ) { $ items = array ( ) ; $ content = Yii :: app ( ) -> cache -> get ( 'CiiMS::Content::list' ) ; if ( $ content == false ) { $ criteria = Content :: model ( ) -> getBaseCriteria ( ) -> addCondition ( 'type_id = 2' ) -> addCondition ( 'password = ""' ) ; $ criteria -> order = 'published DESC' ; $ criteria -> limit = 5 ; $ content = Content :: model ( ) -> findAll ( $ criteria ) ; Yii :: app ( ) -> cache -> set ( 'CiiMS::Content::list' , $ content ) ; } foreach ( $ content as $ v ) $ items [ ] = array ( 'label' => $ v -> title , 'url' => Yii :: app ( ) -> createAbsoluteUrl ( $ v -> slug ) , 'itemOptions' => array ( 'id' => $ v -> id , 'published' => $ v -> published ) ) ; return $ items ; }
Retrieves the recent post items so that the view is cleaned up
3,192
public function getRelatedPosts ( $ id , $ category_id ) { $ items = array ( ) ; $ criteria = Content :: model ( ) -> getBaseCriteria ( ) -> addCondition ( 'category_id = :category_id' ) -> addCondition ( 'id != :id' ) -> addCondition ( 'type_id = 2' ) -> addCondition ( 'password = ""' ) ; $ criteria -> order = 'published DESC' ; $ criteria -> limit = 5 ; $ criteria -> params = array ( ':id' => $ id , ':category_id' => $ category_id ) ; $ related = Content :: model ( ) -> findAll ( $ criteria ) ; foreach ( $ related as $ v ) $ items [ ] = array ( 'label' => $ v -> title , 'url' => Yii :: app ( ) -> createAbsoluteUrl ( $ v -> slug ) , 'itemOptions' => array ( 'id' => $ v -> id , 'published' => $ v -> published ) ) ; return $ items ; }
Retrieves related posts to a given post
3,193
public function getContentTags ( $ id ) { $ items = array ( ) ; $ tags = Content :: model ( ) -> findByPk ( $ id ) -> getTags ( ) ; foreach ( $ tags as $ item ) $ items [ ] = array ( 'label' => $ item , 'url' => Yii :: app ( ) -> createUrl ( '/search?q=' . $ item ) ) ; return $ items ; }
Retrieves the tags for a particular article and flattens them to a pretty array
3,194
protected function setController ( ) { $ controller = null ; if ( is_file ( $ this -> getRootPath ( ) . 'controller/' . $ this -> getMethod ( ) . '/' . $ this -> getNameSpace ( ) . '_controller.php' ) ) { $ controller = $ this -> getRootPath ( ) . 'controller/' . $ this -> getMethod ( ) . '/' . $ this -> getNameSpace ( ) . '_controller.php' ; } else if ( is_file ( $ this -> getRootPath ( ) . 'controller/GET/' . $ this -> getNameSpace ( ) . '_controller.php' ) ) { $ controller = $ this -> getRootPath ( ) . 'controller/GET/' . $ this -> getNameSpace ( ) . '_controller.php' ; } else if ( is_file ( $ this -> getRootPath ( ) . 'controller/' . $ this -> getNameSpace ( ) . '_controller.php' ) ) { $ controller = $ this -> getRootPath ( ) . 'controller/' . $ this -> getNameSpace ( ) . '_controller.php' ; } else if ( is_file ( $ this -> getRootPath ( ) . '' . $ this -> getNameSpace ( ) . '_controller.php' ) ) { $ controller = $ this -> getRootPath ( ) . '' . $ this -> getNameSpace ( ) . '_controller.php' ; } if ( $ controller ) { include $ controller ; $ classPath = '\\' . $ this -> getNameSpace ( ) . '_controller' ; $ this -> controller = new $ classPath ( ) ; } else { $ this -> controller = new DefaultController ( ) ; } }
Set the current controller searching for it in various places .
3,195
protected function setView ( ) { if ( is_file ( $ this -> getRootPath ( ) . 'view/' . $ this -> getMethod ( ) . '/view.php' ) ) { $ this -> view = new View ( $ this -> getRootPath ( ) . 'view/' . $ this -> getMethod ( ) . '/view.php' ) ; } else if ( is_file ( $ this -> getRootPath ( ) . 'view/GET/view.php' ) ) { $ this -> view = new View ( $ this -> getRootPath ( ) . 'view/GET/view.php' ) ; } else if ( is_file ( $ this -> getRootPath ( ) . 'view/view.php' ) ) { $ this -> view = new View ( $ this -> getRootPath ( ) . 'view/view.php' ) ; } else if ( is_file ( $ this -> getRootPath ( ) . 'view.php' ) ) { $ this -> view = new View ( $ this -> getRootPath ( ) . 'view.php' ) ; } else if ( is_file ( $ this -> getRootPath ( ) . 'index.php' ) ) { $ this -> view = new View ( $ this -> getRootPath ( ) . 'index.php' ) ; } else { throw new \ Exception ( 'Vue introuvable pour la page ' . $ this -> code ) ; } }
Set the current view searching for it in various places .
3,196
public function getRootPath ( ) { $ folder = WebApp :: getPageFolder ( ) . $ this -> code ; if ( StringTools :: right ( $ folder , 1 ) != '/' ) { $ folder .= '/' ; } return $ folder ; }
Return the page root path based on WebApp root path and the curent code
3,197
public function render ( ) { $ baseContent = $ this -> view -> executeAndReturnContent ( ) ; $ content = TemplateManager :: render ( $ baseContent ) ; $ content = $ this -> controller -> render ( $ content ) ; return $ content ; }
Render the page
3,198
public static function countLines ( $ filepath ) { $ return = false ; if ( file_exists ( $ filepath ) ) { $ handle = fopen ( $ filepath , 'r' ) ; if ( $ handle ) { $ return = 0 ; while ( ! feof ( $ handle ) ) { $ chunk = fgets ( $ handle , 4096 ) ; $ chunk_count = substr_count ( $ chunk , "\n" ) ; $ return = $ return + $ chunk_count ; } fclose ( $ handle ) ; } } return $ return ; }
Get line count
3,199
public static function safeFileWrite ( $ filepath , $ str = '' , $ opts = array ( ) ) { $ return = false ; $ opts = array_merge ( array ( 'est_size' => strlen ( $ str ) , ) , $ opts ) ; $ fh = self :: safeFopen ( $ filepath , $ opts ) ; if ( $ fh ) { if ( fwrite ( $ fh , $ str ) !== false ) { $ return = true ; } else { trigger_error ( 'Error writing to ' . $ filepath , E_USER_ERROR ) ; } self :: safeFclose ( $ fh ) ; } return $ return ; }
Write a string to a file .. taking care that enough diskspace etc exists