idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
12,400
private function parseUrl ( $ url ) { $ parsed = parse_url ( $ url ) ; if ( ( count ( $ parsed ) === 1 ) && isset ( $ parsed [ 'path' ] ) && ( 0 === strpos ( $ parsed [ 'path' ] , '?' ) || false !== strpos ( $ parsed [ 'path' ] , '&' ) ) ) { $ parsed = array ( 'query' => $ parsed [ 'path' ] ) ; return $ parsed ; } return $ parsed ; }
Parse the URL and fix up if it only contains only one element to make it the query element .
12,401
function setWidth ( $ width ) { if ( ! preg_match ( '!^(\d+)(.*)$!' , $ width , $ _match ) ) return false ; $ _width = $ _match [ 1 ] ; $ _type = $ _match [ 2 ] ; if ( $ _type == '%' ) $ this -> width = $ _width . '%' ; else $ this -> width = $ _width . 'px' ; return true ; }
sets the width of the map
12,402
function setHeight ( $ height ) { if ( ! preg_match ( '!^(\d+)(.*)$!' , $ height , $ _match ) ) return false ; $ _height = $ _match [ 1 ] ; $ _type = $ _match [ 2 ] ; if ( $ _type == '%' ) $ this -> height = $ _height . '%' ; else $ this -> height = $ _height . 'px' ; return true ; }
sets the height of the map
12,403
function setClusterOptions ( $ zoom = "null" , $ gridsize = "null" , $ styles = "null" ) { $ this -> marker_clusterer_options [ "maxZoom" ] = $ zoom ; $ this -> marker_clusterer_options [ "gridSize" ] = $ gridsize ; $ this -> marker_clusterer_options [ "styles" ] = $ styles ; }
set clustering options
12,404
function addMarkerOpener ( $ marker_id , $ dom_id ) { if ( $ this -> info_window === false || ! isset ( $ this -> _markers [ $ marker_id ] ) ) return false ; if ( ! isset ( $ this -> _markers [ $ marker_id ] [ "openers" ] ) ) $ this -> _markers [ $ marker_id ] [ "openers" ] = array ( ) ; $ this -> _markers [ $ marker_id ] [ "openers" ] [ ] = $ dom_id ; }
adds a DOM object ID to specified marker to open the marker s info window . Does nothing if the info windows is disabled .
12,405
function addPolyLineByAddress ( $ address1 , $ address2 , $ id = false , $ color = '' , $ weight = 0 , $ opacity = 0 ) { if ( ( $ _geocode1 = $ this -> getGeocode ( $ address1 ) ) === false ) return false ; if ( ( $ _geocode2 = $ this -> getGeocode ( $ address2 ) ) === false ) return false ; return $ this -> addPolyLineByCoords ( $ _geocode1 [ 'lon' ] , $ _geocode1 [ 'lat' ] , $ _geocode2 [ 'lon' ] , $ _geocode2 [ 'lat' ] , $ id , $ color , $ weight , $ opacity ) ; }
adds a map polyline by address if color weight and opacity are not defined use the google maps defaults
12,406
function addPolyLineByCoords ( $ lon1 , $ lat1 , $ lon2 , $ lat2 , $ id = false , $ color = '' , $ weight = 0 , $ opacity = 0 ) { if ( $ id !== false && isset ( $ this -> _polylines [ $ id ] ) && is_array ( $ this -> _polylines [ $ id ] ) ) { $ _polyline = $ this -> _polylines [ $ id ] ; } else { $ _polyline = array ( "color" => $ color , "weight" => $ weight , "opacity" => $ opacity ) ; } if ( ! isset ( $ _polyline [ 'coords' ] ) || ! is_array ( $ _polyline [ 'coords' ] ) ) { $ _polyline [ 'coords' ] = array ( "0" => array ( "lat" => $ lat1 , "long" => $ lon1 ) , "1" => array ( "lat" => $ lat2 , "long" => $ lon2 ) ) ; } else { $ last_index = sizeof ( $ _polyline [ 'coords' ] ) - 1 ; if ( $ _polyline [ 'coords' ] [ $ last_index ] [ "lat" ] != $ lat1 || $ _polyline [ 'coords' ] [ $ last_index ] [ "long" ] != $ lon1 ) { $ _polyline [ 'coords' ] [ ] = array ( "lat" => $ lat1 , "long" => $ lon1 ) ; } $ _polyline [ 'coords' ] [ ] = array ( "lat" => $ lat2 , "long" => $ lon2 ) ; } if ( $ id === false ) { $ this -> _polylines [ ] = $ _polyline ; $ id = count ( $ this -> _polylines ) - 1 ; } else { $ this -> _polylines [ $ id ] = $ _polyline ; } $ this -> adjustCenterCoords ( $ lon1 , $ lat1 ) ; $ this -> adjustCenterCoords ( $ lon2 , $ lat2 ) ; return $ id ; }
adds a map polyline by map coordinates if color weight and opacity are not defined use the google maps defaults
12,407
function addPolylineElevation ( $ polyline_id , $ elevation_dom_id , $ samples = 256 , $ width = "" , $ height = "" , $ focus_color = "#00ff00" ) { if ( isset ( $ this -> _polylines [ $ polyline_id ] ) ) { $ this -> _elevation_polylines [ $ polyline_id ] = array ( "dom_id" => $ elevation_dom_id , "samples" => $ samples , "width" => ( $ width != "" ? $ width : str_replace ( "px" , "" , $ this -> width ) ) , "height" => ( $ height != "" ? $ height : str_replace ( "px" , "" , $ this -> height ) / 2 ) , "focus_color" => $ focus_color ) ; } }
function to add an elevation profile for a polyline to the page
12,408
function addOverlay ( $ bds_lat1 , $ bds_lon1 , $ bds_lat2 , $ bds_lon2 , $ img_src , $ opacity = 100 ) { $ _overlay = array ( "bounds" => array ( "ne" => array ( "lat" => $ bds_lat1 , "long" => $ bds_lon1 ) , "sw" => array ( "lat" => $ bds_lat2 , "long" => $ bds_lon2 ) ) , "img" => $ img_src , "opacity" => $ opacity / 10 ) ; $ this -> adjustCenterCoords ( $ bds_lon1 , $ bds_lat1 ) ; $ this -> adjustCenterCoords ( $ bds_lon2 , $ bds_lat2 ) ; $ this -> _overlays [ ] = $ _overlay ; return count ( $ this -> _overlays ) - 1 ; }
function to add an overlay to the map .
12,409
function setMarkerIconKey ( $ iconImage , $ iconShadow = '' , $ iconAnchorX = 'x' , $ iconAnchorY = 'x' , $ infoWindowAnchorX = 'x' , $ infoWindowAnchorY = 'x' ) { $ _iconKey = $ this -> getIconKey ( $ iconImage , $ iconShadow ) ; if ( isset ( $ this -> _marker_icons [ $ _iconKey ] ) ) { return $ _iconKey ; } else { return $ this -> addIcon ( $ iconImage , $ iconShadow , $ iconAnchorX , $ iconAnchorY , $ infoWindowAnchorX , $ infoWindowAnchorY ) ; } }
function to check if icon is in class marker_iconset if it is returns the key if not creates a new array indice and returns the key
12,410
function addIcon ( $ iconImage , $ iconShadowImage = '' , $ iconAnchorX = 'x' , $ iconAnchorY = 'x' , $ infoWindowAnchorX = 'x' , $ infoWindowAnchorY = 'x' ) { $ _iconKey = $ this -> getIconKey ( $ iconImage , $ iconShadowImage ) ; $ this -> _marker_icons [ $ _iconKey ] = $ this -> createMarkerIcon ( $ iconImage , $ iconShadowImage , $ iconAnchorX , $ iconAnchorY , $ infoWindowAnchorX , $ infoWindowAnchorY ) ; return $ _iconKey ; }
add an icon to iconset
12,411
function getAddMarkersJS ( $ map_id = "" , $ pano = false ) { if ( $ map_id == "" ) { $ map_id = $ this -> map_id ; } if ( $ pano == false ) { $ _prefix = "map" ; } else { $ _prefix = "panorama" . $ this -> street_view_dom_id ; } $ _output = '' ; foreach ( $ this -> _markers as $ _marker ) { $ iw_html = str_replace ( '"' , '\"' , str_replace ( array ( "\n" , "\r" ) , "" , $ _marker [ 'html' ] ) ) ; $ _output .= "var point = new google.maps.LatLng(" . $ _marker [ 'lat' ] . "," . $ _marker [ 'lon' ] . ");\n" ; $ _output .= sprintf ( '%s.push(createMarker(%s%s, point,"%s","%s", %s, %s, "%s", %s ));' , ( ( $ pano == true ) ? $ _prefix : "" ) . "markers" . $ map_id , $ _prefix , $ map_id , str_replace ( '"' , '\"' , $ _marker [ 'title' ] ) , str_replace ( '/' , '\/' , $ iw_html ) , ( isset ( $ _marker [ "icon_key" ] ) ) ? "icon" . $ map_id . "['" . $ _marker [ "icon_key" ] . "'].image" : "''" , ( isset ( $ _marker [ "icon_key" ] ) && isset ( $ _marker [ "shadow_icon" ] ) ) ? "icon" . $ map_id . "['" . $ _marker [ "icon_key" ] . "'].shadow" : "''" , ( ( $ this -> sidebar ) ? $ this -> sidebar_id : "" ) , ( ( isset ( $ _marker [ "openers" ] ) && count ( $ _marker [ "openers" ] ) > 0 ) ? json_encode ( $ _marker [ "openers" ] ) : "''" ) ) . "\n" ; } if ( $ this -> marker_clusterer && $ pano == false ) { $ _output .= " markerClusterer" . $ map_id . " = new MarkerClusterer(" . $ _prefix . $ map_id . ", markers" . $ map_id . ", { maxZoom: " . $ this -> marker_clusterer_options [ "maxZoom" ] . ", gridSize: " . $ this -> marker_clusterer_options [ "gridSize" ] . ", styles: " . $ this -> marker_clusterer_options [ "styles" ] . " }); " ; } return $ _output ; }
overridable function for generating js to add markers
12,412
function getPolylineJS ( ) { $ _output = '' ; foreach ( $ this -> _polylines as $ polyline_id => $ _polyline ) { $ _coords_output = "" ; foreach ( $ _polyline [ "coords" ] as $ _coords ) { if ( $ _coords_output != "" ) { $ _coords_output .= "," ; } $ _coords_output .= " new google.maps.LatLng(" . $ _coords [ "lat" ] . ", " . $ _coords [ "long" ] . ") " ; } $ _output .= " polylineCoords" . $ this -> map_id . "[$polyline_id] = [" . $ _coords_output . "]; polylines" . $ this -> map_id . "[$polyline_id] = new google.maps.Polyline({ path: polylineCoords" . $ this -> map_id . "[$polyline_id] " . ( ( $ _polyline [ 'color' ] != "" ) ? ", strokeColor: '" . $ _polyline [ 'color' ] . "'" : "" ) . " " . ( ( $ _polyline [ 'opacity' ] != 0 ) ? ", strokeOpacity: " . $ _polyline [ 'opacity' ] . "" : "" ) . " " . ( ( $ _polyline [ 'weight' ] != 0 ) ? ", strokeWeight: " . $ _polyline [ 'weight' ] . "" : "" ) . " }); polylines" . $ this -> map_id . "[$polyline_id].setMap(map" . $ this -> map_id . "); " ; if ( ! empty ( $ this -> _elevation_polylines ) && isset ( $ this -> _elevation_polylines [ $ polyline_id ] ) ) { $ elevation_dom_id = $ this -> _elevation_polylines [ $ polyline_id ] [ "dom_id" ] ; $ width = $ this -> _elevation_polylines [ $ polyline_id ] [ "width" ] ; $ height = $ this -> _elevation_polylines [ $ polyline_id ] [ "height" ] ; $ samples = $ this -> _elevation_polylines [ $ polyline_id ] [ "samples" ] ; $ focus_color = $ this -> _elevation_polylines [ $ polyline_id ] [ "focus_color" ] ; $ _output .= " elevationPolylines" . $ this -> map_id . "[$polyline_id] = { 'selector':'$elevation_dom_id', 'chart': new google.visualization.ColumnChart(document.getElementById('$elevation_dom_id')), 'service': new google.maps.ElevationService(), 'width':$width, 'height':$height, 'focusColor':'$focus_color', 'marker':null }; elevationPolylines" . $ this -> map_id . "[$polyline_id]['service'].getElevationAlongPath({ path: polylineCoords" . $ this -> map_id . "[$polyline_id], samples: $samples }, function(results,status){plotElevation(results,status, elevationPolylines" . $ this -> map_id . "[$polyline_id], map" . $ this -> map_id . ", elevationCharts" . $ this -> map_id . ");}); " ; } } return $ _output ; }
overridable function to generate polyline js - for now can only be used on a map not a streetview
12,413
function getAddDirectionsJS ( ) { $ _output = "" ; foreach ( $ this -> _directions as $ directions ) { $ dom_id = $ directions [ "dom_id" ] ; $ travelModeParams = array ( ) ; $ directionsParams = "" ; if ( $ this -> walking_directions == TRUE ) $ directionsParams .= ", \n travelMode:google.maps.DirectionsTravelMode.WALKING" ; else if ( $ this -> biking_directions == TRUE ) $ directionsParams .= ", \n travelMode:google.maps.DirectionsTravelMode.BICYCLING" ; else $ directionsParams .= ", \n travelMode:google.maps.DirectionsTravelMode.DRIVING" ; if ( $ this -> avoid_highways == TRUE ) $ directionsParams .= ", \n avoidHighways: true" ; if ( $ this -> avoid_tollways == TRUE ) $ directionsParams .= ", \n avoidTolls: true" ; if ( $ this -> directions_unit_system != '' ) { if ( $ this -> directions_unit_system == 'METRIC' ) { $ directionsParams .= ", \n unitSystem: google.maps.DirectionsUnitSystem.METRIC" ; } else { $ directionsParams .= ", \n unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL" ; } } $ _output .= " directions" . $ this -> map_id . "['$dom_id'] = { displayRenderer:new google.maps.DirectionsRenderer(), directionService:new google.maps.DirectionsService(), request:{ waypoints: [{$this->_waypoints_string}], origin: '" . $ directions [ "start" ] . "', destination: '" . $ directions [ "dest" ] . "' $directionsParams } " . ( ( $ this -> elevation_directions ) ? ", selector: '" . $ directions [ "elevation_dom_id" ] . "', chart: new google.visualization.ColumnChart(document.getElementById('" . $ directions [ "elevation_dom_id" ] . "')), service: new google.maps.ElevationService(), width:" . $ directions [ "width" ] . ", height:" . $ directions [ "height" ] . ", focusColor:'#00FF00', marker:null " : "" ) . " }; directions" . $ this -> map_id . "['$dom_id'].displayRenderer.setMap(map" . $ this -> map_id . "); directions" . $ this -> map_id . "['$dom_id'].displayRenderer.setPanel(document.getElementById('$dom_id')); directions" . $ this -> map_id . "['$dom_id'].directionService.route(directions" . $ this -> map_id . "['$dom_id'].request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directions" . $ this -> map_id . "['$dom_id'].displayRenderer.setDirections(response); " . ( ( $ this -> elevation_directions ) ? " directions" . $ this -> map_id . "['$dom_id'].service.getElevationAlongPath({ path: response.routes[0].overview_path, samples: " . $ directions [ "elevation_samples" ] . " }, function(results,status){plotElevation(results,status, directions" . $ this -> map_id . "['$dom_id'], map" . $ this -> map_id . ", elevationCharts" . $ this -> map_id . ");}); " : "" ) . " } }); " ; } return $ _output ; }
function to render proper calls for directions - for now can only be used on a map not a streetview
12,414
function getAddOverlayJS ( ) { $ _output = "" ; foreach ( $ this -> _overlays as $ _key => $ _overlay ) { $ _output .= " var bounds = new google.maps.LatLngBounds(new google.maps.LatLng(" . $ _overlay [ "bounds" ] [ "ne" ] [ "lat" ] . ", " . $ _overlay [ "bounds" ] [ "ne" ] [ "long" ] . "), new google.maps.LatLng(" . $ _overlay [ "bounds" ] [ "sw" ] [ "lat" ] . ", " . $ _overlay [ "bounds" ] [ "sw" ] [ "long" ] . ")); var image = '" . $ _overlay [ "img" ] . "'; overlays" . $ this -> map_id . "[$_key] = new CustomOverlay(bounds, image, map" . $ this -> map_id . ", " . $ _overlay [ "opacity" ] . "); " ; } return $ _output ; }
function to get overlay creation JS .
12,415
function getCreateMarkerJS ( ) { $ _output = " function createMarker(map, point, title, html, icon, icon_shadow, sidebar_id, openers){ var marker_options = { position: point, map: map, title: title}; if(icon!=''){marker_options.icon = icon;} if(icon_shadow!=''){marker_options.shadow = icon_shadow;} //create marker var new_marker = new google.maps.Marker(marker_options); if(html!=''){ " . ( ( $ this -> info_window ) ? " google.maps.event.addListener(new_marker, '" . $ this -> window_trigger . "', function() { infowindow.close(); infowindow.setContent(html); infowindow.open(map,new_marker); }); if(openers != ''&&!isEmpty(openers)){ for(var i in openers){ var opener = document.getElementById(openers[i]); opener.on" . $ this -> window_trigger . " = function() { infowindow.close(); infowindow.setContent(html); infowindow.open(map,new_marker); return false; }; } } " : "" ) . " if(sidebar_id != ''){ var sidebar = document.getElementById(sidebar_id); if(sidebar!=null && sidebar!=undefined && title!=null && title!=''){ var newlink = document.createElement('a'); " . ( ( $ this -> info_window ) ? " newlink.onclick=function(){infowindow.open(map,new_marker); return false}; " : " newlink.onclick=function(){map.setCenter(point); return false}; " ) . " newlink.innerHTML = title; sidebar.appendChild(newlink); } } } return new_marker; } " ; return $ _output ; }
overridable function to generate the js for the js function for creating a marker .
12,416
function geoGetDistance ( $ lat1 , $ lon1 , $ lat2 , $ lon2 , $ unit = 'M' ) { $ M = 69.09 * rad2deg ( acos ( sin ( deg2rad ( $ lat1 ) ) * sin ( deg2rad ( $ lat2 ) ) + cos ( deg2rad ( $ lat1 ) ) * cos ( deg2rad ( $ lat2 ) ) * cos ( deg2rad ( $ lon1 - $ lon2 ) ) ) ) ; switch ( strtoupper ( $ unit ) ) { case 'K' : return $ M * 1.609344 ; break ; case 'N' : return $ M * 0.868976242 ; break ; case 'F' : return $ M * 5280 ; break ; case 'I' : return $ M * 63360 ; break ; case 'M' : default : return $ M ; break ; } }
get distance between to geocoords using great circle distance formula
12,417
public function getHome ( $ track = true ) { $ home = PublishedNode :: whereHome ( 1 ) -> firstOrFail ( ) ; $ this -> track ( $ track , $ home ) ; return $ home ; }
Returns the home node
12,418
public function getNode ( $ name , $ track = true , $ published = true ) { if ( $ this -> withPublishedOnly ( $ published ) ) { $ node = PublishedNode :: withName ( $ name ) ; } else { $ node = Node :: withName ( $ name ) ; } $ node = $ node -> firstOrFail ( ) ; $ this -> track ( $ track , $ node ) ; return $ node ; }
Returns a node by name
12,419
protected function withPublishedOnly ( $ published ) { if ( $ published === false ) { return false ; } if ( $ this -> tokenManager -> requestHasToken ( 'preview_nodes' ) ) { return false ; } return true ; }
Checks if the request includes unpublished nodes as well
12,420
public function getNodeAndSetLocale ( $ name , $ track = true , $ published = true ) { $ node = $ this -> getNode ( $ name , $ track , $ published ) ; $ locale = $ node -> getLocaleForNodeName ( $ name ) ; set_app_locale ( $ locale ) ; return $ node ; }
Returns a node by name and sets the locale
12,421
public function getSearchNodeBuilder ( $ keywords , $ type = null , $ limit = null , $ locale = null ) { $ builder = PublishedNode :: withoutGlobalScopes ( ) -> published ( ) -> typeMailing ( ) -> translatedIn ( $ locale ) -> groupBy ( 'nodes.id' ) ; if ( $ type ) { $ builder -> withType ( $ type ) ; } if ( $ limit ) { $ builder -> limit ( $ limit ) ; } $ builder -> search ( $ keywords , 20 , true ) ; return $ builder ; }
Gets node searching builder
12,422
public function searchNodes ( $ keywords , $ type = null , $ limit = null , $ locale = null ) { return $ this -> getSearchNodeBuilder ( $ keywords , $ type , $ limit , $ locale ) -> get ( ) ; }
Searches for nodes
12,423
public function getSortedNodesBuilder ( $ key = null , $ direction = null , $ type = null , $ limit = null , $ locale = null ) { $ builder = PublishedNode :: translatedIn ( $ locale ) -> groupBy ( 'nodes.id' ) ; if ( $ type ) { $ builder -> withType ( $ type ) ; } if ( $ limit ) { $ builder -> limit ( $ limit ) ; } return $ builder -> sortable ( $ key , $ direction ) ; }
Gets node sortable builder
12,424
public function getSortedNodes ( $ key = null , $ direction = null , $ type = null , $ limit = null , $ locale = null ) { return $ this -> getSortedNodesBuilder ( $ key , $ direction , $ type , $ limit , $ locale ) -> paginate ( ) ; }
Gets sorted nodes
12,425
public function getNodeById ( $ id , $ published ) { return $ published ? PublishedNode :: find ( $ id ) : Node :: find ( $ id ) ; }
Returns a node by id
12,426
public function getNodesByIds ( $ ids , $ published = true ) { if ( empty ( $ ids ) ) { return null ; } if ( is_string ( $ ids ) ) { $ ids = json_decode ( $ ids , true ) ; } if ( is_array ( $ ids ) && ! empty ( $ ids ) ) { $ placeholders = implode ( ',' , array_fill ( 0 , count ( $ ids ) , '?' ) ) ; $ nodes = Node :: whereIn ( 'id' , $ ids ) -> orderByRaw ( 'field(id,' . $ placeholders . ')' , $ ids ) ; if ( $ published ) { $ nodes -> published ( ) ; } $ nodes = $ nodes -> get ( ) ; return ( count ( $ nodes ) > 0 ) ? $ nodes : null ; } return null ; }
Returns nodes by ids
12,427
public function initialize ( ) { if ( $ this -> isInitialized ( ) ) { $ this -> close ( ) ; } if ( ! ( $ this -> curl = curl_init ( ) ) ) { throw new CurlException ( 'Could not initialize a cURL resource' ) ; } return true ; }
Initialize a new cURL resource
12,428
public function setOption ( $ option , $ value ) { $ this -> autoInitialize ( ) ; return curl_setopt ( $ this -> curl , $ option , $ value ) ; }
Set cURL option
12,429
public function getRequestInfo ( $ key = null ) { if ( ! $ this -> isInitialized ( ) ) { return $ key ? '' : [ ] ; } return $ key ? curl_getinfo ( $ this -> curl , $ key ) : curl_getinfo ( $ this -> curl ) ; }
Get additional information about the last cURL request
12,430
public function reset ( ) { if ( ! $ this -> isInitialized ( ) || ! function_exists ( 'curl_reset' ) ) { $ this -> initialize ( ) ; } else { curl_reset ( $ this -> curl ) ; $ this -> response = null ; } }
Reset all cURL options
12,431
public function close ( ) { if ( $ this -> isInitialized ( ) ) { curl_close ( $ this -> curl ) ; $ this -> curl = null ; $ this -> response = null ; } }
Close the cURL resource
12,432
private function parseUrl ( $ string , $ decode ) { $ this -> autoInitialize ( ) ; $ function = $ decode ? 'curl_unescape' : 'curl_escape' ; if ( ! function_exists ( $ function ) ) { return $ decode ? rawurldecode ( $ string ) : rawurlencode ( $ string ) ; } return call_user_func ( $ function , $ this -> curl , $ string ) ; }
Encode or decode a URL
12,433
public function user ( Model $ Model , $ result , $ key = null ) { if ( method_exists ( $ Model , 'user' ) ) { return $ Model -> user ( $ key , $ result ) ; } if ( class_exists ( 'AuthComponent' ) ) { return AuthComponent :: user ( $ key ) ; } if ( class_exists ( 'Authsome' ) ) { return Authsome :: get ( $ key ) ; } if ( method_exists ( $ Model , 'get' ) ) { $ className = get_class ( $ Model ) ; $ ref = new ReflectionMethod ( $ className , 'get' ) ; if ( $ ref -> isStatic ( ) ) { return $ className :: get ( $ key ) ; } } return false ; }
Wrapper around retrieving user data
12,434
public function permit ( Model $ Model , $ settings = array ( ) ) { $ this -> modelDefaultsPersist [ $ Model -> alias ] = $ this -> modelDefaults [ $ Model -> alias ] ; $ this -> modelDefaults [ $ Model -> alias ] = array_merge ( $ this -> modelDefaults [ $ Model -> alias ] , $ settings ) ; }
Used to dynamically assign permit settings
12,435
public function get ( ) { $ this -> scripts ( ) ; return app ( 'antares.form' ) -> of ( "antares.widgets: notification-widget" ) -> extend ( function ( FormGrid $ form ) { $ form -> name ( 'Notification Tester' ) ; $ form -> simple ( handles ( 'antares::notifications/widgets/send' ) , [ 'id' => 'notification-widget-form' ] ) ; $ form -> layout ( 'antares/notifications::widgets.forms.send_notification_form' ) ; $ form -> fieldset ( trans ( 'Default Fieldset' ) , function ( Fieldset $ fieldset ) { $ fieldset -> control ( 'input:hidden' , 'url' ) -> attributes ( [ 'class' => 'notification-widget-url' ] ) -> value ( handles ( 'antares::notifications/notifications' ) ) -> block ( [ 'class' => 'hidden' ] ) ; $ fieldset -> control ( 'select' , 'type' ) -> attributes ( [ 'class' => 'notification-widget-change-type-select' , 'url' => handles ( 'antares::notifications/notifications' ) ] ) -> options ( $ this -> repository -> getDecoratedNotificationTypes ( ) ) -> wrapper ( [ 'class' => 'w200' ] ) ; $ fieldset -> control ( 'select' , 'notifications' ) -> attributes ( [ 'class' => 'notification-widget-notifications-select' ] ) -> options ( $ this -> repository -> getNotificationContents ( 'email' ) -> pluck ( 'title' , 'id' ) ) -> wrapper ( [ 'class' => 'w300' ] ) ; if ( ! is_null ( from_route ( 'user' ) ) ) { $ fieldset -> control ( 'button' , 'send' ) -> attributes ( [ 'type' => 'submit' , 'class' => 'notification-widget-send-button' , 'data-title' => trans ( 'Are you sure to send notification?' ) , 'url' => handles ( 'antares::notifications/widgets/send' ) , ] ) -> value ( trans ( 'Send' ) ) ; } $ fieldset -> control ( 'button' , 'test' ) -> attributes ( [ 'type' => 'submit' , 'class' => 'notification-widget-test-button btn--red' , 'data-title' => trans ( 'Are you sure to test notification?' ) , 'url' => handles ( 'antares::notifications/widgets/test' ) , ] ) -> value ( trans ( 'Test' ) ) ; } ) ; $ form -> rules ( $ this -> rules ) ; $ form -> ajaxable ( [ 'afterValidate' => $ this -> afterValidateInline ( ) ] ) ; } ) ; }
Gets form instance
12,436
public function hasPermission ( $ permission ) { $ permission = ! is_string ( $ permission ) ? : Permission :: where ( [ 'slug' => $ permission ] ) -> first ( ) ; if ( $ permission ) { foreach ( $ this -> permissions as $ p ) { if ( $ p -> id == $ permission -> id ) { return true ; } } } return false ; }
Returns if the user has a permission .
12,437
public function create ( array $ params ) { if ( ! isset ( $ params [ 'email' ] ) ) { throw new MissingArgumentException ( 'email' ) ; } if ( ! isset ( $ params [ 'name' ] ) ) { throw new MissingArgumentException ( 'name' ) ; } if ( ! isset ( $ params [ 'domain' ] ) ) { throw new MissingArgumentException ( 'domain' ) ; } return $ this -> post ( 'app/create' , $ params ) ; }
Creates a new Engage application .
12,438
public function verifyDomain ( array $ params ) { if ( ! isset ( $ params [ 'provider' ] ) ) { throw new MissingArgumentException ( 'provider' ) ; } if ( ! isset ( $ params [ 'code' ] ) ) { throw new MissingArgumentException ( 'code' ) ; } if ( ! isset ( $ params [ 'filename' ] ) ) { throw new MissingArgumentException ( 'filename' ) ; } return $ this -> post ( 'app/verify_domain' , $ params ) ; }
Automates the server - side component of the provider - specific domain verification mechanism .
12,439
public function storeCookie ( $ comment = null ) { $ userData = array ( ) ; $ sessionID = session_id ( ) ; $ currentUser = eZUser :: currentUser ( ) ; if ( is_null ( $ comment ) ) { if ( $ currentUser -> isAnonymous ( ) ) { return '' ; } else { $ userData [ $ sessionID ] = array ( 'email' => $ currentUser -> attribute ( 'email' ) , 'name' => $ currentUser -> contentObject ( ) -> name ( ) ) ; } } else { $ userData [ $ sessionID ] = array ( 'email' => $ comment -> attribute ( 'email' ) , 'website' => $ comment -> attribute ( 'url' ) , 'name' => $ comment -> attribute ( 'name' ) ) ; if ( ! $ currentUser -> isAnonymous ( ) ) { $ userData [ $ sessionID ] [ 'email' ] = $ currentUser -> attribute ( 'email' ) ; } } setcookie ( 'eZCommentsUserData' , base64_encode ( json_encode ( $ userData ) ) , $ this -> expiryTime , '/' ) ; return $ userData ; }
store data into cookie if field is null set cookie based on user data other wise set cookie based on fields
12,440
public function getCustomers ( Get \ RequestData $ requestData = null ) { $ request = new Get \ Request ( $ requestData ) ; $ apiResponse = $ this -> sendRequest ( $ request , Get \ ApiResponse :: class ) ; $ response = $ apiResponse -> getResponse ( ) ; foreach ( $ response -> getCustomers ( ) as $ customer ) { if ( $ customer -> getBirthday ( ) instanceof \ DateTime ) { $ customer -> getBirthday ( ) -> setTime ( 0 , 0 , 0 ) ; } } return $ apiResponse ; }
Get the customers .
12,441
public function getCustomer ( $ customerId ) { $ requestData = new Get \ RequestData ( ) ; $ requestData -> setCustomerId ( $ customerId ) ; $ customers = $ this -> getCustomers ( $ requestData ) -> getResponse ( ) -> getCustomers ( ) ; return isset ( $ customers [ 0 ] ) ? $ customers [ 0 ] : null ; }
Get one customer by ID .
12,442
public function getCustomerByExternalUid ( $ customerExternalUid ) { $ requestData = new Get \ RequestData ( ) ; $ requestData -> setCustomerExternalUid ( $ customerExternalUid ) ; $ customers = $ this -> getCustomers ( $ requestData ) -> getResponse ( ) -> getCustomers ( ) ; return isset ( $ customers [ 0 ] ) ? $ customers [ 0 ] : null ; }
Get once customer by the external ID .
12,443
public function deleteCustomer ( $ customerId ) { $ requestData = new Delete \ RequestData ( $ customerId ) ; $ request = new Delete \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , Delete \ ApiResponse :: class ) ; }
Delete a customer .
12,444
public function addCredits ( $ customerId , $ amount ) { $ requestData = new AddCredits \ RequestData ( $ customerId , $ amount ) ; $ request = new AddCredits \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , AddCredits \ ApiResponse :: class ) ; }
Add credits to a customer .
12,445
protected function parseLines ( array $ lines , $ lineParser ) { return array_filter ( array_map ( function ( $ line ) use ( $ lineParser ) { $ line = trim ( $ line ) ; if ( ! $ line || 0 === strpos ( $ line , '#' ) ) { return ; } return call_user_func ( $ lineParser , $ line ) ; } , $ lines ) , function ( $ pattern ) { return $ pattern !== null ; } ) ; }
Processes a file containing exclude rules of different formats per line
12,446
public function auth ( ) { $ spotify = app ( ) -> make ( 'SpotifyWrapper' , [ 'callback' => '/nova-vendor/nova-spotify-auth-tool/auth' , 'scope' => [ ] , 'show_dialog' => true , ] ) -> requestAccessToken ( ) ; $ spotify -> api -> setAccessToken ( $ spotify -> session -> getAccessToken ( ) ) ; Spotify :: updateOrCreate ( [ 'key' => 'user_id' ] , [ 'value' => $ spotify -> api -> me ( ) -> id ] ) ; Spotify :: updateOrCreate ( [ 'key' => 'refresh_token' ] , [ 'value' => $ spotify -> session -> getRefreshToken ( ) ] ) ; return redirect ( 'nova/nova-spotify-auth-tool' ) ; }
Spotify authentication .
12,447
public function checkHealth ( ) { if ( ! $ this -> process -> isRunning ( ) ) { if ( $ this -> status == self :: STATUS_CLEANINGUP || $ this -> status == self :: STATUS_CLEANEDUP ) { $ this -> status = self :: STATUS_DEAD ; return true ; } elseif ( $ this -> status == ChildProcessContainer :: STATUS_SLEEPY ) { $ this -> status = self :: STATUS_DEAD ; return true ; } $ this -> status = self :: STATUS_DEAD ; return false ; } else { return true ; } }
Checks the health of this child and returns true if healthy otherwise marks it for cleanup
12,448
public function cleanUp ( ) { $ this -> status = self :: STATUS_CLEANINGUP ; if ( $ this -> process -> isRunning ( ) ) { $ this -> sendTERMSignal ( ) ; } else { $ this -> status = self :: STATUS_CLEANEDUP ; } }
Cleans up a process
12,449
public function processOutput ( $ childName ) { $ output = $ this -> outputBuffer . $ this -> process -> getIncrementalOutput ( ) ; $ errorOutput = $ this -> errorOutputBuffer . $ this -> process -> getIncrementalErrorOutput ( ) ; $ outputLines = explode ( "\n" , $ output ) ; $ errorOutputLines = explode ( "\n" , $ errorOutput ) ; if ( count ( $ outputLines ) > 0 ) { $ lastItem = array_pop ( $ outputLines ) ; $ this -> outputBuffer = $ lastItem ; $ this -> bufferLength += implode ( "\n" , $ outputLines ) ; foreach ( $ outputLines as $ line ) { if ( strstr ( $ line , "[[CHILD::BUSY]]" ) ) { $ this -> parent -> verboseOutput ( '<info>' . $ childName . ' BUSY</info>' ) ; $ this -> status = ChildProcessContainer :: STATUS_BUSY ; } elseif ( strstr ( $ line , "[[CHILD::READY]]" ) ) { $ this -> parent -> verboseOutput ( '<info>' . $ childName . ' READY</info>' ) ; if ( $ this -> status != ChildProcessContainer :: STATUS_BUSY_BUT_SLEEPY ) { $ this -> status = ChildProcessContainer :: STATUS_READY ; } else { $ this -> status = ChildProcessContainer :: STATUS_SLEEPY ; } } elseif ( strlen ( $ line ) > 0 ) { $ this -> parent -> verboseOutput ( '<info>OUTPUT ' . $ childName . ':</info>' . $ line ) ; } } } if ( count ( $ errorOutputLines ) > 0 ) { $ lastItemError = array_pop ( $ errorOutputLines ) ; $ this -> errorOutputBuffer = $ lastItemError ; $ knownErrorOutput = implode ( "\n" , $ errorOutputLines ) ; $ this -> bufferLength += strlen ( $ knownErrorOutput ) ; } }
Looks into and processes the child s output
12,450
public function start ( ) { $ cmd = 'app/console ' . $ this -> workerCommand ; if ( $ this -> tube != '' ) { $ cmd .= ' --use-tube=' . escapeshellarg ( $ this -> tube ) ; } if ( $ this -> parent -> isVerbose ( ) ) { $ cmd .= ' -vvvv' ; } $ this -> startTime = time ( ) ; $ this -> parent -> verboseOutput ( '<info>Starting:</info>' . $ cmd ) ; $ this -> process = new Process ( 'exec ' . $ cmd , $ this -> consolePath , null , null , null ) ; $ this -> process -> start ( ) ; if ( $ this -> process -> isRunning ( ) ) { $ this -> status = ChildProcessContainer :: STATUS_ALIVE ; } else { $ this -> status = ChildProcessContainer :: STATUS_DEAD ; } }
Starts the child process
12,451
private function sendTERMSignal ( ) { if ( ! $ this -> hasReceivedHUP ) { $ this -> hasReceivedHUP = true ; try { $ this -> process -> signal ( SIGTERM ) ; } catch ( \ Symfony \ Component \ Process \ Exception \ LogicException $ e ) { } } }
Sends a signal to the process this method prevents the signal from being sent twice
12,452
public function getReadyForBed ( ) { $ busyStatusses = array ( ChildProcessContainer :: STATUS_SLEEPY , ChildProcessContainer :: STATUS_BUSY_BUT_SLEEPY ) ; if ( in_array ( $ this -> status , $ busyStatusses ) ) { return ; } if ( $ this -> status == ChildProcessContainer :: STATUS_DEAD ) { } else if ( $ this -> status == ChildProcessContainer :: STATUS_BUSY ) { $ this -> status = ChildProcessContainer :: STATUS_BUSY_BUT_SLEEPY ; } else { $ this -> status = ChildProcessContainer :: STATUS_SLEEPY ; } if ( $ this -> process -> isRunning ( ) ) { $ this -> sendTERMSignal ( ) ; } }
Tells the child to not pick up any more work and go to bed
12,453
protected function _getTargetMap ( ) { if ( is_null ( $ this -> _targetMap ) ) { $ this -> _targetMap = array ( ) ; $ this -> _targetMap [ ] = array ( 'name' => "magelocal" , 'label' => "Magento Local module file" , 'uri' => "./app/code/local" ) ; $ this -> _targetMap [ ] = array ( 'name' => "magecommunity" , 'label' => "Magento Community module file" , 'uri' => "./app/code/community" ) ; $ this -> _targetMap [ ] = array ( 'name' => "magecore" , 'label' => "Magento Core team module file" , 'uri' => "./app/code/core" ) ; $ this -> _targetMap [ ] = array ( 'name' => "magedesign" , 'label' => "Magento User Interface (layouts, templates)" , 'uri' => "./app/design" ) ; $ this -> _targetMap [ ] = array ( 'name' => "mageetc" , 'label' => "Magento Global Configuration" , 'uri' => "./app/etc" ) ; $ this -> _targetMap [ ] = array ( 'name' => "magelib" , 'label' => "Magento PHP Library file" , 'uri' => "./lib" ) ; $ this -> _targetMap [ ] = array ( 'name' => "magelocale" , 'label' => "Magento Locale language file" , 'uri' => "./app/locale" ) ; $ this -> _targetMap [ ] = array ( 'name' => "magemedia" , 'label' => "Magento Media library" , 'uri' => "./media" ) ; $ this -> _targetMap [ ] = array ( 'name' => "mageskin" , 'label' => "Magento Theme Skin (Images, CSS, JS)" , 'uri' => "./skin" ) ; $ this -> _targetMap [ ] = array ( 'name' => "mageweb" , 'label' => "Magento Other web accessible file" , 'uri' => "." ) ; $ this -> _targetMap [ ] = array ( 'name' => "magetest" , 'label' => "Magento PHPUnit test" , 'uri' => "./tests" ) ; $ this -> _targetMap [ ] = array ( 'name' => "mage" , 'label' => "Magento other" , 'uri' => "." ) ; } return $ this -> _targetMap ; }
Retrieve content from target . xml .
12,454
public function getTargets ( ) { if ( ! is_array ( $ this -> _targets ) ) { $ this -> _targets = array ( ) ; if ( $ this -> _getTargetMap ( ) ) { foreach ( $ this -> _getTargetMap ( ) as $ _target ) { $ this -> _targets [ $ _target [ 'name' ] ] = ( string ) $ _target [ 'uri' ] ; } } } return $ this -> _targets ; }
Retrieve targets as associative array from target . xml .
12,455
public function getLabelTargets ( ) { $ targets = array ( ) ; foreach ( $ this -> _getTargetMap ( ) as $ _target ) { $ targets [ $ _target [ 'name' ] ] = $ _target [ 'label' ] ; } return $ targets ; }
Retrieve tragets with label for select options .
12,456
public function getTargetUri ( $ name ) { foreach ( $ this -> getTargets ( ) as $ _name => $ _uri ) { if ( $ name == $ _name ) { return $ _uri ; } } return '' ; }
Get uri by target s name .
12,457
public static function change_case ( $ st , $ case = 'x' ) : string { $ st = self :: cast ( $ st ) ; $ case = substr ( strtolower ( ( string ) $ case ) , 0 , 1 ) ; switch ( $ case ) { case "l" : $ case = MB_CASE_LOWER ; break ; case "u" : $ case = MB_CASE_UPPER ; break ; default : $ case = MB_CASE_TITLE ; } if ( ! empty ( $ st ) ) { $ st = mb_convert_case ( $ st , $ case ) ; } return $ st ; }
Converts the case of a string .
12,458
public static function encode_filename ( $ st , $ maxlength = 50 , $ extension = null , $ is_path = false ) : string { $ st = self :: remove_accents ( self :: cast ( $ st ) ) ; $ allowed = '~\-_.,\(\[\)\]' ; $ args = \ func_get_args ( ) ; foreach ( $ args as $ i => $ a ) { if ( $ i > 0 ) { if ( \ is_string ( $ a ) ) { $ extension = $ a ; } else if ( \ is_int ( $ a ) ) { $ maxlength = $ a ; } else if ( \ is_bool ( $ a ) ) { $ is_path = $ a ; } } } if ( ! \ is_int ( $ maxlength ) ) { $ maxlength = mb_strlen ( $ st ) ; } if ( $ is_path ) { $ allowed .= '/' ; } if ( $ extension && ( self :: file_ext ( $ st ) === self :: change_case ( $ extension , 'lower' ) ) ) { $ st = substr ( $ st , 0 , - ( \ strlen ( $ extension ) + 1 ) ) ; } else if ( $ extension = self :: file_ext ( $ st ) ) { $ st = substr ( $ st , 0 , - ( \ strlen ( $ extension ) + 1 ) ) ; } $ st = mb_ereg_replace ( "([^\w\s\d" . $ allowed . ".])" , '' , $ st ) ; $ st = mb_ereg_replace ( "([\.]{2,})" , '' , $ st ) ; $ res = mb_substr ( $ st , 0 , $ maxlength ) ; if ( $ extension ) { $ res .= '.' . $ extension ; } return $ res ; }
Returns a cross - platform filename for the file .
12,459
public static function encode_dbname ( $ st , $ maxlength = 50 ) : string { $ st = self :: remove_accents ( self :: cast ( $ st ) ) ; $ res = '' ; if ( ! \ is_int ( $ maxlength ) ) { $ maxlength = mb_strlen ( $ st ) ; } for ( $ i = 0 ; $ i < $ maxlength ; $ i ++ ) { if ( mb_ereg_match ( '[A-z0-9]' , mb_substr ( $ st , $ i , 1 ) ) ) { $ res .= mb_substr ( $ st , $ i , 1 ) ; } else if ( ( mb_strlen ( $ res ) > 0 ) && ( mb_substr ( $ res , - 1 ) != '_' ) && ( $ i < ( mb_strlen ( $ st ) - 1 ) ) ) { $ res .= '_' ; } } if ( substr ( $ res , - 1 ) === '_' ) { $ res = substr ( $ res , 0 , - 1 ) ; } return $ res ; }
Returns a corrected string for database naming .
12,460
public static function genpwd ( int $ int_max = 12 , int $ int_min = 6 ) : string { mt_srand ( ) ; $ len = ( $ int_min > 0 ) && ( $ int_min < $ int_max ) ? random_int ( $ int_min , $ int_max ) : $ int_max ; $ mdp = '' ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ type = $ i === 0 ? random_int ( 2 , 3 ) : random_int ( 1 , 3 ) ; switch ( $ type ) { case 1 : $ mdp .= random_int ( 0 , 9 ) ; break ; case 2 : $ mdp .= \ chr ( random_int ( 65 , 90 ) ) ; break ; case 3 : $ mdp .= \ chr ( random_int ( 97 , 122 ) ) ; break ; } } return $ mdp ; }
Returns a random password .
12,461
public static function is_json ( $ st ) { if ( \ is_string ( $ st ) && ! empty ( $ st ) && ( ( substr ( $ st , 0 , 1 ) === '{' ) || ( substr ( $ st , 0 , 1 ) === '[' ) ) ) { json_decode ( $ st ) ; return ( json_last_error ( ) == JSON_ERROR_NONE ) ; } return false ; }
Checks if the string is a json string .
12,462
public static function is_number ( ) : bool { $ args = \ func_get_args ( ) ; foreach ( $ args as $ a ) { if ( \ is_string ( $ a ) || ( abs ( $ a ) > PHP_INT_MAX ) ) { if ( ! preg_match ( '/^-?(?:\d+|\d*\.\d+)$/' , $ a ) ) { return false ; } } else if ( ! \ is_int ( $ a ) && ! \ is_float ( $ a ) ) { return false ; } } return 1 ; }
Checks if the item is a number . Can take as many arguments and will return false if one of them is not a number .
12,463
public static function is_integer ( ) : bool { $ args = \ func_get_args ( ) ; foreach ( $ args as $ a ) { if ( \ is_string ( $ a ) || ( abs ( $ a ) > PHP_INT_MAX ) ) { if ( ! preg_match ( '/^-?(\d+)$/' , ( string ) $ a ) ) { return false ; } } else if ( ! \ is_int ( $ a ) ) { return false ; } } return true ; }
Checks if the item is a integer . Can take as many arguments and will return false if one of them is not an integer or the string of an integer .
12,464
public static function is_buid ( $ st ) : bool { if ( \ is_string ( $ st ) && ( \ strlen ( $ st ) === 16 ) && ! ctype_print ( $ st ) && ! ctype_space ( $ st ) ) { $ enc = mb_detect_encoding ( $ st , [ '8bit' , 'UTF-8' ] ) ; if ( ! $ enc || ( $ enc === '8bit' ) ) { return true ; } } return false ; }
Checks if the string is a valid binary UID string .
12,465
public static function is_email ( $ email ) : bool { if ( function_exists ( 'filter_var' ) ) { return filter_var ( $ email , FILTER_VALIDATE_EMAIL ) ? true : false ; } else { $ isValid = true ; $ atIndex = mb_strrpos ( $ email , "@" ) ; if ( \ is_bool ( $ atIndex ) && ! $ atIndex ) { $ isValid = false ; } else { $ domain = mb_substr ( $ email , $ atIndex + 1 ) ; $ local = mb_substr ( $ email , 0 , $ atIndex ) ; $ localLen = mb_strlen ( $ local ) ; $ domainLen = mb_strlen ( $ domain ) ; if ( $ localLen < 1 || $ localLen > 64 ) $ isValid = false ; else if ( $ domainLen < 1 || $ domainLen > 255 ) $ isValid = false ; else if ( $ local [ 0 ] == '.' || $ local [ $ localLen - 1 ] == '.' ) $ isValid = false ; else if ( mb_ereg_match ( '\\.\\.' , $ local ) ) $ isValid = false ; else if ( ! mb_ereg_match ( '^[A-Za-z0-9\\-\\.]+$' , $ domain ) ) $ isValid = false ; else if ( mb_ereg_match ( '\\.\\.' , $ domain ) ) $ isValid = false ; else if ( ! mb_ereg_match ( '^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$' , str_replace ( "\\\\" , "" , $ local ) ) ) { if ( ! mb_ereg_match ( '^"(\\\\"|[^"])+"$' , str_replace ( "\\\\" , "" , $ local ) ) ) $ isValid = false ; } } return $ isValid ; } }
Checks if the string is the correct type of e - mail address .
12,466
public static function correct_types ( $ st ) { if ( \ is_string ( $ st ) ) { if ( self :: is_buid ( $ st ) ) { $ st = bin2hex ( $ st ) ; } else { if ( self :: is_json ( $ st ) ) { if ( strpos ( $ st , '": ' ) && ( $ json = json_decode ( $ st ) ) ) { return json_encode ( $ json ) ; } return $ st ; } $ st = trim ( $ st ) ; if ( ! preg_match ( '/^0[^.]+|\.[0-9]*0$/' , $ st ) ) { if ( self :: is_integer ( $ st ) && ( ( substr ( ( string ) $ st , 0 , 1 ) !== '0' ) || ( $ st === '0' ) ) ) { $ tmp = ( int ) $ st ; if ( ( $ tmp < PHP_INT_MAX ) && ( $ tmp > - PHP_INT_MAX ) ) { return $ tmp ; } } else if ( self :: is_decimal ( $ st ) ) { return ( float ) $ st ; } } } } else if ( \ is_array ( $ st ) ) { foreach ( $ st as $ k => $ v ) { $ st [ $ k ] = self :: correct_types ( $ v ) ; } } else if ( \ is_object ( $ st ) ) { $ vs = get_object_vars ( $ st ) ; foreach ( $ vs as $ k => $ v ) { $ st -> $ k = self :: correct_types ( $ v ) ; } } return $ st ; }
If it looks like an int or float type the string variable is converted into the correct type .
12,467
public static function parse_url ( $ url ) : array { $ url = self :: cast ( $ url ) ; $ r = x :: merge_arrays ( parse_url ( $ url ) , [ 'url' => $ url , 'query' => '' , 'params' => [ ] ] ) ; if ( strpos ( $ url , '?' ) > 0 ) { $ p = explode ( '?' , $ url ) ; $ r [ 'url' ] = $ p [ 0 ] ; $ r [ 'query' ] = $ p [ 1 ] ; $ ps = explode ( '&' , $ r [ 'query' ] ) ; foreach ( $ ps as $ p ) { $ px = explode ( '=' , $ p ) ; $ r [ 'params' ] [ $ px [ 0 ] ] = $ px [ 1 ] ; } } return $ r ; }
Returns an array containing any of the various components of the URL that are present .
12,468
public static function check_name ( ) : bool { $ args = \ func_get_args ( ) ; foreach ( $ args as $ a ) { $ a = self :: cast ( $ a ) ; $ t = preg_match ( '#[A-z0-9_]+#' , $ a , $ m ) ; if ( $ t !== 1 || $ m [ 0 ] !== $ a ) { return false ; } } return true ; }
Checks if a string complies with SQL naming convention .
12,469
public static function check_filename ( ) : bool { $ args = \ func_get_args ( ) ; foreach ( $ args as $ a ) { if ( ! \ is_string ( $ a ) || ( strpos ( $ a , '/' ) !== false ) || ( strpos ( $ a , '\\' ) !== false ) ) { return false ; } } return true ; }
Checks if a string doesn t contain a filesystem path .
12,470
public static function has_slash ( ) : bool { $ args = \ func_get_args ( ) ; foreach ( $ args as $ a ) { if ( ( strpos ( $ a , '/' ) !== false ) || ( strpos ( $ a , '\\' ) !== false ) ) { return true ; } } return false ; }
Checks if a string complies with SQL naming convention . Returns true if slash or backslash are present .
12,471
public static function say_size ( $ bytes , $ unit = 'B' , $ stop = false ) : string { $ i = 0 ; $ units = [ '' , 'K' , 'M' , 'G' , 'T' ] ; while ( $ stop || ( $ bytes > 2000 ) ) { $ i ++ ; $ bytes /= 1024 ; if ( $ stop === $ units [ $ i ] ) { break ; } } return sprintf ( "%5.2f %s" . $ unit , $ bytes , $ units [ $ i ] ) ; }
Converts the bytes to another unit form .
12,472
public function getPrintableMessage ( ) { $ ret = $ this -> message ; if ( $ this -> _parser != null ) { $ string = rtrim ( $ this -> _parser -> getString ( ) ) ; $ offset = $ this -> _parser -> getOffset ( ) ; $ rightStr = substr ( $ string , $ offset ) ; $ offset0 = $ offset + strlen ( $ rightStr ) - strlen ( ltrim ( $ rightStr ) ) ; $ str1 = substr ( $ string , 0 , $ offset0 ) ; $ offset1 = strrpos ( $ str1 , "\n" ) ; if ( $ offset1 !== false ) { $ offset1 ++ ; } $ str2 = substr ( $ string , $ offset1 ) ; $ offset2 = strpos ( $ str2 , "\n" ) ; if ( $ offset2 === false ) { $ offset2 = strlen ( $ str2 ) ; } $ str3 = substr ( $ str2 , 0 , $ offset2 ) ; $ line = $ offset0 > 0 ? substr_count ( $ string , "\n" , 0 , $ offset0 ) : 0 ; $ column = $ offset0 - $ offset1 ; $ ret = "$str3\n" . str_repeat ( " " , $ column ) . "^" . $ this -> message ; if ( $ line > 0 ) { $ ret .= " (line " . ( $ line + 1 ) . ")" ; } } return $ ret ; }
Gets a printable message .
12,473
public function make ( $ responseBody , array $ responseInfo ) { $ info = $ this -> makeResponseInfo ( $ responseInfo ) ; $ response = $ this -> makeResponse ( $ responseBody , $ info ) ; return $ response ; }
Make a response
12,474
public function file_error_message ( $ key ) { if ( $ this -> file_info ( $ key ) ) { return '' ; } elseif ( ! isset ( $ _FILES [ $ key ] ) ) { return $ this -> __ ( 'File is not specified.' ) ; } else { switch ( $ _FILES [ $ key ] [ 'error' ] ) { case UPLOAD_ERR_FORM_SIZE : case UPLOAD_ERR_INI_SIZE : return $ this -> __ ( 'Uploaded file size exceeds allowed limit.' ) ; break ; default : return $ this -> __ ( 'Failed to upload' ) ; break ; } } }
Get file upload error message
12,475
protected function _runShell ( ) { echo wordwrap ( '-- discovery-shell to help discover a class or library --' . PHP_EOL . PHP_EOL . 'Use TAB for autocompletion and your arrow-keys to navigate through your method-history.' . PHP_EOL . 'Beware! This is not a full-featured php-shell. The input gets parsed with PHP-Parser to avoid the usage' . ' of eval().' . PHP_EOL , exec ( 'tput cols' ) , PHP_EOL ) ; while ( true ) { $ input = $ this -> _getInput ( ) ; list ( $ method , $ arguments ) = $ this -> _parseInput ( $ input ) ; $ answer = call_user_func_array ( array ( $ this -> _object , $ method ) , $ arguments ) ; $ this -> _outputAnswer ( $ answer ) ; } }
Runs the shell
12,476
public function createTemporaryTable ( $ tableNamePattern , $ tableDefinition ) { $ tableNamePattern = $ this -> getPrefixedTableNames ( $ tableNamePattern ) ; if ( strpos ( $ tableNamePattern , '%' ) === false ) { $ tableName = $ tableNamePattern ; } else { $ maxTries = 10 ; do { $ num = rand ( 10000000 , 99999999 ) ; $ tableName = strtoupper ( str_replace ( '%' , $ num , $ tableNamePattern ) ) ; $ query = "SELECT count(*) AS cnt FROM user_tables WHERE table_name='$tableName'" ; $ cnt = ( int ) $ this -> db -> query ( $ query ) -> fetchColumn ( 0 ) ; $ maxTries -- ; } while ( $ cnt > 0 && $ maxTries > 0 ) ; if ( $ maxTries == 0 ) { throw ezcDbException ( ezcDbException :: GENERIC_ERROR , "Tried to generate an uninque temp table name for {$maxTries} time with no luck." ) ; } } $ this -> db -> exec ( "CREATE GLOBAL TEMPORARY TABLE $tableName ($tableDefinition)" ) ; return $ tableName ; }
Creates a new temporary table and returns the name .
12,477
public function dropTemporaryTable ( $ tableName ) { $ tableName = $ this -> getPrefixedTableNames ( $ tableName ) ; $ this -> db -> exec ( "TRUNCATE TABLE $tableName" ) ; $ this -> db -> exec ( "DROP TABLE $tableName" ) ; }
Drop specified temporary table in a portable way .
12,478
public function getBaseUri ( ) { return sprintf ( '%s%s' , $ this -> params [ 'endpoint' ] , ! empty ( $ this -> id ) ? '/' . $ this -> id : null ) ; }
Return entity endpoint base uri
12,479
public function Register ( $ data ) { if ( isset ( $ data [ "Password" ] ) && is_array ( $ data [ "Password" ] ) && isset ( $ data [ "Password" ] [ "_Password" ] ) ) { $ data [ "Password" ] = $ data [ "Password" ] [ "_Password" ] ; } $ this -> owner -> update ( $ data ) ; $ this -> owner -> VerificationCode = sha1 ( mt_rand ( ) . mt_rand ( ) ) ; $ this -> owner -> write ( ) ; if ( count ( Users :: config ( ) -> new_user_groups ) ) { $ groups = Group :: get ( ) -> filter ( array ( "Code" => Users :: config ( ) -> new_user_groups ) ) ; foreach ( $ groups as $ group ) { $ group -> Members ( ) -> add ( $ this -> owner ) ; $ group -> write ( ) ; } } if ( Users :: config ( ) -> send_verification_email ) { $ this -> owner -> sendVerificationEmail ( ) ; } if ( Users :: config ( ) -> login_after_register ) { $ this -> owner -> LogIn ( isset ( $ data [ 'Remember' ] ) ) ; } return $ this -> owner ; }
Register a new user account using the provided data and then return the current member
12,480
public function sendVerificationEmail ( ) { if ( $ this -> owner -> exists ( ) ) { $ controller = Injector :: inst ( ) -> get ( "Users_Register_Controller" ) ; $ subject = _t ( "Users.PleaseVerify" , "Please verify your account" ) ; if ( Users :: config ( ) -> send_email_from ) { $ from = Users :: config ( ) -> send_email_from ; } else { $ from = Email :: config ( ) -> admin_email ; } $ email = Email :: create ( ) ; $ email -> setFrom ( $ from ) -> setTo ( $ this -> owner -> Email ) -> setSubject ( $ subject ) -> setTemplate ( 'UsersAccountVerification' ) -> populateTemplate ( ArrayData :: create ( array ( "Link" => Controller :: join_links ( $ controller -> AbsoluteLink ( "verify" ) , $ this -> owner -> ID , $ this -> owner -> VerificationCode ) ) ) ) ; $ email -> send ( ) ; return true ; } return false ; }
Send a verification email to this user account
12,481
public function exec ( $ sql ) { $ this -> writeToLog ( "Exec: " . $ sql ) ; $ result = parent :: exec ( $ sql ) ; return $ result ; }
Used to issue statements which return no results but rather the number of rows affected
12,482
public function prepare ( $ sql , $ options = null ) { $ md5 = md5 ( $ sql ) ; if ( isset ( $ this -> prepared_sql [ $ md5 ] ) ) { return $ this -> prepared_sql [ $ md5 ] ; } $ stmt = parent :: prepare ( $ sql ) ; $ this -> prepared_sql [ $ md5 ] = $ stmt ; return $ stmt ; }
Used to prepare sql statements for value binding
12,483
public function writeToLog ( $ message ) { if ( is_null ( $ this -> logger ) ) { $ this -> setLogger ( ) ; } if ( empty ( $ this -> sbf_id ) || $ this -> sbf_id == \ sb \ Gateway :: $ cookie [ 'SBF_ID' ] ) { $ message = preg_replace ( "~\t~" , " " , $ message ) ; return $ this -> logger -> { $ this -> log_str } ( $ message ) ; } }
Logs all sql statements to a file if the log file is specified
12,484
public function getMetaData ( ModelInterface $ model , DiInterface $ di ) { $ reflection = $ di -> getAnnotations ( ) -> get ( $ model ) ; $ properties = $ reflection -> getPropertiesAnnotations ( ) ; if ( ! $ properties ) { throw new \ Exception ( 'There are no properties defined on the class' ) ; } $ tableProperties = $ reflection -> getClassAnnotations ( ) ; if ( $ tableProperties && $ tableProperties -> has ( 'Source' ) ) { $ source = $ tableProperties -> get ( 'Source' ) -> getArguments ( ) [ 0 ] ; } else { throw new \ Exception ( 'Model ' . get_class ( $ model ) . ' has no Source defined' ) ; } $ database = $ di -> get ( $ source ) ; $ dbType = ucfirst ( $ database -> getType ( ) ) ; $ indexes = $ this -> getIndexes ( $ reflection ) ; return call_user_func_array ( [ '\Phalcon\Annotations\DbStrategies\\' . $ dbType , 'getMetaData' ] , [ $ reflection , $ properties , $ indexes ] ) ; }
Initializes the model s meta - data
12,485
public function getColumnMaps ( ModelInterface $ model , DiInterface $ di ) { $ reflection = $ di [ 'annotations' ] -> get ( $ model ) ; $ columnMap = array ( ) ; $ reverseColumnMap = array ( ) ; $ renamed = false ; foreach ( $ reflection -> getPropertiesAnnotations ( ) as $ name => $ collection ) { if ( $ collection -> has ( 'Column' ) ) { $ arguments = $ collection -> get ( 'Column' ) -> getArguments ( ) ; if ( isset ( $ arguments [ 'column' ] ) ) { $ columnName = $ arguments [ 'column' ] ; } else { $ columnName = $ name ; } $ columnMap [ $ columnName ] = $ name ; $ reverseColumnMap [ $ name ] = $ columnName ; if ( ! $ renamed ) { if ( $ columnName != $ name ) { $ renamed = true ; } } } } return array ( MetaData :: MODELS_COLUMN_MAP => $ columnMap , MetaData :: MODELS_REVERSE_COLUMN_MAP => $ reverseColumnMap ) ; }
Initializes the model s column map
12,486
public function getOutputAsArray ( ) { $ output = trim ( $ this -> getOutput ( ) ) ; if ( empty ( $ output ) === false ) { return preg_split ( '{\r?\n}' , $ output ) ; } return array ( ) ; }
Returns the output separated by newline as array .
12,487
public function setAccessToken ( \ Gpupo \ CommonSchema \ ORM \ Entity \ Application \ API \ OAuth \ Client \ AccessToken $ accessToken = null ) { $ this -> access_token = $ accessToken ; return $ this ; }
Set accessToken .
12,488
public function setProvider ( \ Gpupo \ CommonSchema \ ORM \ Entity \ Application \ API \ OAuth \ Provider $ provider = null ) { $ this -> provider = $ provider ; return $ this ; }
Set provider .
12,489
private function set_tags ( ) { if ( $ this -> mode ) { if ( $ this -> mode === 'vue' ) { $ tags = \ bbn \ x :: merge_arrays ( $ this -> all_tags [ 'js' ] , $ this -> all_tags [ 'vue' ] ) ; } else { $ tags = $ this -> all_tags [ $ this -> mode ] ; } $ this -> tags = \ bbn \ x :: merge_arrays ( $ this -> all_tags [ 'common' ] , $ tags ) ; return $ this -> tags ; } }
Sets the tags list relative to the selected mode
12,490
private function get_tags ( string $ block ) { preg_match_all ( $ this -> pattern [ 'tag' ] , $ block , $ tags , PREG_OFFSET_CAPTURE ) ; if ( ! empty ( $ tags [ 0 ] ) ) { return $ tags [ 0 ] ; } return [ ] ; }
Gets te tags list of a docblock
12,491
private function group_tags ( array $ tags ) { $ res = [ ] ; if ( ! empty ( $ tags ) ) { foreach ( $ tags as $ i => $ tag ) { if ( $ tag [ 'tag' ] === 'memberof' ) { continue ; } $ t = $ tag [ 'tag' ] ; unset ( $ tag [ 'tag' ] ) ; $ res [ $ t ] [ ] = $ tag [ 'text' ] ?? $ tag ; } } return array_map ( function ( $ r ) { if ( is_array ( $ r ) && ( count ( $ r ) === 1 ) ) { return $ r [ 0 ] ; } return $ r ; } , $ res ) ; }
Groups tags by name
12,492
private function tag_has_type ( string $ tag ) { return in_array ( 'type' , array_values ( \ is_array ( $ this -> tags [ $ tag ] ) ? $ this -> tags [ $ tag ] : $ this -> tags [ $ this -> tags [ $ tag ] ] ) ) ; }
Cheks if a tag has type
12,493
private function tag_has_default ( string $ tag ) { return in_array ( 'default' , array_values ( \ is_array ( $ this -> tags [ $ tag ] ) ? $ this -> tags [ $ tag ] : $ this -> tags [ $ this -> tags [ $ tag ] ] ) ) ; }
Cheks if a tag has default
12,494
private function tag_has_name ( string $ tag ) { return in_array ( 'name' , array_values ( \ is_array ( $ this -> tags [ $ tag ] ) ? $ this -> tags [ $ tag ] : $ this -> tags [ $ this -> tags [ $ tag ] ] ) ) ; }
Cheks if a tag has name
12,495
private function tag_has_desc ( string $ tag ) { return in_array ( 'description' , array_values ( \ is_array ( $ this -> tags [ $ tag ] ) ? $ this -> tags [ $ tag ] : $ this -> tags [ $ this -> tags [ $ tag ] ] ) ) ; }
Cheks if a tag has description
12,496
private function tag_has_text ( string $ tag ) { return in_array ( 'text' , array_values ( \ is_array ( $ this -> tags [ $ tag ] ) ? $ this -> tags [ $ tag ] : $ this -> tags [ $ this -> tags [ $ tag ] ] ) ) ; }
Cheks if a tag has text
12,497
private function tag_get_type ( string $ text ) { if ( ( $ this -> mode === 'js' ) || ( $ this -> mode === 'vue' ) ) { preg_match ( '/(?:\{)(.+)(?:\})/' , $ text , $ type , PREG_OFFSET_CAPTURE ) ; } else if ( $ this -> mode === 'php' ) { preg_match ( '/(?:\@[a-z]+\s{1})(.+)(?:\s{1}\$)/' , $ text , $ type , PREG_OFFSET_CAPTURE ) ; $ type [ 0 ] = $ type [ 1 ] ; } return $ type ; }
Gets tag type
12,498
private function tag_get_default ( string $ text ) { if ( ( $ this -> mode === 'js' ) || ( $ this -> mode === 'vue' ) ) { preg_match ( '/(?:\[)(.+)(?:\])/' , $ text , $ def , PREG_OFFSET_CAPTURE ) ; } return $ def ; }
Gets tag default
12,499
private function tag_get_name ( string $ text ) { if ( ( $ this -> mode === 'js' ) || ( $ this -> mode === 'vue' ) ) { preg_match ( '/[[:graph:]]+/' , $ text , $ name , PREG_OFFSET_CAPTURE ) ; } else if ( $ this -> mode === 'php' ) { preg_match ( '/\$[a-z]+/' , $ text , $ name , PREG_OFFSET_CAPTURE ) ; } return $ name ; }
Gets tag name