idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
14,100
public function get ( $ coord ) { $ coord = rad2deg ( $ coord ) ; $ degrees = ( integer ) $ coord ; $ compass = '' ; if ( $ this -> direction == N :: LAT ) { if ( $ degrees < 0 ) $ compass = 'S' ; elseif ( $ degrees > 0 ) $ compass = 'N' ; } elseif ( $ this -> direction == N :: LONG ) { if ( $ degrees < 0 ) $ compass = 'W' ; elseif ( $ degrees > 0 ) $ compass = 'E' ; } $ minutes = $ coord - $ degrees ; if ( $ minutes < 0 ) $ minutes -= ( 2 * $ minutes ) ; if ( $ degrees < 0 ) $ degrees -= ( 2 * $ degrees ) ; $ minutes = $ minutes * 60 ; $ seconds = $ minutes - ( integer ) $ minutes ; $ minutes = ( integer ) $ minutes ; $ seconds = ( float ) $ seconds * 60 ; $ coordinate = sprintf ( $ this -> output_format , $ degrees , $ minutes , $ seconds , $ compass ) ; return $ coordinate ; }
Get a string representation of the coordinate in DMS notation
14,101
protected function convertRow ( array $ row , Connection $ connection , Table $ table ) { $ result = [ ] ; foreach ( $ row as $ key => $ value ) { $ type = $ table -> getColumn ( $ key ) -> getType ( ) ; $ val = $ type -> convertToPHPValue ( $ value , $ connection -> getDatabasePlatform ( ) ) ; if ( $ type instanceof Types \ DateTimeType ) { $ val = $ val -> format ( \ DateTime :: RFC3339 ) ; } elseif ( $ type instanceof Types \ DateTimeTzType ) { $ val = $ val -> format ( \ DateTime :: RFC3339_EXTENDED ) ; } elseif ( $ type instanceof Types \ TimeType ) { $ val = $ val -> format ( 'H:i:s' ) ; } elseif ( $ type instanceof Types \ BinaryType || $ type instanceof Types \ BlobType ) { $ val = base64_encode ( stream_get_contents ( $ val ) ) ; } $ result [ $ key ] = $ val ; } return $ result ; }
Converts a raw database row to the correct PHP types
14,102
public static function renderStatic ( array $ arguments , \ Closure $ renderChildrenClosure , RenderingContextInterface $ renderingContext ) : string { $ key = $ arguments [ 'key' ] ; $ value = $ arguments [ 'value' ] ; array_push ( $ GLOBALS [ 'TSFE' ] -> registerStack , $ GLOBALS [ 'TSFE' ] -> register ) ; $ GLOBALS [ 'TSFE' ] -> register [ $ key ] = $ value ; $ content = $ renderChildrenClosure ( ) ; if ( $ content ) { $ GLOBALS [ 'TSFE' ] -> register = array_pop ( $ GLOBALS [ 'TSFE' ] -> registerStack ) ; return $ content ; } return '' ; }
Renders the viewhelper .
14,103
public function guessParser ( $ coord ) { if ( ! is_numeric ( $ coord ) and ! is_null ( $ coord ) ) { return new C \ DmsParser ; } return new C \ DecimalParser ; }
Guess the correct parser for a given coordinate
14,104
public function Master ( ) { if ( Translatable :: get_current_locale ( ) != Translatable :: default_locale ( ) ) { if ( $ master = $ this -> owner -> getTranslation ( Translatable :: default_locale ( ) ) ) { return $ master ; } } return $ this -> owner ; }
Get the translation master of this page
14,105
public static function create ( $ term , $ taxonomy = null ) { if ( is_string ( $ term ) && class_exists ( $ term ) ) { return new $ term ; } if ( ! is_object ( $ term ) ) { $ term = get_term ( $ term , $ taxonomy ) ; } $ class = str_replace ( ' ' , '' , ucwords ( str_replace ( Base :: SEPARATOR , ' ' , $ term -> taxonomy ) ) ) ; if ( ! class_exists ( $ class ) ) { $ class = str_replace ( ' ' , '\\' , ucwords ( str_replace ( Base :: SEPARATOR , ' ' , $ term -> taxonomy ) ) ) ; } $ instance = new $ class ; $ instance -> load ( $ term -> term_id ) ; return $ instance ; }
Create an instance based on a term object This basically autoloads the meta data
14,106
public static function createMultiple ( $ terms , $ taxonomy = null ) { if ( ! Arr :: iterable ( $ terms ) ) { return $ terms ; } $ out = array ( ) ; foreach ( $ terms as $ term ) { $ instance = self :: create ( $ term , $ taxonomy ) ; $ out [ $ instance -> get ( 'term_id' ) ] = $ instance ; } return $ out ; }
Create multiple instances based on term objects This basically autoloads the meta data
14,107
public function signupUpdate ( Request $ request ) { $ this -> middleware ( 'auth:api' ) ; $ data = $ request -> all ( ) ; $ validator = Validator :: make ( $ data , [ 'firstname' => 'sometimes|required|max:255' , 'surname' => 'sometimes|required|max:255' , 'email' => 'sometimes|required|email|max:255|unique:users' , 'mobile_number' => 'sometimes|min:10|unique:signup_data' , 'password' => 'sometimes|required|min:6' , 'gender' => 'sometimes|required' , 'user_id' => 'required|integer' , ] ) ; if ( ! empty ( $ validator -> errors ( ) -> messages ( ) ) ) { return new Response ( [ 'status' => 'FAIL' , 'message' => 'Fail to update user signup data' , 'Errors' => $ validator -> errors ( ) ] , 500 ) ; } else { try { unset ( $ data [ '_method' ] ) ; $ signupModel = Signup :: find ( $ data [ 'user_id' ] ) ; foreach ( $ data as $ k => $ ln ) { $ signupModel -> $ k = $ ln ; } $ signupModel -> save ( ) ; return new Response ( [ 'status' => 'OK' , 'message' => 'User signup data updated' , ] , 201 ) ; } catch ( \ Illuminate \ Database \ QueryException $ ex ) { return new Response ( [ 'status' => 'Fail' , 'message' => 'Fail updating' , 'Errors ' => $ ex -> getMessage ( ) ] ) ; } } }
Update user signup instance .
14,108
public static function encode ( $ value , $ options = 0 , $ depth = 512 ) { $ options |= JSON_UNESCAPED_UNICODE ; $ data = version_compare ( PHP_VERSION , '5.5.0' , '>=' ) ? json_encode ( $ value , $ options , $ depth ) : json_encode ( $ value , $ options ) ; if ( JSON_ERROR_NONE !== json_last_error ( ) ) { return $ data ; } return version_compare ( PHP_VERSION , '5.4.0' , '>=' ) ? $ data : preg_replace_callback ( "/\\\\u([0-9a-f]{2})([0-9a-f]{2})/iu" , function ( $ pipe ) { return iconv ( strncasecmp ( PHP_OS , 'WIN' , 3 ) ? 'UCS-2BE' : 'UCS-2' , 'UTF-8' , chr ( hexdec ( $ pipe [ 1 ] ) ) . chr ( hexdec ( $ pipe [ 2 ] ) ) ) ; } , $ data ) ; }
PHP > = 5 . 3 JSON_UNESCAPED_UNICODE constant supported
14,109
public static function getExtensionConfig ( ) : array { $ supportedMimeTypes = self :: DEFAULT_SUPPORTED_MIME_TYPES ; $ desktopWidth = self :: DEFAULT_DESKTOP_WIDTH ; $ tabletWidth = self :: DEFAULT_TABLET_WIDTH ; $ smartphoneWidth = self :: DEFAULT_SMARTPHONE_WIDTH ; if ( isset ( $ GLOBALS [ 'TYPO3_CONF_VARS' ] [ 'EXTENSIONS' ] [ 'responsive_images' ] ) ) { $ supportedMimeTypes = $ GLOBALS [ 'TYPO3_CONF_VARS' ] [ 'EXTENSIONS' ] [ 'responsive_images' ] [ 'supportedMimeTypes' ] ?? self :: DEFAULT_SUPPORTED_MIME_TYPES ; $ desktopWidth = ( int ) $ GLOBALS [ 'TYPO3_CONF_VARS' ] [ 'EXTENSIONS' ] [ 'responsive_images' ] [ 'maxDesktopImageWidth' ] ?? self :: DEFAULT_DESKTOP_WIDTH ; $ tabletWidth = ( int ) $ GLOBALS [ 'TYPO3_CONF_VARS' ] [ 'EXTENSIONS' ] [ 'responsive_images' ] [ 'maxTabletImageWidth' ] ?? self :: DEFAULT_TABLET_WIDTH ; $ smartphoneWidth = ( int ) $ GLOBALS [ 'TYPO3_CONF_VARS' ] [ 'EXTENSIONS' ] [ 'responsive_images' ] [ 'maxSmartphoneImageWidth' ] ?? self :: DEFAULT_SMARTPHONE_WIDTH ; } elseif ( isset ( $ GLOBALS [ 'TYPO3_CONF_VARS' ] [ 'EXT' ] [ 'extConf' ] [ 'responsive_images' ] ) ) { try { $ extConfig = unserialize ( $ GLOBALS [ 'TYPO3_CONF_VARS' ] [ 'EXT' ] [ 'extConf' ] [ 'responsive_images' ] ) ; if ( ! empty ( $ extConfig [ 'supportedMimeTypes' ] ) ) { $ supportedMimeTypes = $ extConfig [ 'supportedMimeTypes' ] ; } if ( isset ( $ extConfig [ 'maxDesktopImageWidth' ] ) && is_numeric ( $ extConfig [ 'maxDesktopImageWidth' ] ) ) { $ desktopWidth = ( int ) $ extConfig [ 'maxDesktopImageWidth' ] ; } if ( isset ( $ extConfig [ 'maxTabletImageWidth' ] ) && is_numeric ( $ extConfig [ 'maxTabletImageWidth' ] ) ) { $ tabletWidth = ( int ) $ extConfig [ 'maxTabletImageWidth' ] ; } if ( isset ( $ extConfig [ 'maxSmartphoneImageWidth' ] ) && is_numeric ( $ extConfig [ 'maxSmartphoneImageWidth' ] ) ) { $ smartphoneWidth = ( int ) $ extConfig [ 'maxSmartphoneImageWidth' ] ; } } catch ( \ Exception $ e ) { } } return [ 'supportedMimeTypes' => $ supportedMimeTypes , 'maxDesktopImageWidth' => $ desktopWidth , 'maxTabletImageWidth' => $ tabletWidth , 'maxSmartphoneImageWidth' => $ smartphoneWidth , ] ; }
Returns extension management configuration as array .
14,110
public static function load ( $ class ) { $ instance = new $ class ; $ taxonomy_key = $ instance -> getTaxonomyKey ( ) ; if ( is_admin ( ) ) { add_action ( sprintf ( 'created_%s' , $ taxonomy_key ) , array ( $ instance , 'addSaveHooks' ) ) ; add_action ( sprintf ( 'edited_%s' , $ taxonomy_key ) , array ( $ instance , 'addSaveHooks' ) ) ; add_action ( sprintf ( '%s_add_form_fields' , $ taxonomy_key ) , array ( $ instance , 'addMetaBoxes' ) ) ; add_action ( sprintf ( '%s_edit_form_fields' , $ taxonomy_key ) , array ( $ instance , 'addMetaBoxes' ) ) ; add_action ( sprintf ( 'manage_edit-%s_columns' , $ taxonomy_key ) , array ( $ instance , 'addAdminColumns' ) , 10 , 3 ) ; add_action ( sprintf ( 'manage_%s_custom_column' , $ taxonomy_key ) , array ( $ instance , 'renderAdminColumn' ) , 10 , 3 ) ; } }
Load a term
14,111
private function calculateHash ( ) { $ hashType = $ this -> getHashType ( ) ; if ( $ hashType == 'sign' ) { throw new InvalidResponseException ( 'Control sign forming method "SIGN" is not supported' ) ; } elseif ( $ hashType == null ) { throw new InvalidResponseException ( 'Invalid signature type' ) ; } return strtoupper ( hash ( $ hashType , $ this -> data [ 'LMI_PAYEE_PURSE' ] . $ this -> data [ 'LMI_PAYMENT_AMOUNT' ] . $ this -> data [ 'LMI_PAYMENT_NO' ] . $ this -> data [ 'LMI_MODE' ] . $ this -> data [ 'LMI_SYS_INVS_NO' ] . $ this -> data [ 'LMI_SYS_TRANS_NO' ] . $ this -> data [ 'LMI_SYS_TRANS_DATE' ] . $ this -> request -> getSecretkey ( ) . $ this -> data [ 'LMI_PAYER_PURSE' ] . $ this -> data [ 'LMI_PAYER_WM' ] ) ) ; }
Calculate hash to verify transaction details .
14,112
public function load ( $ id , $ load_terms = true ) { $ info = ( is_object ( $ id ) ) ? $ id : get_post ( $ id ) ; if ( ! is_object ( $ info ) ) { return false ; } if ( isset ( $ info -> post_title ) && preg_match ( '/[&]{1,}/' , $ info -> post_title ) ) { $ info -> post_title = html_entity_decode ( $ info -> post_title ) ; } $ this -> _info = ( array ) $ info ; $ meta = get_post_meta ( $ this -> _info [ self :: ID ] ) ; if ( Arr :: iterable ( $ meta ) ) { foreach ( $ meta as $ k => $ v ) { $ this -> set ( $ k , current ( $ v ) ) ; } } if ( ! $ load_terms ) { return true ; } $ this -> loadTerms ( ) ; return true ; }
Load a post by ID
14,113
public function loadTerms ( ) { $ taxonomy_keys = $ this -> getTaxonomyKeys ( ) ; if ( ! Arr :: iterable ( $ taxonomy_keys ) ) { return false ; } $ taxonomies_subclasses = array ( ) ; $ subclasses = Term \ Loader :: getSubclasses ( ) ; foreach ( $ subclasses as $ subclass ) { $ term_instance = new $ subclass ; $ term_instance_taxonomy_key = $ term_instance -> getKey ( ) ; foreach ( $ taxonomy_keys as $ taxonomy_key ) { if ( array_key_exists ( $ taxonomy_key , $ taxonomies_subclasses ) ) { continue ; } if ( $ term_instance_taxonomy_key !== $ taxonomy_key ) { continue ; } $ taxonomies_subclasses [ $ taxonomy_key ] = $ subclass ; break ; } } foreach ( $ taxonomy_keys as $ taxonomy_key ) { $ terms = wp_get_post_terms ( $ this -> get ( self :: ID ) , $ taxonomy_key ) ; if ( ! Arr :: iterable ( $ terms ) ) { continue ; } $ terms = array_combine ( array_map ( 'intval' , Collection :: pluck ( $ terms , 'term_id' ) ) , $ terms ) ; if ( array_key_exists ( $ taxonomy_key , $ taxonomies_subclasses ) ) { $ terms = Term \ Factory :: createMultiple ( $ terms , $ taxonomy_key ) ; } $ this -> _terms [ $ taxonomy_key ] = $ terms ; } return true ; }
Load the terms
14,114
public function getDefaults ( ) { global $ user ; return array ( 'post_type' => $ this -> getPostType ( ) , 'post_author' => ( is_object ( $ user ) ) ? $ user -> ID : null , 'post_date' => current_time ( 'mysql' ) , 'post_category' => array ( 0 ) , 'post_status' => 'publish' ) ; }
Get default values Override this
14,115
public function registerPostType ( ) { $ config = $ this -> getPostTypeConfig ( ) ; if ( empty ( $ config ) ) { return ; } register_post_type ( $ this -> getPostType ( ) , $ config ) ; }
Register the post type Override this if you need to
14,116
public function getTaxonomy ( $ key ) { $ taxonomies = $ this -> getTaxonomies ( ) ; if ( ! Arr :: iterable ( $ taxonomies ) ) { return false ; } $ taxonomy = ( array_key_exists ( $ key , $ taxonomies ) ) ? $ taxonomies [ $ key ] : false ; if ( ! $ taxonomy ) { return false ; } if ( is_string ( $ taxonomy ) ) { $ taxonomy = ( is_numeric ( $ key ) ) ? array ( 'label' => self :: getGeneratedTaxonomyLabel ( $ taxonomy ) ) : array ( 'label' => $ taxonomy ) ; } elseif ( is_array ( $ taxonomy ) && ! array_key_exists ( 'label' , $ taxonomy ) ) { $ taxonomy [ 'label' ] = self :: getGeneratedTaxonomyLabel ( $ key ) ; } if ( ! array_key_exists ( 'hierarchical' , $ taxonomy ) ) { $ taxonomy [ 'hierarchical' ] = true ; } return $ taxonomy ; }
Get a taxonomy by name
14,117
public function getTaxonomyKeys ( ) { $ taxonomies = $ this -> getTaxonomies ( ) ; if ( ! Arr :: iterable ( $ taxonomies ) ) { return array ( ) ; } $ out = array ( ) ; foreach ( $ taxonomies as $ k => $ taxonomy ) { $ taxonomy = $ this -> getTaxonomy ( $ k ) ; $ out [ ] = $ this -> getTaxonomyKey ( $ k , $ taxonomy ) ; } return $ out ; }
Get the taxonomy keys
14,118
public function getTaxonomyKey ( $ key , $ taxonomy = array ( ) ) { if ( is_string ( $ key ) ) { return $ key ; } if ( is_array ( $ taxonomy ) && array_key_exists ( 'label' , $ taxonomy ) ) { return Str :: machine ( $ taxonomy [ 'label' ] , Base :: SEPARATOR ) ; } return $ key ; }
Get a taxonomy key
14,119
public function getTaxonomiesInfo ( ) { $ taxonomies = $ this -> getTaxonomies ( ) ; if ( ! Arr :: iterable ( $ taxonomies ) ) { return array ( ) ; } $ out = array ( ) ; foreach ( $ taxonomies as $ k => $ taxonomy ) { $ taxonomy = $ this -> getTaxonomy ( $ k ) ; $ key = $ this -> getTaxonomyKey ( $ k , $ taxonomy ) ; $ out [ ] = array ( 'key' => $ key , 'post_type' => $ this -> getPostType ( ) , 'config' => $ taxonomy ) ; } return $ out ; }
Get the taxonomy info
14,120
public function getPostTypeConfig ( ) { if ( in_array ( $ this -> getPostType ( ) , array ( 'post' , 'page' ) ) ) { return null ; } return array ( 'labels' => array ( 'name' => _x ( $ this -> getPlural ( ) , 'post type general name' ) , 'singular_name' => _x ( $ this -> getSingular ( ) , 'post type singular name' ) , 'add_new' => _x ( 'Add New' , $ this -> getSingular ( ) ) , 'add_new_item' => __ ( sprintf ( 'Add New %s' , $ this -> getSingular ( ) ) ) , 'edit_item' => __ ( sprintf ( 'Edit %s' , $ this -> getSingular ( ) ) ) , 'new_item' => __ ( sprintf ( 'New %s' , $ this -> getPlural ( ) ) ) , 'view_item' => __ ( sprintf ( 'View %s' , $ this -> getSingular ( ) ) ) , 'search_items' => __ ( sprintf ( 'Search %s' , $ this -> getPlural ( ) ) ) , 'not_found' => __ ( sprintf ( 'No %s found' , $ this -> getPlural ( ) ) ) , 'not_found_in_trash' => __ ( sprintf ( 'No %s found in Trash' , $ this -> getPlural ( ) ) ) , 'parent_item_colon' => '' ) , 'hierarchical' => $ this -> getHierarchical ( ) , 'public' => $ this -> getPublic ( ) , 'supports' => $ this -> getSupports ( ) , 'show_in_menu' => $ this -> getShowInMenu ( ) , 'show_in_admin_bar' => $ this -> getShowInAdminBar ( ) , 'menu_icon' => $ this -> getMenuIcon ( ) , 'menu_position' => $ this -> getMenuPosition ( ) , 'exclude_from_search' => $ this -> getExcludeFromSearch ( ) , 'has_archive' => $ this -> getHasArchive ( ) , 'rewrite' => $ this -> getRewrite ( ) , 'publicly_queryable' => $ this -> getPubliclyQueryable ( ) , ) ; }
Get the post type config
14,121
public function getMenuIcon ( ) { $ reflector = new \ ReflectionClass ( get_called_class ( ) ) ; $ dir = basename ( dirname ( $ reflector -> getFileName ( ) ) ) ; $ post_type = $ this -> getPostType ( ) ; $ fnames = array ( $ post_type . '.png' , $ post_type . '.gif' , $ post_type . '.jpg' ) ; foreach ( $ fnames as $ fname ) { $ fpath = sprintf ( '%s/%s/%s' , WP_PLUGIN_DIR , $ dir , $ fname ) ; if ( ! file_exists ( $ fpath ) ) { continue ; } return sprintf ( '%s/%s/%s' , WP_PLUGIN_URL , $ dir , $ fname ) ; } return '' ; }
Get the menu icon
14,122
public function sortAdminColumns ( $ vars ) { if ( ! isset ( $ vars [ 'orderby' ] ) ) { return $ vars ; } $ admin_columns = $ this -> getAdminColumns ( ) ; if ( ! Arr :: iterable ( $ admin_columns ) ) { return $ vars ; } foreach ( $ admin_columns as $ k ) { if ( $ vars [ 'orderby' ] !== $ k ) { continue ; } $ vars = array_merge ( $ vars , array ( 'meta_key' => $ k , 'orderby' => 'meta_value' ) ) ; break ; } return $ vars ; }
Sort the admin columns if necessary
14,123
public function makeAdminTaxonomyColumnsSortable ( $ clauses , $ wp_query ) { global $ wpdb ; if ( ! array_key_exists ( 'orderby' , $ wp_query -> query ) ) { return $ clauses ; } if ( $ wp_query -> query [ 'orderby' ] !== 'meta_value' ) { return $ clauses ; } if ( ! array_key_exists ( 'meta_key' , $ wp_query -> query ) ) { return $ clauses ; } $ taxonomies = $ this -> getTaxonomies ( ) ; if ( ! Arr :: iterable ( $ taxonomies ) ) { return $ clauses ; } $ sortable_taxonomy_key = null ; foreach ( $ taxonomies as $ taxonomy_key => $ taxonomy ) { $ taxonomy_key = ( is_int ( $ taxonomy_key ) ) ? $ taxonomy : $ taxonomy_key ; if ( $ wp_query -> query [ 'meta_key' ] !== $ taxonomy_key ) { continue ; } $ sortable_taxonomy_key = $ taxonomy_key ; break ; } if ( ! $ sortable_taxonomy_key ) { return $ clauses ; } if ( $ wp_query -> query [ 'meta_key' ] !== $ sortable_taxonomy_key ) { return $ clauses ; } $ clauses [ 'where' ] = str_replace ( array ( "AND ({$wpdb->postmeta}.meta_key = '" . $ taxonomy . "' )" , "AND ( \n {$wpdb->postmeta}.meta_key = '" . $ taxonomy . "'\n)" ) , '' , $ clauses [ 'where' ] ) ; $ clauses [ 'join' ] .= " LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id) LEFT OUTER JOIN {$wpdb->terms} USING (term_id) " ; $ clauses [ 'where' ] .= "AND (taxonomy = '" . $ taxonomy . "' OR taxonomy IS NULL)" ; $ clauses [ 'groupby' ] = "object_id" ; $ clauses [ 'orderby' ] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC)" ; $ clauses [ 'orderby' ] .= ( strtoupper ( $ wp_query -> get ( 'order' ) ) == 'ASC' ) ? 'ASC' : 'DESC' ; return $ clauses ; }
Make the admin taxonomy columns sortable Admittedly this is a bit hackish
14,124
public function getHideTitleFromAdminColumns ( ) { if ( in_array ( 'title' , $ this -> getAdminColumns ( ) ) ) { return false ; } $ supports = $ this -> getSupports ( ) ; if ( is_array ( $ supports ) && in_array ( 'title' , $ supports ) ) { return false ; } return true ; }
Hide the title from admin columns?
14,125
public function getPostType ( ) { $ called_class_segments = explode ( '\\' , get_called_class ( ) ) ; $ class_name = end ( $ called_class_segments ) ; return ( is_null ( $ this -> post_type ) ) ? Str :: machine ( Str :: camelToHuman ( $ class_name ) , Base :: SEPARATOR ) : $ this -> post_type ; }
Get the post type
14,126
public static function getPairs ( $ args = array ( ) ) { $ called_class = get_called_class ( ) ; $ instance = Post \ Factory :: create ( $ called_class ) ; if ( ! Arr :: iterable ( $ args ) ) { global $ wpdb ; $ sql = sprintf ( "SELECT p.ID, p.post_title FROM $wpdb->posts p WHERE p.post_type = '%s' AND (p.post_status = 'publish') ORDER BY p.post_title ASC" , $ instance -> getPostType ( ) ) ; $ results = $ wpdb -> get_results ( $ sql ) ; if ( ! Arr :: iterable ( $ results ) ) { return array ( ) ; } return array_combine ( Collection :: pluck ( $ results , 'ID' ) , Collection :: pluck ( $ results , 'post_title' ) ) ; } $ default_args = array ( 'post_type' => $ instance -> getPostType ( ) , 'numberposts' => - 1 , 'order' => 'ASC' , 'orderby' => 'title' , ) ; $ args = ( Arr :: iterable ( $ args ) ) ? $ args : $ default_args ; if ( ! array_key_exists ( 'post_type' , $ args ) ) { $ args [ 'post_type' ] = $ instance -> getPostType ( ) ; } $ all = get_posts ( $ args ) ; if ( ! Arr :: iterable ( $ all ) ) { return array ( ) ; } return array_combine ( Collection :: pluck ( $ all , self :: ID ) , Collection :: pluck ( $ all , 'post_title' ) ) ; }
Get the pairs
14,127
public static function getWhere ( $ args = array ( ) , $ load_terms = true ) { $ instance = Post \ Factory :: create ( get_called_class ( ) ) ; $ default_orderby = $ instance -> getDefaultOrderBy ( ) ; $ default_order = $ instance -> getDefaultOrder ( ) ; $ default_args = array ( 'post_type' => $ instance -> getPostType ( ) , 'numberposts' => - 1 , 'orderby' => $ default_orderby , 'order' => $ default_order , ) ; if ( $ default_orderby !== 'menu_order' ) { $ fields = $ instance -> getFields ( ) ; if ( array_key_exists ( $ default_orderby , $ fields ) ) { $ default_args [ 'meta_key' ] = $ default_orderby ; $ default_args [ 'orderby' ] = ( $ fields [ $ default_orderby ] [ 'type' ] === 'number' ) ? 'meta_value_num' : 'meta_value' ; } } if ( array_key_exists ( 'orderby' , $ args ) ) { $ fields = $ instance -> getFields ( ) ; if ( array_key_exists ( $ args [ 'orderby' ] , $ fields ) ) { $ args [ 'meta_key' ] = $ args [ 'orderby' ] ; $ args [ 'orderby' ] = ( $ fields [ $ args [ 'orderby' ] ] [ 'type' ] === 'number' ) ? 'meta_value_num' : 'meta_value' ; } } $ criteria = array_merge ( $ default_args , $ args ) ; return Post \ Factory :: createMultiple ( get_posts ( $ criteria ) , $ load_terms ) ; }
Get posts with conditions
14,128
public static function getByTerm ( $ taxonomy , $ terms , $ field = 'slug' , $ args = array ( ) , $ load_terms = true ) { $ args = array_merge ( $ args , array ( 'tax_query' => array ( array ( 'taxonomy' => $ taxonomy , 'terms' => $ terms , 'field' => $ field ) ) , ) ) ; return static :: getWhere ( $ args , $ load_terms ) ; }
Get by a taxonomy and term
14,129
public static function getOneByTerm ( $ taxonomy , $ terms , $ field = 'slug' , $ args = array ( ) , $ load_terms = true ) { $ args [ 'numberposts' ] = 1 ; $ result = static :: getByTerm ( $ taxonomy , $ terms , $ field , $ args , $ load_terms ) ; return ( count ( $ result ) ) ? current ( $ result ) : null ; }
Get one by a taxonomy and term
14,130
public static function getPage ( $ page = 1 , $ args = array ( ) , $ load_terms = true ) { $ instance = Post \ Factory :: create ( get_called_class ( ) ) ; $ criteria = array ( 'post_type' => $ instance -> getPostType ( ) , 'orderby' => 'date' , 'order' => 'DESC' , 'posts_per_page' => $ instance -> getPostsPerPage ( ) , 'offset' => ( $ page - 1 ) * $ instance -> getPostsPerPage ( ) ) ; $ criteria = array_merge ( $ criteria , $ args ) ; return Post \ Factory :: createMultiple ( get_posts ( $ criteria ) , $ load_terms ) ; }
Get results by page
14,131
public function setTerms ( $ term_ids , $ taxonomy = null , $ append = false ) { $ taxonomy = ( $ taxonomy ) ? $ taxonomy : 'post_tag' ; if ( ! is_array ( $ this -> _terms ) ) { $ this -> _terms = array ( ) ; } if ( ! array_key_exists ( $ taxonomy , $ this -> _terms ) ) { $ this -> _terms [ $ taxonomy ] = array ( ) ; } $ this -> _terms [ $ taxonomy ] = ( $ append ) ? array_merge ( $ this -> _terms [ $ taxonomy ] , $ term_ids ) : $ term_ids ; return $ this -> _terms [ $ taxonomy ] ; }
Set the terms
14,132
public function getTerms ( $ taxonomy = null ) { if ( $ taxonomy ) { return ( array_key_exists ( $ taxonomy , $ this -> _terms ) ) ? $ this -> _terms [ $ taxonomy ] : array ( ) ; } return $ this -> _terms ; }
Get the terms
14,133
public function hasTerm ( $ term_id ) { $ taxonomy_terms = $ this -> getTerms ( ) ; if ( ! Arr :: iterable ( $ taxonomy_terms ) ) { return false ; } foreach ( $ taxonomy_terms as $ taxonomy_key => $ terms ) { if ( ! Arr :: iterable ( $ terms ) ) { continue ; } foreach ( $ terms as $ term ) { if ( ( int ) $ term -> term_id === ( int ) $ term_id ) { return true ; } } } return false ; }
Does this post have this term?
14,134
public function getPostAttachment ( $ size = 'full' , $ property = null ) { $ post_id = $ this -> get ( 'ID' ) ; if ( ! has_post_thumbnail ( $ post_id ) ) { return false ; } $ attachment_id = get_post_thumbnail_id ( $ post_id ) ; $ image_properties = array ( 'url' , 'width' , 'height' , 'is_resized' ) ; $ image_array = array_combine ( $ image_properties , array_values ( wp_get_attachment_image_src ( $ attachment_id , $ size ) ) ) ; if ( in_array ( $ property , $ image_properties ) ) { return $ image_array [ $ property ] ; } return $ image_array ; }
Get the image attachment array for post s featured image
14,135
public function getRenderPublicField ( $ key , $ field = null , $ load_value = true ) { $ class = get_called_class ( ) ; if ( $ key === self :: KEY_CLASS ) { $ attribs = array ( 'type' => 'hidden' , 'name' => $ key , 'value' => $ class ) ; return Html :: tag ( 'input' , null , $ attribs ) ; } if ( $ key === self :: KEY_NONCE ) { $ attribs = array ( 'type' => 'hidden' , 'name' => $ key , 'value' => wp_create_nonce ( $ this -> getNonceAction ( ) ) ) ; return Html :: tag ( 'input' , null , $ attribs ) ; } if ( $ load_value ) { if ( ! is_array ( $ field ) ) { $ field = self :: getField ( $ key ) ; } if ( ! array_key_exists ( 'value' , $ field ) ) { $ field [ 'value' ] = $ this -> $ key ; } } return self :: getRenderMetaBoxField ( $ key , $ field ) ; }
Render a public field
14,136
public function getPublicFormKey ( $ suffix = null ) { $ val = sprintf ( '%s_public_form' , $ this -> getPostType ( ) ) ; return ( $ suffix ) ? sprintf ( '%s_%s' , $ val , $ suffix ) : $ val ; }
Get the public form key This is useful for integrations with FlashData and the like when you want to persist data from the form to another page . For instance in the case of error messages and form values .
14,137
public static function find ( $ post_id , $ load_terms = true ) { $ instance = Post \ Factory :: create ( get_called_class ( ) ) ; $ instance -> load ( $ post_id , $ load_terms ) ; return $ instance ; }
Find a post
14,138
public function getLinkURL ( $ field ) { $ link_attr = self :: decodeLinkObject ( $ this -> get ( $ field ) ) ; if ( ! is_object ( $ link_attr ) ) { return $ this -> get ( $ field ) ; } if ( ! ( strlen ( $ link_attr -> href ) && strlen ( $ link_attr -> title ) && strlen ( $ link_attr -> target ) ) ) { $ field_attribs = $ this -> getField ( $ field ) ; if ( array_key_exists ( 'default' , $ field_attribs ) ) return $ field_attribs [ 'default' ] ; } return $ link_attr -> href ; }
Get just the URL from a field type of link
14,139
public function linkAttribsToHTMLString ( $ link_attr , $ body = '' , $ classes = '' , $ id = '' , $ styles = '' ) { $ link_text = null ; if ( strlen ( $ link_attr -> title ) ) { $ link_text = $ link_attr -> title ; } elseif ( strlen ( $ body ) ) { $ link_text = $ body ; } else { $ link_text = $ link_attr -> href ; } return Html :: link ( $ link_attr -> href , $ link_text , array ( 'title' => $ link_attr -> title , 'target' => $ link_attr -> target , 'class' => $ classes , 'id' => $ id , 'style' => $ styles ) ) ; }
Get an HTML link from attributes that come from a link object This is mainly used with the field type of link
14,140
public static function getLinkHTMLFromObject ( $ object_string , $ body = '' , $ classes = '' , $ id = '' , $ styles = '' ) { return self :: linkAttribsToHTMLString ( self :: decodeLinkObject ( $ object_string ) , $ body , $ classes , $ id , $ styles ) ; }
Get an HTML link from an encoded link object
14,141
public function generateToken ( $ save = false ) { $ attributes = [ 'token' => str_random ( 16 ) , 'is_used' => false , 'user_id' => $ this -> id , 'created_at' => time ( ) ] ; $ token = App :: make ( Token :: class ) ; $ token -> fill ( $ attributes ) ; if ( $ save ) { $ token -> save ( ) ; } return $ token ; }
Generate a token for the current user .
14,142
public function enterExpression ( Expression $ expr ) { $ hash = spl_object_hash ( $ expr ) ; if ( $ expr instanceof Key ) { if ( ! count ( $ this -> hashes ) ) { $ this -> qb -> andWhere ( $ this -> toExpr ( $ expr ) ) ; } else { $ lastHash = end ( $ this -> hashes ) ; $ this -> map [ $ lastHash ] [ ] = $ this -> toExpr ( $ expr ) ; } } elseif ( $ expr instanceof OrX ) { $ this -> hashes [ ] = $ hash ; $ this -> map [ $ hash ] = [ ] ; } elseif ( $ expr instanceof AndX ) { $ this -> hashes [ ] = $ hash ; $ this -> map [ $ hash ] = [ ] ; } return $ expr ; }
Adds Key expressions to the query or stores children of OrX and AndX expressions in memory to be added on the leaveExpression for OrX or AndX expressions .
14,143
public function leaveExpression ( Expression $ expr ) { if ( $ expr instanceof OrX || $ expr instanceof AndX ) { $ hash = spl_object_hash ( $ expr ) ; if ( $ expr instanceof OrX ) { $ composite = $ this -> qb -> expr ( ) -> orX ( ) ; $ composite -> addMultiple ( $ this -> map [ $ hash ] ) ; } else { $ composite = $ this -> qb -> expr ( ) -> andX ( ) ; $ composite -> addMultiple ( $ this -> map [ $ hash ] ) ; } unset ( $ this -> hashes [ array_search ( $ hash , $ this -> hashes ) ] ) ; if ( ! count ( $ this -> hashes ) ) { $ this -> qb -> andWhere ( $ composite ) ; } else { $ lastHash = end ( $ this -> hashes ) ; $ this -> map [ $ lastHash ] [ ] = $ composite ; } } return $ expr ; }
Adds the AndX and OrX Doctrine expressions to the query
14,144
public function shouldJoin ( $ key , $ prefix = null ) { $ parts = explode ( '.' , $ key ) ; if ( ! $ prefix ) { $ prefix = $ this -> getRootAlias ( ) ; } if ( ! in_array ( $ parts [ 0 ] , $ this -> qb -> getAllAliases ( ) ) ) { $ this -> qb -> leftJoin ( $ prefix . '.' . $ parts [ 0 ] , $ parts [ 0 ] ) ; } if ( count ( $ parts ) > 2 ) { $ prefix = array_shift ( $ parts ) ; $ leftover = implode ( '.' , $ parts ) ; $ key = $ this -> shouldJoin ( $ leftover , $ prefix ) ; } return $ key ; }
Strips the key parts and creates joins if they don t exist yet .
14,145
private function validateKey ( $ key ) { $ details = openssl_pkey_get_details ( $ key ) ; if ( ! isset ( $ details [ 'key' ] ) || $ details [ 'type' ] !== OPENSSL_KEYTYPE_RSA ) { throw new \ InvalidArgumentException ( 'This key is not compatible with RSA signatures' ) ; } }
Returns if the key type is equals with expected type
14,146
public function downloadMediaAction ( $ filename ) { $ media = $ this -> mediaManager -> getRepository ( ) -> findOneByReference ( $ filename ) ; $ provider = $ this -> container -> get ( 'opifer.media.provider.pool' ) -> getProvider ( $ media -> getProvider ( ) ) ; $ mediaUrl = $ provider -> getUrl ( $ media ) ; $ fileSystem = $ provider -> getFileSystem ( ) ; $ file = $ fileSystem -> read ( $ media -> getReference ( ) ) ; $ response = new Response ( ) ; $ response -> headers -> set ( 'Content-type' , $ media -> getContentType ( ) ) ; $ response -> headers -> set ( 'Content-Disposition' , sprintf ( 'attachment; filename="%s"' , basename ( $ mediaUrl ) ) ) ; $ response -> setContent ( $ file ) ; return $ response ; }
Download media item .
14,147
protected function getDisplayLogicPrototypes ( BlockInterface $ block ) { $ collection = new PrototypeCollection ( [ new OrXPrototype ( ) , new AndXPrototype ( ) , new EventPrototype ( 'click_event' , 'Click Event' , 'event.type.click' ) , new TextPrototype ( 'dom_node_id' , 'DOM Node Id' , 'node.id' ) ] ) ; $ owner = $ block -> getOwner ( ) ; if ( $ owner ) { $ blockChoices = [ ] ; foreach ( $ owner -> getBlocks ( ) as $ member ) { try { $ properties = $ member -> getProperties ( ) ; if ( $ member instanceof ChoiceFieldBlock ) { if ( empty ( $ member -> getName ( ) ) ) { continue ; } if ( ! isset ( $ properties [ 'options' ] ) ) { continue ; } $ choices = [ ] ; foreach ( $ properties [ 'options' ] as $ option ) { if ( empty ( $ option [ 'key' ] ) ) { continue ; } $ choices [ ] = new Choice ( $ option [ 'key' ] , $ option [ 'value' ] ) ; } $ collection -> add ( new SelectPrototype ( $ member -> getName ( ) , $ properties [ 'label' ] , $ member -> getName ( ) , $ choices ) ) ; } elseif ( $ member instanceof NumberFieldBlock || $ member instanceof RangeFieldBlock ) { if ( empty ( $ member -> getName ( ) ) ) { continue ; } $ collection -> add ( new NumberPrototype ( $ member -> getName ( ) , $ properties [ 'label' ] , $ member -> getName ( ) ) ) ; } if ( ! empty ( $ member -> getName ( ) ) ) { $ blockChoices [ ] = new Choice ( $ member -> getName ( ) , $ member -> getName ( ) ) ; } } catch ( \ Exception $ e ) { } } $ collection -> add ( new SelectPrototype ( 'block_name' , 'Block Name' , 'block.name' , $ blockChoices ) ) ; } return $ collection -> all ( ) ; }
Builds the default display condition prototypes
14,148
public function onAuthenticationSuccess ( Request $ request , TokenInterface $ token ) { if ( $ user = $ token -> getUser ( ) ) { if ( ! $ user -> getFirstName ( ) || ! $ user -> getLastName ( ) ) { return new RedirectResponse ( $ this -> router -> generate ( 'opifer_cms_user_profile' ) ) ; } } return parent :: onAuthenticationSuccess ( $ request , $ token ) ; }
Checks if the user has actually filled in some mandatory data . If not it redirects to the users profile page .
14,149
public function fromBase64URL ( $ data ) { if ( $ remainder = strlen ( $ data ) % 4 ) { $ data .= str_repeat ( '=' , 4 - $ remainder ) ; } return base64_decode ( strtr ( $ data , '-_' , '+/' ) ) ; }
Deserializes from base64url
14,150
public function synchronise ( Subscription $ subscription ) { try { $ contact = [ 'update' => true , 'purge' => false , 'contact' => [ 'externalId' => $ subscription -> getId ( ) , 'properties' => [ 'email' => $ subscription -> getEmail ( ) , ] , ] , ] ; $ response = $ this -> post ( 'contact' , $ contact ) ; if ( $ response -> getStatusCode ( ) == '204' ) { $ this -> subscriptionManager -> updateStatus ( $ subscription , Subscription :: STATUS_SYNCED ) ; return true ; } else { $ this -> subscriptionManager -> updateStatus ( $ subscription , Subscription :: STATUS_FAILED ) ; return false ; } } catch ( \ Exception $ e ) { $ this -> subscriptionManager -> updateStatus ( $ subscription , Subscription :: STATUS_FAILED ) ; return true ; } }
Synchronize a subscription
14,151
public function getHeader ( $ name , $ default = null ) { if ( $ this -> hasHeader ( $ name ) ) { return $ this -> getHeaderValue ( $ name ) ; } if ( $ default === null ) { throw new \ OutOfBoundsException ( 'Requested header is not configured' ) ; } return $ default ; }
Returns the value of a token header
14,152
private function getHeaderValue ( $ name ) { $ header = $ this -> headers [ $ name ] ; if ( $ header instanceof Claim ) { return $ header -> getValue ( ) ; } return $ header ; }
Returns the value stored in header
14,153
public function getClaim ( $ name , $ default = null ) { if ( $ this -> hasClaim ( $ name ) ) { return $ this -> claims [ $ name ] -> getValue ( ) ; } if ( $ default === null ) { throw new \ OutOfBoundsException ( 'Requested claim is not configured' ) ; } return $ default ; }
Returns the value of a token claim
14,154
public function verify ( Signer $ signer , $ key ) { if ( $ this -> signature === null ) { throw new \ BadMethodCallException ( 'This token is not signed' ) ; } if ( $ this -> headers [ 'alg' ] !== $ signer -> getAlgorithmId ( ) ) { return false ; } return $ this -> signature -> verify ( $ signer , $ this -> getPayload ( ) , $ key ) ; }
Verify if the key matches with the one that created the signature
14,155
public function validate ( ValidationData $ data ) { foreach ( $ this -> getValidatableClaims ( ) as $ claim ) { if ( ! $ claim -> validate ( $ data ) ) { return false ; } } return true ; }
Validates if the token is valid
14,156
private function getValidatableClaims ( ) { $ claims = array ( ) ; foreach ( $ this -> claims as $ claim ) { if ( $ claim instanceof Validatable ) { $ cliams [ ] = $ claim ; } } return $ claims ; }
Yields the validatable claims
14,157
public function create ( $ projectKey , $ issueTypeName ) { $ fieldsMetadata = $ this -> getCreateMetadataFields ( $ projectKey , $ issueTypeName ) ; $ fluentIssueCreate = new FluentIssueCreate ( $ this -> client , $ fieldsMetadata ) ; return $ fluentIssueCreate -> field ( Field :: PROJECT , $ projectKey ) -> field ( Field :: ISSUE_TYPE , $ issueTypeName ) ; }
Creates an issue or a sub - task
14,158
public function addComment ( $ issue , $ body , $ visibilityType = null , $ visibilityName = null , $ expand = false ) { $ path = "/issue/{$issue}/comment" . ( $ expand ? '?expand' : '' ) ; $ data = array ( 'body' => $ body ) ; if ( $ visibilityType !== null && $ visibilityName !== null ) { $ data [ 'visibility' ] = array ( 'type' => $ visibilityType , 'value' => $ visibilityName ) ; } try { $ result = $ this -> client -> callPost ( $ path , $ data ) ; return new Comment ( $ this -> client , $ result -> getData ( ) ) ; } catch ( Exception $ e ) { throw new JiraException ( "Failed to add comment" , $ e ) ; } }
Adds a new comment to an issue .
14,159
public function deleteComment ( $ issue , $ commentId ) { $ path = "/issue/{$issue}/comment/{$commentId}" ; try { $ this -> client -> callDelete ( $ path ) ; } catch ( Exception $ e ) { throw new JiraException ( "Failed to delete comment" , $ e ) ; } }
Deletes an existing comment
14,160
public function getEditMetadata ( $ issue ) { $ path = "/issue/{$issue}/editmeta" ; try { $ data = $ this -> client -> callGet ( $ path ) -> getData ( ) ; if ( ! isset ( $ data [ 'fields' ] ) ) { throw new JiraException ( "Bad metadata" ) ; } return $ data ; } catch ( Exception $ e ) { throw new JiraException ( "Failed to retrieve issue metadata" , $ e ) ; } }
Returns the meta data for editing an issue .
14,161
public function addWatcher ( $ issue , $ login ) { $ path = "/issue/{$issue}/watchers" ; try { $ this -> client -> callPost ( $ path , $ login ) ; } catch ( Exception $ e ) { throw new JiraException ( "Failed to add watcher '{$login}' to issue '{$issue}'" , $ e ) ; } return $ this ; }
Adds a user to an issue s watcher list .
14,162
public function deleteWatcher ( $ issue , $ login ) { $ path = "/issue/{$issue}/watchers?username={$login}" ; try { $ this -> client -> callDelete ( $ path ) ; } catch ( Exception $ e ) { throw new JiraException ( "Failed to delete watcher '{$login}' to issue '{$issue}'" , $ e ) ; } }
Removes a user from an issue s watcher list .
14,163
public function get ( $ issue , $ includedFields = null , $ expandFields = false ) { $ params = array ( ) ; if ( $ includedFields !== null ) { $ params [ 'fields' ] = $ includedFields ; } if ( $ expandFields ) { $ params [ 'expand' ] = '' ; } $ path = "/issue/{$issue}?" . http_build_query ( $ params ) ; $ result = $ this -> client -> callGet ( $ path ) -> getData ( ) ; return new \ JiraClient \ Resource \ Issue ( $ this -> client , $ result ) ; }
Returns a full representation of the issue for the given issue key .
14,164
protected function findall ( string $ haystack , $ needle ) : array { $ lastPos = 0 ; $ positions = [ ] ; while ( ( $ lastPos = strpos ( $ haystack , $ needle , $ lastPos ) ) !== false ) { $ positions [ ] = $ lastPos ; $ lastPos = $ lastPos + 1 ; } return $ positions ; }
Find all occurrences of a needle in a string
14,165
protected function findFirstPacketOffset ( ) { $ positions = $ this -> findall ( $ this -> buffer , 'G' ) ; while ( count ( $ positions ) > 0 ) { $ position = array_shift ( $ positions ) ; for ( $ i = 1 ; $ i <= $ this -> consecutivePacketsBeforeLock ; $ i ++ ) { if ( ! in_array ( $ position + 188 * $ i , $ positions ) ) { break ; } return $ position ; } } return false ; }
Find the offset of the first MPEG TS packet in the current buffer
14,166
protected function extGetLL ( $ key , $ convertWithHtmlspecialchars = true ) { $ labelStr = $ this -> getLanguageService ( ) -> getLL ( $ key ) ; if ( $ convertWithHtmlspecialchars ) { $ labelStr = htmlspecialchars ( $ labelStr ) ; } return $ labelStr ; }
Translate given key
14,167
public function extGetFeAdminValue ( $ sectionName , $ val = '' ) { $ beUser = $ this -> getBackendUser ( ) ; if ( $ val && isset ( $ beUser -> extAdminConfig [ 'override.' ] [ $ sectionName . '.' ] [ $ val ] ) ) { return $ beUser -> extAdminConfig [ 'override.' ] [ $ sectionName . '.' ] [ $ val ] ; } if ( ! $ val && isset ( $ beUser -> extAdminConfig [ 'override.' ] [ $ sectionName ] ) ) { return $ beUser -> extAdminConfig [ 'override.' ] [ $ sectionName ] ; } $ returnValue = $ val ? $ beUser -> uc [ 'TSFE_adminConfig' ] [ $ sectionName . '_' . $ val ] : 1 ; return ! $ val ? true : $ returnValue ; }
Returns the value for an Admin Panel setting .
14,168
protected function loadCollection ( BlockInterface $ block ) { $ properties = $ block -> getProperties ( ) ; $ conditions = ( isset ( $ properties [ 'conditions' ] ) ) ? $ properties [ 'conditions' ] : '[]' ; $ conditions = $ this -> expressionEngine -> deserialize ( $ conditions ) ; if ( empty ( $ conditions ) ) { return ; } $ site = $ this -> siteManager -> getSite ( ) ; $ qb = $ this -> expressionEngine -> toQueryBuilder ( $ conditions , $ this -> contentManager -> getClass ( ) ) ; $ qb -> andWhere ( 'a.publishAt < :now OR a.publishAt IS NULL' ) -> andWhere ( 'a.active = :active' ) -> andWhere ( 'a.layout = :layout' ) ; if ( $ site == null ) { $ qb -> andWhere ( 'a.site IS NULL' ) ; } else { $ qb -> andWhere ( 'a.site = :site' ) -> setParameter ( 'site' , $ site ) ; } $ qb -> setParameter ( 'active' , true ) -> setParameter ( 'layout' , false ) -> setParameter ( 'now' , new \ DateTime ( ) ) ; if ( isset ( $ properties [ 'order_by' ] ) ) { $ direction = ( isset ( $ properties [ 'order_direction' ] ) ) ? $ properties [ 'order_direction' ] : 'ASC' ; $ qb -> orderBy ( 'a.' . $ properties [ 'order_by' ] , $ direction ) ; } $ limit = ( isset ( $ properties [ 'limit' ] ) ) ? $ properties [ 'limit' ] : 10 ; $ qb -> setMaxResults ( $ limit ) ; $ collection = $ qb -> getQuery ( ) -> getResult ( ) ; if ( $ collection ) { $ block -> setCollection ( $ collection ) ; } }
Load the collection if any conditions are defined .
14,169
protected function setResponseHeaders ( BlockInterface $ block , Response $ response ) { if ( $ block && $ block -> getReference ( ) ) { if ( $ this -> getReferenceService ( $ block ) -> isEsiEnabled ( $ block -> getReference ( ) ) ) { $ this -> getReferenceService ( $ block ) -> setResponseHeaders ( $ block -> getReference ( ) , $ response ) ; } else { $ response -> setLastModified ( $ block -> getReference ( ) -> getUpdatedAt ( ) ) ; $ response -> setPublic ( ) ; } } }
Sets the response headers defined on the reference service
14,170
public function listAction ( ) { $ source = new Entity ( $ this -> get ( 'opifer.form.post_manager' ) -> getClass ( ) ) ; $ formColumn = new TextColumn ( [ 'id' => 'posts' , 'title' => 'Form' , 'source' => false , 'filterable' => false , 'sortable' => false , 'safe' => false ] ) ; $ formColumn -> manipulateRenderCell ( function ( $ value , $ row , $ router ) { return '<a href="' . $ this -> generateUrl ( 'opifer_form_form_edit' , [ 'id' => $ row -> getEntity ( ) -> getForm ( ) -> getId ( ) ] ) . '">' . $ row -> getEntity ( ) -> getForm ( ) -> getName ( ) . '</a>' ; } ) ; $ viewAction = new RowAction ( 'view' , 'opifer_form_post_view' ) ; $ viewAction -> setRouteParameters ( [ 'id' ] ) ; $ deleteAction = new RowAction ( 'delete' , 'opifer_form_post_delete' ) ; $ deleteAction -> setRouteParameters ( [ 'id' ] ) ; $ grid = $ this -> get ( 'grid' ) ; $ grid -> setId ( 'posts' ) -> setSource ( $ source ) -> setDefaultOrder ( 'id' , 'desc' ) -> addColumn ( $ formColumn , 2 ) -> addRowAction ( $ viewAction ) -> addRowAction ( $ deleteAction ) ; return $ grid -> getGridResponse ( 'OpiferCmsBundle:Backend/Post:list.html.twig' ) ; }
Lists all posts from every form
14,171
public function onAfterRoute ( ) { $ app = JFactory :: getApplication ( ) ; $ username = $ app -> input -> server -> get ( 'PHP_AUTH_USER' , null , 'string' ) ; $ password = $ app -> input -> server -> get ( 'PHP_AUTH_PW' , null , 'string' ) ; if ( $ username && $ password ) { if ( ! $ this -> _login ( $ username , $ password , $ app ) ) { throw new Exception ( 'Login failed' , 401 ) ; } } }
Ask for authentication and log the user in into the application .
14,172
protected function _login ( $ username , $ password , $ application ) { if ( $ application -> login ( array ( 'username' => $ username , 'password' => $ password ) ) !== true ) { return false ; } if ( class_exists ( 'Koowa' ) ) { $ manager = KObjectManager :: getInstance ( ) ; $ request = $ manager -> getInstance ( ) -> getObject ( 'com:koowa.dispatcher.request' ) ; $ user = $ manager -> getInstance ( ) -> getObject ( 'user' ) ; $ token = $ user -> getSession ( ) -> getToken ( ) ; $ request -> setReferrer ( JUri :: root ( ) ) ; $ request -> getHeaders ( ) -> add ( array ( 'X-Xsrf-Token' => $ token ) ) ; $ request -> getCookies ( ) -> add ( array ( 'csrf_token' => $ token ) ) ; } return true ; }
Logs in a given user to an application .
14,173
public function getReadableFilesize ( ) { $ size = $ this -> filesize ; if ( $ size < 1 ) { return $ size ; } if ( $ size < 1024 ) { return $ size . 'b' ; } else { $ help = $ size / 1024 ; if ( $ help < 1024 ) { return round ( $ help , 1 ) . 'kb' ; } else { return round ( ( $ help / 1024 ) , 1 ) . 'mb' ; } } }
Get filesize with filesize extension .
14,174
public function createQueryBuilderFromRequest ( Request $ request ) { $ qb = $ this -> createQueryBuilder ( 'm' ) ; if ( $ request -> get ( 'ids' ) ) { $ ids = explode ( ',' , $ request -> get ( 'ids' ) ) ; $ qb -> andWhere ( 'm.id IN (:ids)' ) -> setParameter ( 'ids' , $ ids ) ; } $ qb -> andWhere ( 'm.status = :status' ) -> setParameter ( 'status' , Media :: STATUS_ENABLED ) ; if ( $ request -> get ( 'search' ) ) { $ qb -> andWhere ( 'm.name LIKE :term' ) -> setParameter ( 'term' , '%' . $ request -> get ( 'search' ) . '%' ) ; } if ( $ request -> get ( 'order' ) ) { $ direction = ( $ request -> get ( 'orderdir' ) ) ? $ request -> get ( 'orderdir' ) : 'asc' ; $ qb -> orderBy ( 'm.' . $ request -> get ( 'order' ) , $ direction ) ; } return $ qb ; }
Create the query builder from request .
14,175
public function search ( $ term , $ limit , $ offset , $ orderBy = null ) { $ qb = $ this -> createQueryBuilder ( 'm' ) ; $ qb -> where ( 'm.name LIKE :term' ) -> andWhere ( 'm.status IN (:statuses)' ) -> setParameters ( array ( 'term' => '%' . $ term . '%' , 'statuses' => array ( 0 , 1 ) , ) ) ; if ( $ limit ) { $ qb -> setMaxResults ( $ limit ) ; } if ( $ offset ) { $ qb -> setFirstResult ( $ offset ) ; } return $ qb -> getQuery ( ) -> getResult ( ) ; }
Search media items by a searchterm .
14,176
public function setQuerystring ( array $ str = array ( ) , $ append = true , $ default = true ) { if ( is_null ( $ this -> filterable ) ) { $ this -> resetFilterableOptions ( ) ; } if ( sizeof ( $ str ) == 0 && $ default ) { parse_str ( $ _SERVER [ 'QUERY_STRING' ] , $ this -> filterable [ 'qstring' ] ) ; } else { $ this -> filterable [ 'qstring' ] = $ str ; } if ( sizeof ( $ this -> filterable [ 'qstring' ] ) > 0 ) { if ( ! $ append ) { $ this -> filterable [ 'filters' ] = array ( ) ; } foreach ( $ this -> filterable [ 'qstring' ] as $ k => $ v ) { if ( $ v == '' ) { continue ; } $ thisColumn = isset ( $ this -> filterable [ 'columns' ] [ $ k ] ) ? $ this -> filterable [ 'columns' ] [ $ k ] : false ; if ( $ thisColumn ) { $ this -> filterable [ 'filters' ] [ $ thisColumn ] [ 'val' ] = $ v ; $ thisBoolData = isset ( $ this -> filterable [ 'qstring' ] [ 'bool' ] [ $ k ] ) ? $ this -> filterable [ 'qstring' ] [ 'bool' ] [ $ k ] : false ; $ thisBoolAvailable = $ thisBoolData && isset ( $ this -> filterable [ 'bools' ] [ $ thisBoolData ] ) ? $ this -> filterable [ 'bools' ] [ $ thisBoolData ] : false ; if ( $ thisBoolData && $ thisBoolAvailable ) { $ this -> filterable [ 'filters' ] [ $ thisColumn ] [ 'boolean' ] = $ thisBoolAvailable ; } else { $ this -> filterable [ 'filters' ] [ $ thisColumn ] [ 'boolean' ] = $ this -> filterable [ 'defaultWhere' ] ; } if ( isset ( $ this -> filterable [ 'qstring' ] [ 'operator' ] [ $ k ] ) && in_array ( $ this -> filterable [ 'qstring' ] [ 'operator' ] [ $ k ] , $ this -> filterable [ 'operators' ] ) ) { $ this -> filterable [ 'filters' ] [ $ thisColumn ] [ 'operator' ] = $ this -> filterable [ 'qstring' ] [ 'operator' ] [ $ k ] ; } else { $ this -> filterable [ 'filters' ] [ $ thisColumn ] [ 'operator' ] = $ this -> filterable [ 'defaultOperator' ] ; } } } } return $ this ; }
Parse the query string
14,177
public function scopeFilterColumns ( $ query , $ columns = array ( ) , $ validate = false ) { if ( sizeof ( $ columns ) > 0 ) { $ this -> setColumns ( $ columns ) ; } if ( $ validate ) { $ this -> validateColumns ( ) ; } if ( sizeof ( $ this -> filterable [ 'filters' ] ) == 0 ) { $ this -> setQuerystring ( ) ; } if ( sizeof ( $ this -> filterable [ 'filters' ] ) > 0 ) { foreach ( $ this -> filterable [ 'filters' ] as $ k => $ v ) { $ where = $ v [ 'boolean' ] ; if ( is_array ( $ v [ 'val' ] ) ) { if ( isset ( $ v [ 'val' ] [ 'start' ] ) && isset ( $ v [ 'val' ] [ 'end' ] ) ) { $ query -> whereBetween ( $ k , array ( $ v [ 'val' ] [ 'start' ] , $ v [ 'val' ] [ 'end' ] ) ) ; } else { $ query -> { $ where } ( function ( $ q ) use ( $ k , $ v , $ query ) { foreach ( $ v [ 'val' ] as $ key => $ val ) { $ q -> orWhere ( $ k , $ v [ 'operator' ] , $ val ) ; } } ) ; } } else { $ query -> { $ where } ( $ k , $ v [ 'operator' ] , $ v [ 'val' ] ) ; } } } if ( sizeof ( $ this -> filterable [ 'callbacks' ] ) > 0 ) { foreach ( $ this -> filterable [ 'callbacks' ] as $ v ) { $ v ( $ query ) ; } } if ( isset ( $ this -> filterable [ 'qstring' ] [ $ this -> filterable [ 'orderby' ] ] ) && isset ( $ this -> filterable [ 'columns' ] [ $ this -> filterable [ 'qstring' ] [ $ this -> filterable [ 'orderby' ] ] ] ) ) { $ order = isset ( $ this -> filterable [ 'qstring' ] [ $ this -> filterable [ 'order' ] ] ) ? $ this -> filterable [ 'qstring' ] [ $ this -> filterable [ 'order' ] ] : 'asc' ; $ query -> orderBy ( $ this -> filterable [ 'columns' ] [ $ this -> filterable [ 'qstring' ] [ $ this -> filterable [ 'orderby' ] ] ] , $ order ) ; } return $ query ; }
Laravel Eloquent query scope .
14,178
public function getAllBlocks ( ) { $ this -> load ( ) ; $ blocks = [ ] ; foreach ( $ this -> blockCache as $ blockCache ) { $ blocks = array_merge ( $ blocks , $ blockCache ) ; } return $ blocks ; }
Get all cached blocks
14,179
public function verify ( Signer $ signer , $ payload , $ key ) { return $ signer -> verify ( $ this -> hash , $ payload , $ key ) ; }
Verifies if the current hash matches with with the result of the creation of a new signature with given data
14,180
public function buildCreateForm ( FormBuilderInterface $ builder , array $ options ) { $ builder -> add ( 'files' , DropzoneType :: class , [ 'mapped' => false , 'path' => $ this -> router -> generate ( 'opifer_api_media_upload' ) , 'form_action' => $ this -> router -> generate ( 'opifer_media_media_updateall' ) , 'label' => '' , ] ) ; }
Build the add file form .
14,181
public function findByIds ( $ ids ) { if ( ! is_array ( $ ids ) ) { $ ids = explode ( ',' , $ ids ) ; } return $ this -> createQueryBuilder ( 'ml' ) -> andWhere ( 'ml.id IN (:ids)' ) -> setParameter ( 'ids' , $ ids ) -> getQuery ( ) -> getResult ( ) ; }
Find the mailinglist by an array of IDs
14,182
public function getDiscriminatorMap ( ) { $ map = array ( ) ; foreach ( $ this -> blockManager -> getValues ( ) as $ alias => $ value ) { $ map [ $ alias ] = $ value -> getEntity ( ) ; } return $ map ; }
Transforms the registered blocks into a discriminatorMap
14,183
public function validate ( $ value , Constraint $ constraint ) { if ( is_array ( $ value ) ) { $ value = json_encode ( $ value ) ; } if ( ! json_decode ( $ value , true ) ) { $ this -> context -> addViolation ( $ constraint -> message , array ( ) ) ; } }
Checks if the passed value is a valid JSON string . If it s already converted by for example Doctrine s json_array type encode the value first and then check if the encode value is valid .
14,184
public function createMissingValueSet ( Content $ content ) { if ( $ content -> getContentType ( ) !== null && $ content -> getValueSet ( ) === null ) { $ valueSet = new ValueSet ( ) ; $ this -> em -> persist ( $ valueSet ) ; $ valueSet -> setSchema ( $ content -> getContentType ( ) -> getSchema ( ) ) ; $ content -> setValueSet ( $ valueSet ) ; $ content = $ this -> save ( $ content ) ; } return $ content ; }
Creates a ValueSet entity for Content when missing and there is a ContentType set .
14,185
protected function stripMetadata ( array $ array , $ stripped = [ ] ) { $ allowed = [ 'id' , '__children' ] ; foreach ( $ array as $ item ) { if ( count ( $ item [ '__children' ] ) ) { $ item [ '__children' ] = $ this -> stripMetadata ( $ item [ '__children' ] , $ stripped ) ; } $ stripped [ ] = array_intersect_key ( $ item , array_flip ( $ allowed ) ) ; } return $ stripped ; }
Strips metadata that should not be stored
14,186
public function var_dump ( $ item ) { if ( $ this -> hasCollector ( 'vardump' ) ) { $ collector = $ this -> getCollector ( 'vardump' ) ; $ collector -> addVarDump ( $ item ) ; } }
Adds an item to the VarDumpCollector
14,187
public function preSetData ( FormEvent $ event ) { $ data = $ event -> getData ( ) ; $ form = $ event -> getForm ( ) ; $ fields = $ form -> getConfig ( ) -> getOption ( 'fields' ) ; if ( null === $ data || '' === $ data ) { $ data = [ ] ; } if ( ! is_array ( $ data ) && ! ( $ data instanceof \ Traversable && $ data instanceof \ ArrayAccess ) ) { throw new UnexpectedTypeException ( $ data , 'array or (\Traversable and \ArrayAccess)' ) ; } uasort ( $ data , function ( $ a , $ b ) { return $ a -> getAttribute ( ) -> getSort ( ) > $ b -> getAttribute ( ) -> getSort ( ) ; } ) ; foreach ( $ data as $ name => $ value ) { if ( ! empty ( $ fields ) && ! in_array ( $ name , $ fields ) ) { continue ; } if ( $ form -> has ( $ name ) ) { continue ; } $ form -> add ( $ name , ValueType :: class , [ 'label' => $ value -> getAttribute ( ) -> getDisplayName ( ) , 'required' => $ value -> getAttribute ( ) -> getRequired ( ) , 'attribute' => $ value -> getAttribute ( ) , 'entity' => get_class ( $ value ) , 'value' => $ value , 'attr' => [ 'help_text' => $ value -> getAttribute ( ) -> getDescription ( ) ] ] ) ; } }
Listens to the PRE_SET_DATA event and adds form fields dynamically .
14,188
public function verifyHash ( array $ params ) { $ result = false ; try { $ this -> sdk -> CheckOutFeedback ( $ params ) ; $ result = true ; } catch ( Exception $ e ) { } return $ result ; }
Verify if the hash of the given parameter is correct .
14,189
public function editAction ( Request $ request , $ id ) { $ manager = $ this -> get ( 'opifer.redirect.redirect_manager' ) ; $ redirect = $ manager -> getRepository ( ) -> find ( $ id ) ; $ form = $ this -> createForm ( RedirectType :: class , $ redirect ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ manager -> save ( $ redirect ) ; $ this -> addFlash ( 'success' , $ this -> get ( 'translator' ) -> trans ( 'opifer_redirect.flash.updated' ) ) ; return $ this -> redirectToRoute ( 'opifer_redirect_redirect_edit' , [ 'id' => $ redirect -> getId ( ) ] ) ; } return $ this -> render ( $ this -> container -> getParameter ( 'opifer_redirect.redirect_edit_view' ) , [ 'form' => $ form -> createView ( ) , 'redirect' => $ redirect ] ) ; }
Edit a redirect
14,190
public function deleteAction ( $ id ) { $ manager = $ this -> get ( 'opifer.redirect.redirect_manager' ) ; $ redirect = $ manager -> getRepository ( ) -> find ( $ id ) ; $ manager -> remove ( $ redirect ) ; $ this -> addFlash ( 'success' , $ this -> get ( 'translator' ) -> trans ( 'opifer_redirect.flash.deleted' ) ) ; return $ this -> redirectToRoute ( 'opifer_redirect_redirect_index' ) ; }
Delete a redirect
14,191
public function getContentByReference ( $ reference ) { if ( is_numeric ( $ reference ) ) { $ nestedContent = $ this -> getRepository ( ) -> find ( $ reference ) ; } else { $ template = $ this -> em -> getRepository ( $ this -> templateClass ) -> findOneByName ( $ reference ) ; $ nestedContent = $ this -> eavManager -> initializeEntity ( $ template ) ; $ nestedContent -> setNestedDefaults ( ) ; } return $ nestedContent ; }
Get the content by a reference
14,192
private function detachAndPersist ( $ entity ) { $ this -> em -> detach ( $ entity ) ; $ this -> em -> persist ( $ entity ) ; }
For cloning purpose
14,193
private function hasChangedParent ( SluggableAdapter $ ea , $ object , $ getter ) { $ relation = $ object -> $ getter ( ) ; if ( ! $ relation ) { return false ; } $ changeSet = $ ea -> getObjectChangeSet ( $ this -> om -> getUnitOfWork ( ) , $ relation ) ; if ( isset ( $ changeSet [ $ this -> usedOptions [ 'relationField' ] ] ) ) { return true ; } return $ this -> hasChangedParent ( $ ea , $ relation , $ getter ) ; }
Check if the given object has a changed parent recursively
14,194
public function typeAction ( $ type ) { $ contentType = $ this -> get ( 'opifer.content.content_type_manager' ) -> getRepository ( ) -> find ( $ type ) ; if ( ! $ contentType ) { throw $ this -> createNotFoundException ( sprintf ( 'Content Type with ID %d could not be found.' , $ type ) ) ; } $ queryBuilder = $ this -> get ( 'opifer.content.content_manager' ) -> getRepository ( ) -> createQueryBuilder ( 'c' ) -> select ( 'c' , 'vs' , 'v' , 'a' ) -> leftJoin ( 'c.valueSet' , 'vs' ) -> leftJoin ( 'vs.values' , 'v' ) -> leftJoin ( 'v.attribute' , 'a' ) ; $ source = new Entity ( $ this -> getParameter ( 'opifer_content.content_class' ) ) ; $ source -> initQueryBuilder ( $ queryBuilder ) ; $ tableAlias = $ source -> getTableAlias ( ) ; $ source -> manipulateQuery ( function ( $ query ) use ( $ tableAlias , $ contentType ) { $ query -> andWhere ( $ tableAlias . '.contentType = :contentType' ) -> setParameter ( 'contentType' , $ contentType ) ; $ query -> andWhere ( $ tableAlias . '.layout = :layout' ) -> setParameter ( 'layout' , false ) ; } ) ; $ designAction = new RowAction ( 'button.design' , 'opifer_content_contenteditor_design' ) ; $ designAction -> setRouteParameters ( [ 'id' , 'owner' => 'content' ] ) ; $ designAction -> setRouteParametersMapping ( [ 'id' => 'ownerId' ] ) ; $ detailsAction = new RowAction ( 'button.details' , 'opifer_content_content_edit' ) ; $ detailsAction -> setRouteParameters ( [ 'id' ] ) ; $ grid = $ this -> get ( 'grid' ) ; $ grid -> setId ( 'content' ) -> setSource ( $ source ) -> addRowAction ( $ detailsAction ) -> addRowAction ( $ designAction ) ; foreach ( $ contentType -> getSchema ( ) -> getAttributes ( ) as $ attribute ) { $ name = $ attribute -> getName ( ) ; $ column = new AttributeColumn ( [ 'id' => $ name , 'field' => 'valueSet.values.value' , 'title' => $ attribute -> getDisplayName ( ) , 'visible' => false , 'attribute' => $ name , 'source' => true ] ) ; $ column -> manipulateRenderCell ( function ( $ value , $ row , $ router ) use ( $ name ) { $ value = $ row -> getEntity ( ) -> getAttributes ( ) [ $ name ] ; return $ value ; } ) ; $ grid -> addColumn ( $ column ) ; } return $ grid -> getGridResponse ( $ this -> getParameter ( 'opifer_content.content_type_view' ) , [ 'content_type' => $ contentType , 'grid' => $ grid , ] ) ; }
Index view of content by type
14,195
public function getTemperature ( $ withUnit = false ) { if ( ! $ this -> lastResponse || ! isset ( $ this -> lastResponse [ 'item' ] [ 'condition' ] [ 'temp' ] ) ) { return '' ; } $ return = $ this -> lastResponse [ 'item' ] [ 'condition' ] [ 'temp' ] ; if ( $ withUnit ) { $ return .= ' ' . $ this -> lastResponse [ 'units' ] [ 'temperature' ] ; } return $ return ; }
Get current temperature .
14,196
public function getWind ( $ withUnit = false ) { if ( ! $ this -> lastResponse || ! isset ( $ this -> lastResponse [ 'wind' ] [ 'speed' ] ) ) { return array ( ) ; } $ response = array ( 'chill' => $ this -> lastResponse [ 'wind' ] [ 'chill' ] , 'direction' => $ this -> lastResponse [ 'wind' ] [ 'direction' ] , 'speed' => $ this -> lastResponse [ 'wind' ] [ 'speed' ] , ) ; if ( $ withUnit ) { $ response [ 'speed' ] .= ' ' . $ this -> lastResponse [ 'units' ] [ 'speed' ] ; } return $ response ; }
get Wind .
14,197
public function subscribeAction ( Block $ block ) { $ response = $ this -> execute ( $ block ) ; $ properties = $ block -> getProperties ( ) ; if ( $ this -> subscribed && isset ( $ properties [ 'responseType' ] ) && $ properties [ 'responseType' ] == 'redirect' ) { $ content = $ this -> contentManager -> getRepository ( ) -> find ( $ properties [ 'responseContent' ] ) ; $ response = new RedirectResponse ( $ this -> router -> generate ( '_content' , [ 'slug' => $ content -> getSlug ( ) ] ) ) ; } return $ response ; }
Processes a POST request to subscribe .
14,198
public function transform ( $ slug ) { if ( null === $ slug ) { return ; } if ( substr ( $ slug , - 1 ) == '/' ) { return '/' ; } $ array = explode ( '/' , $ slug ) ; $ slug = end ( $ array ) ; return $ slug ; }
Removes the directory path from the slug .
14,199
public function create ( ) { $ class = $ this -> getClass ( ) ; $ contentType = new $ class ( ) ; $ schema = $ this -> schemaManager -> create ( ) ; $ schema -> setObjectClass ( $ this -> contentManager -> getClass ( ) ) ; $ contentType -> setSchema ( $ schema ) ; return $ contentType ; }
Create a new contentType instance .