idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
46,700
public function register ( $ key , $ callable ) { if ( ! $ this -> has ( $ key ) && is_callable ( $ callable ) ) { self :: $ registry [ $ key ] = $ callable ; return true ; } return false ; }
Registers a function to be called with a specific key
46,701
public function forget ( $ key ) { if ( isset ( self :: $ registry [ $ key ] ) ) { unset ( self :: $ registry [ $ key ] ) ; return true ; } return false ; }
Removes a key for a method from registry .
46,702
protected function find ( $ cls ) { if ( ! empty ( self :: $ paths ) ) { foreach ( self :: $ paths as $ path ) { $ inc = $ path . DS . strtolower ( $ cls ) . '.php' ; if ( file_exists ( $ inc ) ) { $ code = file_get_contents ( $ inc ) ; $ tokens = token_get_all ( $ code ) ; for ( $ i = 2 ; $ i < count ( $ tokens ) ; $ i ++ ) { if ( $ tokens [ $ i - 2 ] [ 0 ] === T_CLASS && $ tokens [ $ i - 1 ] [ 0 ] === T_WHITESPACE && $ tokens [ $ i ] [ 0 ] === T_STRING ) { include_once $ inc ; return $ tokens [ $ i ] [ 1 ] ; } } } } } return null ; }
Search added paths for a callable class
46,703
public function addIncludePath ( $ path = '' ) { settype ( $ path , 'array' ) ; foreach ( $ path as $ dir ) { if ( ! empty ( $ dir ) && ! in_array ( $ dir , self :: $ paths ) ) { array_unshift ( self :: $ paths , \ Hubzero \ Filesystem \ Util :: normalizePath ( $ dir ) ) ; } } return self :: $ paths ; }
Add a directory where Html should search for helpers . You may either pass a string or an array of directories .
46,704
public function parse ( $ path ) { libxml_use_internal_errors ( true ) ; $ xml = simplexml_load_file ( $ path , null , LIBXML_NOERROR ) ; if ( $ xml === false ) { $ errors = libxml_get_errors ( ) ; $ latestError = array_pop ( $ errors ) ; $ error = array ( 'message' => $ latestError -> message , 'type' => $ latestError -> level , 'code' => $ latestError -> code , 'file' => $ latestError -> file , 'line' => $ latestError -> line , ) ; throw new ParseException ( $ error ) ; } $ data = new stdClass ; foreach ( $ xml -> children ( ) as $ node ) { $ data -> { $ node [ 'name' ] } = $ this -> getValueFromNode ( $ node ) ; } $ data = json_decode ( json_encode ( $ data ) , true ) ; return $ data ; }
Parses an XML file as an array
46,705
public function getTableColumns ( $ table , $ typeOnly = true ) { $ columns = $ this -> query ( $ this -> syntax -> getColumnsQuery ( $ table ) , 'rows' ) ; return $ this -> syntax -> normalizeColumns ( $ columns , $ typeOnly ) ; }
Retrieves field information about the given tables
46,706
public function setAdditionalUrlParam ( $ key , $ value ) { $ result = isset ( $ this -> _additionalUrlParams [ $ key ] ) ? $ this -> _additionalUrlParams [ $ key ] : null ; if ( $ value === null ) { unset ( $ this -> _additionalUrlParams [ $ key ] ) ; } else { $ this -> _additionalUrlParams [ $ key ] = $ value ; } return $ this ; }
Method to set an additional URL parameter to be added to all pagination class generated links .
46,707
public function orderUpIcon ( $ i , $ condition = true , $ task = 'orderup' , $ alt = 'JLIB_HTML_MOVE_UP' , $ enabled = true , $ checkbox = 'cb' ) { if ( ( $ i > 0 || ( $ i + $ this -> limitstart > 0 ) ) && $ condition ) { return Grid :: orderUp ( $ i , $ task , '' , $ alt , $ enabled , $ checkbox ) ; } return '&#160;' ; }
Return the icon to move an item UP .
46,708
public function orderDownIcon ( $ i , $ n , $ condition = true , $ task = 'orderdown' , $ alt = 'JLIB_HTML_MOVE_DOWN' , $ enabled = true , $ checkbox = 'cb' ) { if ( ( $ i < $ n - 1 || $ i + $ this -> limitstart < $ this -> total - 1 ) && $ condition ) { return Grid :: orderDown ( $ i , $ task , '' , $ alt , $ enabled , $ checkbox ) ; } return '&#160;' ; }
Return the icon to move an item DOWN .
46,709
public function render ( $ view = null ) { $ this -> set ( 'pages.ellipsis' , false ) ; $ data = $ this -> getData ( ) ; $ data -> prefix = $ this -> prefix ; $ data -> i = $ this -> get ( 'pages.i' ) ; $ data -> ellipsis = $ this -> get ( 'pages.ellipsis' ) ; $ data -> total = $ this -> get ( 'pages.total' ) ; $ data -> startloop = $ this -> get ( 'pages.start' ) ; $ data -> stoploop = $ this -> get ( 'pages.stop' ) ; $ data -> current = $ this -> get ( 'pages.current' ) ; if ( is_array ( $ view ) ) { $ view = new View ( $ view ) ; } if ( ! $ view instanceof View ) { $ view = new View ( ) ; } $ view -> set ( 'limit' , $ this -> limit ) -> set ( 'start' , $ this -> limitstart ) -> set ( 'total' , $ this -> total ) -> set ( 'pages' , $ data ) -> set ( 'viewall' , $ this -> _viewall ) -> set ( 'limits' , $ this -> _limits ) -> set ( 'prefix' , $ this -> prefix ) ; return $ view -> loadTemplate ( ) ; }
Return the pagination footer .
46,710
protected static function parseLocation ( $ location ) { if ( is_string ( $ location ) ) { $ locationName = self :: getMountNameFromPath ( $ location ) ; $ locationMount = self :: findMountByName ( $ locationName ) ; } else { $ locationName = uniqid ( '' , true ) ; $ locationMount = $ location -> getAdapter ( ) ; $ location = $ locationName . '://' . $ location -> getPath ( ) ; } return [ $ location , $ locationName , $ locationMount ] ; }
Parses the location input into mount and mount names
46,711
protected static function findMountByName ( $ name ) { if ( array_key_exists ( $ name , self :: $ adapters ) ) { return self :: $ adapters [ $ name ] ; } foreach ( self :: $ adapters as $ key => $ adapter ) { if ( strpos ( $ key , $ name ) === 0 ) { return self :: $ adapters [ $ key ] ; } } return false ; }
Finds a mount by name irrelevant of params
46,712
protected static function getMountNameFromPath ( $ path ) { preg_match ( '/([[:alpha:]]*):\/\//' , $ path , $ name ) ; if ( ! isset ( $ name [ 1 ] ) || ! $ name [ 1 ] ) { throw new \ Exception ( 'Could not determine source mount type' , 500 ) ; } return $ name [ 1 ] ; }
Grabs the mount name from a given path
46,713
protected static function getRelativePath ( $ path ) { preg_match ( '/([[:alpha:]]*):\/\/(.*)/' , $ path , $ name ) ; if ( isset ( $ name [ 2 ] ) && $ name [ 2 ] ) { return $ name [ 2 ] ; } return $ path ; }
Grabs the relative path from the given path removing any mount prefix
46,714
public static function adapter ( $ name , $ params = [ ] , $ key = null ) { $ key = $ key ? : $ name . '.' . md5 ( serialize ( $ params ) ) ; if ( ! isset ( self :: $ adapters [ $ key ] ) ) { Plugin :: import ( 'filesystem' ) ; $ plugin = 'plgFilesystem' . ucfirst ( $ name ) ; $ adapter = $ plugin :: init ( $ params ) ; self :: $ adapters [ $ key ] = new Flysystem ( $ adapter ) ; } return self :: $ adapters [ $ key ] ; }
Returns the appropriate adapter
46,715
public static function copy ( $ source , $ dest , $ overwrite = false ) { list ( $ source , $ sourceName , $ sourceMount ) = self :: parseLocation ( $ source ) ; list ( $ dest , $ destName , $ destMount ) = self :: parseLocation ( $ dest ) ; if ( ! $ sourceMount ) { throw new \ Exception ( "'{$sourceMount}' has not been mounted" , 500 ) ; } if ( ! $ destMount ) { throw new \ Exception ( "'{$destMount}' has not been mounted" , 500 ) ; } if ( $ destMount -> has ( self :: getRelativePath ( $ dest ) ) ) { if ( $ overwrite ) { $ destMount -> delete ( self :: getRelativePath ( $ dest ) ) ; } else { return true ; } } $ manager = new \ League \ Flysystem \ MountManager ( [ $ sourceName => $ sourceMount , $ destName => $ destMount ] ) ; return $ manager -> copy ( $ source , $ dest ) ; }
Copys file from one location to another between mounts
46,716
public static function validate ( $ data , $ rules ) { $ errors = array ( ) ; foreach ( $ data as $ k => $ v ) { if ( array_key_exists ( $ k , $ rules ) ) { $ rule = null ; if ( is_callable ( $ rules [ $ k ] ) ) { if ( $ error = call_user_func_array ( $ rules [ $ k ] , [ $ data ] ) ) { $ errors [ ] = $ error ; } } else if ( strpos ( $ rules [ $ k ] , '|' ) ) { $ rule = explode ( '|' , $ rules [ $ k ] ) ; } else { $ rule = array ( $ rules [ $ k ] ) ; } if ( isset ( $ rule ) ) { foreach ( $ rule as $ r ) { if ( method_exists ( __CLASS__ , $ r ) ) { if ( $ error = self :: $ r ( $ k , $ v ) ) { $ errors [ ] = $ error ; } } } } } } return ( count ( $ errors ) > 0 ) ? $ errors : true ; }
Do validation checks on provided data
46,717
public static function generate ( $ name = null ) { $ name = $ name ? : self :: getName ( ) ; return '<label id="hypt_' . $ name . '_wrap" style="display:none;">' . "\n" . 'Leave this field empty:' . "\n" . Input :: input ( 'text' , $ name . '[p]' ) . "\n" . Input :: input ( 'text' , $ name . '[t]' , self :: getEncrypter ( ) -> encrypt ( time ( ) ) ) . "\n" . '</label>' . "\n" ; }
Displays a hidden token field to reduce the risk of CSRF exploits
46,718
public static function validateTime ( $ value , $ delay ) { $ value = self :: getEncrypter ( ) -> decrypt ( $ value ) ; return ( is_numeric ( $ value ) && time ( ) > ( $ value + $ delay ) ) ; }
Validate time was within the time limit
46,719
protected static function getEncrypter ( ) { static $ crypt ; if ( ! $ crypt ) { $ key = \ App :: get ( 'session' ) -> getFormToken ( ) ; $ crypt = new Encrypter ( new Simple , new Key ( 'simple' , $ key , $ key ) ) ; } return $ crypt ; }
Get the encrypter
46,720
public function parse ( $ path ) { $ data = json_decode ( file_get_contents ( $ path ) , true ) ; if ( function_exists ( 'json_last_error_msg' ) ) { $ error_message = json_last_error_msg ( ) ; } else { $ error_message = 'Syntax error' ; } if ( json_last_error ( ) !== JSON_ERROR_NONE ) { $ error = array ( 'message' => $ error_message , 'type' => json_last_error ( ) , 'file' => $ path , ) ; throw new ParseException ( $ error ) ; } return $ data ; }
Loads a JSON file as an array
46,721
public function listContents ( $ directory = '' , $ recursive = false ) { $ contents = parent :: listContents ( $ directory , $ recursive ) ; return $ this -> encapsulate ( $ contents ) ; }
Gets the directory contents
46,722
private function encapsulate ( $ entities ) { $ items = [ ] ; foreach ( $ entities as $ entity ) { $ items [ ] = Entity :: fromMetadata ( $ entity , $ this ) ; } return new Collection ( $ items ) ; }
Encapsulates the entities list in their appropriate classes and returns as part of a collection
46,723
protected function getUserGroups ( ) { $ db = App :: get ( 'db' ) ; $ query = $ db -> getQuery ( ) -> select ( 'a.id' , 'value' ) -> select ( 'a.title' , 'text' ) -> select ( 'COUNT(DISTINCT b.id)' , 'level' ) -> select ( 'a.parent_id' ) -> from ( '#__usergroups' , 'a' ) -> joinRaw ( '#__usergroups AS b' , 'a.lft > b.lft AND a.rgt < b.rgt' , 'left' ) -> group ( 'a.id' ) -> group ( 'a.title' ) -> group ( 'a.lft' ) -> group ( 'a.rgt' ) -> group ( 'a.parent_id' ) -> order ( 'a.lft' , 'ASC' ) ; $ db -> setQuery ( $ query -> toString ( ) ) ; $ options = $ db -> loadObjectList ( ) ; return $ options ; }
Get a list of the user groups .
46,724
public static function getActionItems ( $ type , $ component , $ element , $ uid ) { $ entries = self :: all ( ) ; $ a = $ entries -> getTableName ( ) ; $ m = Message :: blank ( ) -> getTableName ( ) ; $ r = Recipient :: blank ( ) -> getTableName ( ) ; return $ entries -> select ( $ m . '.id' ) -> join ( $ r , $ r . '.actionid' , $ a . '.id' , 'inner' ) -> join ( $ m , $ m . '.id' , $ r . '.mid' , 'inner' ) -> whereEquals ( $ m . '.type' , $ type ) -> whereEquals ( $ r . '.uid' , $ uid ) -> whereEquals ( $ a . '.class' , $ component ) -> whereEquals ( $ a . '.element' , $ element ) -> rows ( ) ; }
Get records for specific type element component and user
46,725
public function send ( Swift_Mime_Message $ message , & $ failedRecipients = null ) { try { $ from = $ message -> getFrom ( ) ; $ to = [ ] ; foreach ( $ message -> getTo ( ) as $ address => $ name ) { $ to [ ] = [ 'email' => $ address , 'name' => $ name , 'type' => 'to' ] ; } $ attachments = [ ] ; $ html = '' ; $ txt = '' ; foreach ( $ message -> getChildren ( ) as $ children ) { if ( $ children instanceof Swift_Attachment ) { $ attachments [ ] = [ 'type' => $ children -> getContentType ( ) , 'name' => $ children -> getFilename ( ) , 'content' => base64_encode ( $ children -> getBody ( ) ) ] ; } elseif ( $ message -> getBody ( ) == null ) { if ( $ children -> getContentType ( ) == 'text/html' ) { $ html .= $ children -> getBody ( ) ; } else { $ txt .= $ children -> getBody ( ) ; } } else { if ( $ message -> getContentType ( ) == 'text/html' ) { $ html .= $ message -> getBody ( ) ; } else { $ txt .= $ message -> getBody ( ) ; } } } $ mail = [ 'html' => $ html , 'txt' => $ txt , 'subject' => $ message -> getSubject ( ) , 'from_email' => array_keys ( $ from ) [ 0 ] , 'from_name' => reset ( $ from ) , 'to' => $ to , 'headers' => array ( 'Reply-To' => $ message -> getReplyTo ( ) ) , 'attachments' => $ attachments , 'tags' => $ message -> getTags ( ) , 'preserve_recipients' => false , ] ; $ async = false ; $ ip_pool = 'Main Pool' ; $ result = $ this -> mandrill -> messages -> send ( $ mail , $ async , $ ip_pool ) ; foreach ( $ result as $ recepient ) { if ( ! in_array ( $ recepient [ 'status' ] , [ 'queued' , 'sent' ] ) ) { \ Log :: info ( \ Lang :: txt ( 'Mail to %s failed' , $ recepient [ 'email' ] ) ) ; } } return true ; } catch ( Mandrill_Error $ e ) { throw new RuntimeException ( 'A mandrill error occurred: ' . $ e -> getMessage ( ) , 500 ) ; } }
Sends the given message
46,726
protected static function getRedirectUri ( $ name ) { $ service = trim ( Request :: base ( ) , '/' ) ; if ( substr ( $ service , - 13 ) == 'administrator' ) { $ scope = '/index.php?option=com_login&task=login&authenticator=' . $ name ; } else { $ task = ( User :: isGuest ( ) ) ? 'user.login' : 'user.link' ; $ scope = '/index.php?option=com_users&task=' . $ task . '&authenticator=' . $ name ; } return $ service . $ scope ; }
Builds the redirect URI based on the current URI and a few other assumptions
46,727
public static function addEntry ( $ name , $ link = '' , $ active = false ) { static :: getRoot ( ) -> appendButton ( $ name , $ link , $ active ) ; }
Method to add a menu item to submenu .
46,728
public static function mozifyHtml ( $ html = '' , $ mosaicSize = 5 ) { preg_match_all ( '/<img src="([^"]*)"([^>]*)>/' , $ html , $ matches , PREG_SET_ORDER ) ; if ( count ( $ matches ) > 0 ) { foreach ( $ matches as $ match ) { $ config = array ( 'imageUrl' => $ match [ 1 ] , 'mosaicSize' => $ mosaicSize ) ; $ him = new Mozify ( $ config ) ; $ html = str_replace ( $ match [ 0 ] , $ him -> mozify ( ) , $ html ) ; } } return $ html ; }
Convert images in a string of HTML to mosaics
46,729
public static function getTimeZoneObject ( $ tz , $ ignoreDst = false ) { if ( ! ( $ tz instanceof DateTimeZone ) ) { if ( $ tz === null ) { $ tz = self :: $ gmt ; } elseif ( is_numeric ( $ tz ) ) { $ tz = new DateTimeZone ( self :: $ offsets [ ( string ) $ tz ] ) ; } elseif ( is_string ( $ tz ) ) { $ tz = new DateTimeZone ( $ tz ) ; } } if ( $ ignoreDst ) { $ lastYear = self :: of ( '-1 year' ) -> toUnix ( ) ; $ currentDate = self :: of ( 'now' ) -> toUnix ( ) ; $ transitions = $ tz -> getTransitions ( $ lastYear , $ currentDate ) ; $ offsets = array_reduce ( $ transitions , function ( $ carry , $ transition ) { if ( empty ( $ transition [ 'isdst' ] ) ) { $ carry [ ] = $ transition [ 'offset' ] ; } return $ carry ; } ) ; if ( ! empty ( $ offsets ) ) { $ offset = $ offsets [ 0 ] ; if ( abs ( $ offset ) > 0 ) { $ offset = $ offset / 3600 ; } $ tz = new DateTimeZone ( $ offset ) ; } } return $ tz ; }
Get TimeZone object for setting the timezone on the provided time .
46,730
public function calendar ( $ format , $ local = false , $ translate = true ) { return $ this -> format ( $ format , $ local , $ translate ) ; }
Gets the date as a formatted string in a local calendar .
46,731
public function toLocal ( $ format = '' , $ ignoreDst = false ) { $ format = $ format ? : self :: $ format ; $ tz = \ User :: getParam ( 'timezone' , \ Config :: get ( 'offset' ) ) ; return $ this -> toTimeZone ( $ tz , $ format , $ ignoreDst ) ; }
Gets the date as UNIX time stamp .
46,732
public function toTimeZone ( $ timeZone , $ format = null , $ ignoreDst = false ) { $ format = $ format ? : parent :: $ format ; $ timeZone = self :: getTimeZoneObject ( $ timeZone , $ ignoreDst ) ; $ this -> setTimezone ( $ timeZone ) ; return $ this -> format ( $ format , true ) ; }
Function to explicitly convert a date to the timezone and format provided .
46,733
public function relative ( $ unit = null , $ time = null ) { if ( is_null ( $ time ) ) { $ time = new self ( 'now' ) ; } $ diff = strtotime ( $ time ) - strtotime ( $ this ) ; if ( $ diff < 60 ) { return \ Lang :: txt ( 'JLIB_HTML_DATE_RELATIVE_LESSTHANAMINUTE' ) ; } $ diff = round ( $ diff / 60 ) ; if ( $ diff < 60 || $ unit == 'minute' ) { return \ Lang :: txts ( 'JLIB_HTML_DATE_RELATIVE_MINUTES' , $ diff ) ; } $ diff = round ( $ diff / 60 ) ; if ( $ diff < 24 || $ unit == 'hour' ) { return \ Lang :: txts ( 'JLIB_HTML_DATE_RELATIVE_HOURS' , $ diff ) ; } $ diff = round ( $ diff / 24 ) ; if ( $ diff < 7 || $ unit == 'day' ) { return \ Lang :: txts ( 'JLIB_HTML_DATE_RELATIVE_DAYS' , $ diff ) ; } $ diff = round ( $ diff / 7 ) ; if ( $ diff <= 4 || $ unit == 'week' ) { return \ Lang :: txts ( 'JLIB_HTML_DATE_RELATIVE_WEEKS' , $ diff ) ; } $ text = $ this -> _ago ( strtotime ( $ this ) , strtotime ( $ time ) ) ; $ parts = explode ( ' ' , $ text ) ; $ text = $ parts [ 0 ] . ' ' . $ parts [ 1 ] ; $ text .= ( $ parts [ 2 ] ) ? ' ' . $ parts [ 2 ] . ' ' . $ parts [ 3 ] : '' ; return sprintf ( '%s ago' , $ text ) ; }
Function to convert a static time into a relative measurement
46,734
protected function _ago ( $ timestamp , $ current_time = null ) { if ( is_null ( $ current_time ) ) { $ current_time = new self ( 'now' ) ; $ current_time = strtotime ( $ current_time ) ; } $ difference = $ current_time - $ timestamp ; $ periods = array ( 'second' , 'minute' , 'hour' , 'day' , 'week' , 'month' , 'year' , 'decade' ) ; $ lengths = array ( 1 , 60 , 3600 , 86400 , 604800 , 2630880 , 31570560 , 315705600 ) ; for ( $ val = count ( $ lengths ) - 1 ; ( $ val >= 0 ) && ( ( $ number = $ difference / $ lengths [ $ val ] ) <= 1 ) ; $ val -- ) { } if ( $ val < 0 ) { $ val = 0 ; } $ new_time = $ current_time - ( $ difference % $ lengths [ $ val ] ) ; $ number = floor ( $ number ) ; if ( $ number != 1 ) { $ periods [ $ val ] .= 's' ; } $ text = sprintf ( "%d %s " , $ number , $ periods [ $ val ] ) ; if ( ( $ val >= 1 ) && ( ( $ current_time - $ new_time ) > 0 ) ) { $ text .= $ this -> _ago ( $ new_time , $ current_time ) ; } return $ text ; }
Calculate how long ago a date was
46,735
public function load ( ) { if ( ! ( $ this -> get ( 'db' ) instanceof \ Hubzero \ Database \ Driver ) ) { return ; } $ db = $ this -> get ( 'db' ) ; $ query = $ db -> getQuery ( ) -> select ( 'm.id' ) -> select ( 'm.menutype' ) -> select ( 'm.title' ) -> select ( 'm.alias' ) -> select ( 'm.note' ) -> select ( 'm.path' , 'route' ) -> select ( 'm.link' ) -> select ( 'm.type' ) -> select ( 'm.level' ) -> select ( 'm.language' ) -> select ( 'm.browserNav' ) -> select ( 'm.access' ) -> select ( 'm.params' ) -> select ( 'm.home' ) -> select ( 'm.img' ) -> select ( 'm.template_style_id' ) -> select ( 'm.component_id' ) -> select ( 'm.parent_id' ) -> select ( 'e.element' , 'component' ) -> from ( '#__menu' , 'm' ) -> join ( '#__extensions AS e' , 'e.extension_id' , 'm.component_id' , 'left' ) -> whereEquals ( 'm.published' , 1 ) -> where ( 'm.parent_id' , '>' , 0 ) -> whereEquals ( 'm.client_id' , 0 ) -> order ( 'm.lft' , 'asc' ) ; $ db -> setQuery ( $ query -> toString ( ) ) ; $ this -> _items = $ db -> loadObjectList ( 'id' ) ; foreach ( $ this -> _items as & $ item ) { $ parent_tree = array ( ) ; if ( isset ( $ this -> _items [ $ item -> parent_id ] ) ) { $ parent_tree = $ this -> _items [ $ item -> parent_id ] -> tree ; } $ parent_tree [ ] = $ item -> id ; $ item -> tree = $ parent_tree ; $ url = str_replace ( 'index.php?' , '' , $ item -> link ) ; $ url = str_replace ( '&amp;' , '&' , $ url ) ; parse_str ( $ url , $ item -> query ) ; } }
Loads the entire menu table into memory .
46,736
private static function init ( ) { $ classes [ ] = array ( 'id' => '1' , 'name' => 'uppercase' , 'regex' => '[A-Z]' , 'flag' => '1' ) ; $ classes [ ] = array ( 'id' => '2' , 'name' => 'numeric' , 'regex' => '[0-9]' , 'flag' => '1' ) ; $ classes [ ] = array ( 'id' => '3' , 'name' => 'lowercase' , 'regex' => '[a-z]' , 'flag' => '1' ) ; $ classes [ ] = array ( 'id' => '4' , 'name' => 'special' , 'regex' => '[!"\'(),-.:;?[`{}#$%&*+<=>@^_|~\]\/\\\]' , 'flag' => '1' ) ; $ classes [ ] = array ( 'id' => '5' , 'name' => 'nonalpha' , 'regex' => '[!"\'(),\-.:;?[`{}#$%&*+<=>@^_|~\]\/\\\0-9]' , 'flag' => '0' ) ; $ classes [ ] = array ( 'id' => '6' , 'name' => 'alpha' , 'regex' => '[A-Za-z]' , 'flag' => '0' ) ; self :: $ classes = $ classes ; }
Populate the list of character classes
46,737
public static function match ( $ char = '' ) { $ result = array ( ) ; if ( empty ( self :: $ classes ) ) { self :: init ( ) ; } if ( empty ( self :: $ classes ) ) { return $ result ; } if ( empty ( $ char ) ) { $ char = chr ( 0 ) ; } $ char = $ char { 0 } ; foreach ( self :: $ classes as $ class ) { if ( preg_match ( "/" . $ class [ 'regex' ] . "/" , $ char ) ) { $ match = new \ stdClass ( ) ; $ match -> name = $ class [ 'name' ] ; $ match -> flag = $ class [ 'flag' ] ; $ result [ ] = $ match ; } } return $ result ; }
Match character class
46,738
protected function getEnvironmentArgument ( array $ args ) { foreach ( $ args as $ k => $ v ) { if ( substr ( $ v , 0 , strlen ( '--env' ) ) == '--env' ) { return $ v ; } } return null ; }
Get the enviornment argument from the console .
46,739
public function created ( $ as = '' ) { $ as = strtolower ( $ as ) ; if ( $ as == 'date' ) { return Date :: of ( $ this -> get ( 'created' ) ) -> toLocal ( Lang :: txt ( 'DATE_FORMAT_HZ1' ) ) ; } if ( $ as == 'time' ) { return Date :: of ( $ this -> get ( 'created' ) ) -> toLocal ( Lang :: txt ( 'TIME_FORMAT_HZ1' ) ) ; } return $ this -> get ( 'created' ) ; }
Return a formatted Created timestamp
46,740
public function replies ( $ filters = array ( ) ) { if ( ! isset ( $ filters [ 'item_id' ] ) ) { $ filters [ 'item_id' ] = $ this -> get ( 'item_id' ) ; } if ( ! isset ( $ filters [ 'item_type' ] ) ) { $ filters [ 'item_type' ] = $ this -> get ( 'item_type' ) ; } $ entries = self :: all ( ) -> whereEquals ( 'parent' , ( int ) $ this -> get ( 'id' ) ) -> whereEquals ( 'item_type' , $ filters [ 'item_type' ] ) -> whereEquals ( 'item_id' , ( int ) $ filters [ 'item_id' ] ) ; if ( isset ( $ filters [ 'state' ] ) ) { $ entries -> whereIn ( 'state' , ( array ) $ filters [ 'state' ] ) ; } return $ entries ; }
Get either a count of or list of replies
46,741
public function ballot ( $ user_id = 0 , $ ip = null ) { if ( User :: isGuest ( ) ) { $ vote = new Vote ( ) ; $ vote -> set ( 'item_type' , 'comment' ) ; $ vote -> set ( 'item_id' , $ this -> get ( 'id' ) ) ; $ vote -> set ( 'created_by' , $ user_id ) ; $ vote -> set ( 'ip' , $ ip ) ; return $ vote ; } $ user = $ user_id ? User :: getInstance ( $ user_id ) : User :: getInstance ( ) ; $ ip = $ ip ? : Request :: ip ( ) ; $ votes = $ this -> votes ( ) ; if ( $ user -> get ( 'id' ) ) { $ votes -> whereEquals ( 'created_by' , $ user -> get ( 'id' ) ) ; } elseif ( $ ip ) { $ votes -> whereEquals ( 'ip' , $ ip ) ; } $ vote = $ votes -> ordered ( ) -> limit ( 1 ) -> row ( ) ; if ( ! $ vote || ! $ vote -> get ( 'id' ) ) { $ vote = new Vote ( ) ; $ vote -> set ( 'item_type' , 'comment' ) ; $ vote -> set ( 'item_id' , $ this -> get ( 'id' ) ) ; $ vote -> set ( 'created_by' , $ user_id ) ; if ( $ ip ) { $ vote -> set ( 'ip' , $ ip ) ; } } return $ vote ; }
Check if a user has voted for this entry
46,742
public function vote ( $ vote = 0 , $ user_id = 0 , $ ip = null ) { if ( ! $ this -> get ( 'id' ) ) { $ this -> addError ( Lang :: txt ( 'No record found' ) ) ; return false ; } if ( ! $ vote ) { $ this -> addError ( Lang :: txt ( 'No vote provided' ) ) ; return false ; } $ ip = $ ip ? : Request :: ip ( ) ; $ al = $ this -> ballot ( $ user_id , $ ip ) ; $ al -> set ( 'item_type' , 'comment' ) ; $ al -> set ( 'item_id' , $ this -> get ( 'id' ) ) ; $ al -> set ( 'created_by' , $ user_id ) ; if ( $ ip ) { $ al -> set ( 'ip' , $ ip ) ; } $ vote = $ al -> automaticVote ( [ 'vote' => $ vote ] ) ; if ( $ this -> get ( 'created_by' ) == $ user_id ) { $ this -> addError ( Lang :: txt ( 'Cannot vote for your own entry' ) ) ; return false ; } if ( $ vote != $ al -> get ( 'vote' , 0 ) ) { if ( $ vote > 0 ) { $ this -> set ( 'positive' , ( int ) $ this -> get ( 'positive' ) + 1 ) ; if ( $ al -> get ( 'id' ) ) { $ this -> set ( 'negative' , ( int ) $ this -> get ( 'negative' ) - 1 ) ; } } else { if ( $ al -> get ( 'id' ) ) { $ this -> set ( 'positive' , ( int ) $ this -> get ( 'positive' ) - 1 ) ; } $ this -> set ( 'negative' , ( int ) $ this -> get ( 'negative' ) + 1 ) ; } if ( ! $ this -> save ( ) ) { return false ; } $ al -> set ( 'vote' , $ vote ) ; if ( ! $ al -> save ( ) ) { $ this -> addError ( $ al -> getError ( ) ) ; return false ; } } return true ; }
Vote for the entry
46,743
public function fetchButton ( $ type = 'Help' , $ url = '#' , $ width = 700 , $ height = 500 ) { $ text = \ Lang :: txt ( 'JTOOLBAR_HELP' ) ; $ class = $ this -> fetchIconClass ( 'help' ) ; $ msg = \ Lang :: txt ( 'JHELP' , true ) ; if ( ! strstr ( '?' , $ url ) && ! strstr ( '&' , $ url ) && substr ( $ url , 0 , 4 ) != 'http' ) { $ url = \ Route :: url ( 'index.php?option=com_help&component=' . \ Request :: getCmd ( 'option' ) . '&page=' . $ url ) ; } else { $ url = $ this -> _getCommand ( $ ref = $ type , $ com = false , $ override = false , $ component = \ Request :: getCmd ( 'option' ) ) ; } $ html = '<a href="' . $ url . '" data-title="' . $ text . '" data-message="' . $ msg . '" data-width="' . $ width . '" data-height="' . $ height . '" rel="help" class="toolbar toolbar-popup">' . "\n" ; $ html .= '<span class="' . $ class . '">' . "\n" ; $ html .= $ text . "\n" ; $ html .= '</span>' . "\n" ; $ html .= '</a>' . "\n" ; return $ html ; }
Fetches the button HTML code .
46,744
public static function createURL ( $ ref , $ useComponent = false , $ override = null , $ component = null ) { $ local = false ; if ( $ override ) { $ url = $ override ; } else { $ user = \ User :: getInstance ( ) ; $ url = $ user -> getParam ( 'helpsite' ) ; if ( $ url == '' ) { $ url = $ app -> getCfg ( 'helpurl' ) ; } if ( $ useComponent ) { $ params = \ Component :: params ( $ component ) ; $ url = $ params -> get ( 'helpURL' ) ; if ( $ url == '' ) { $ local = true ; $ url = 'components/{component}/help/{language}/{keyref}' ; } } if ( ! $ url ) { $ local = true ; $ url = 'help/{language}/{keyref}' ; } } if ( $ local ) { if ( ! preg_match ( '#\.html$|\.xml$#i' , $ ref ) ) { $ url .= '.html' ; } } $ lang = \ App :: get ( 'language' ) ; $ version = HVERSION ; $ hver = explode ( '.' , $ version ) ; $ hlang = explode ( '-' , $ lang -> getTag ( ) ) ; $ debug = $ lang -> setDebug ( false ) ; $ keyref = $ lang -> txt ( $ ref ) ; $ lang -> setDebug ( $ debug ) ; $ search = array ( '{app}' , '{component}' , '{keyref}' , '{language}' , '{langcode}' , '{langregion}' , '{major}' , '{minor}' , '{maintenance}' ) ; $ replace = array ( \ App :: get ( 'client' ) -> name , $ component , $ keyref , $ lang -> getTag ( ) , $ hlang [ 0 ] , $ hlang [ 1 ] , $ hver [ 0 ] , $ hver [ 1 ] , $ hver [ 2 ] ) ; if ( $ local ) { $ try = str_replace ( $ search , $ replace , $ url ) ; if ( ! \ Filesystem :: exists ( PATH_ROOT . '/' . $ try ) ) { $ replace [ 3 ] = 'en-GB' ; $ replace [ 4 ] = 'en' ; $ replace [ 5 ] = 'GB' ; } } $ url = str_replace ( $ search , $ replace , $ url ) ; return $ url ; }
Create a URL for a given help key reference
46,745
public function getError ( $ i = null , $ toString = true ) { if ( $ i === null ) { $ error = end ( $ this -> _errors ) ; } elseif ( ! array_key_exists ( $ i , $ this -> _errors ) ) { return false ; } else { $ error = $ this -> _errors [ $ i ] ; } if ( $ error instanceof Exception && $ toString ) { return ( string ) $ error ; } return $ error ; }
Get the most recent error message .
46,746
public static function history ( $ limit = 50 , $ uid = null ) { $ model = self :: all ( ) ; if ( $ limit ) { $ model -> limit ( ( int ) $ limit ) ; } if ( $ uid ) { $ model -> whereEquals ( 'uid' , $ uid ) ; } return $ model -> order ( 'created' , 'desc' ) -> rows ( ) ; }
Get a history of transactions for a user
46,747
public static function deleteRecords ( $ category = null , $ type = null , $ referenceid = null , $ uid = null ) { $ model = self :: all ( ) ; if ( $ category ) { $ model -> whereEquals ( 'category' , $ category ) ; } if ( $ type ) { $ model -> whereEquals ( 'type' , $ type ) ; } if ( $ referenceid ) { $ model -> whereEquals ( 'referenceid' , $ referenceid ) ; } if ( $ uid ) { $ model -> whereEquals ( 'uid' , $ uid ) ; } foreach ( $ model -> rows ( ) as $ row ) { if ( ! $ row -> destroy ( ) ) { return false ; } } return true ; }
Delete records for a given category type and reference combination
46,748
public static function getAmount ( $ category = null , $ type = null , $ referenceid = null , $ uid = null ) { $ model = self :: all ( ) -> select ( 'amount' ) ; if ( $ category ) { $ model -> whereEquals ( 'category' , $ category ) ; } if ( $ type ) { $ model -> whereEquals ( 'type' , $ type ) ; } if ( $ referenceid ) { $ model -> whereEquals ( 'referenceid' , $ referenceid ) ; } if ( $ uid ) { $ model -> whereEquals ( 'uid' , $ uid ) ; } $ row = $ model -> row ( ) ; return $ row -> amount ; }
Get get the transaction amount for a category type reference item and optionally user
46,749
public function render ( $ module , $ attribs = array ( ) , $ content = null ) { if ( ! is_object ( $ module ) ) { $ title = isset ( $ attribs [ 'title' ] ) ? $ attribs [ 'title' ] : null ; $ module = \ App :: get ( 'module' ) -> byName ( $ module , $ title ) ; if ( ! is_object ( $ module ) ) { if ( is_null ( $ content ) ) { return '' ; } else { $ tmp = $ module ; $ module = new stdClass ; $ module -> params = null ; $ module -> module = $ tmp ; $ module -> id = 0 ; $ module -> user = 0 ; } } } if ( ! is_null ( $ content ) ) { $ module -> content = $ content ; } $ params = new Registry ( $ module -> params ) ; if ( isset ( $ attribs [ 'params' ] ) ) { $ template_params = new Registry ( html_entity_decode ( $ attribs [ 'params' ] , ENT_COMPAT , 'UTF-8' ) ) ; $ params -> merge ( $ template_params ) ; $ module = clone $ module ; $ module -> params = ( string ) $ params ; } return \ App :: get ( 'module' ) -> render ( $ module , $ attribs ) ; }
Renders a module script and returns the results as a string
46,750
public static function getInstance ( $ group ) { static $ instances ; if ( ! isset ( $ instances ) ) { $ instances = array ( ) ; } if ( ! isset ( $ instances [ $ group ] ) ) { if ( is_numeric ( $ group ) ) { foreach ( $ instances as $ instance ) { if ( $ instance && $ instance -> get ( 'gidNumber' ) == $ group ) { return $ instance ; break ; } } } $ hzg = new self ( ) ; if ( $ hzg -> read ( $ group ) === false ) { $ instances [ $ group ] = false ; } else { $ instances [ $ group ] = $ hzg ; } } return $ instances [ $ group ] ; }
Returns a reference to a group object
46,751
private function _userids ( $ users ) { $ db = \ App :: get ( 'db' ) ; if ( empty ( $ db ) ) { return false ; } $ usernames = array ( ) ; $ userids = array ( ) ; if ( ! is_array ( $ users ) ) { $ users = array ( $ users ) ; } foreach ( $ users as $ u ) { if ( is_numeric ( $ u ) ) { $ userids [ ] = $ u ; } else { $ usernames [ ] = $ db -> quote ( $ u ) ; } } if ( empty ( $ usernames ) ) { return $ userids ; } $ set = implode ( $ usernames , "," ) ; $ sql = "SELECT id FROM `#__users` WHERE username IN ($set);" ; $ db -> setQuery ( $ sql ) ; $ result = $ db -> loadColumn ( ) ; if ( empty ( $ result ) ) { $ result = array ( ) ; } $ result = array_merge ( $ result , $ userids ) ; return $ result ; }
Get a list of user IDs from a string list or list of usernames
46,752
public function add ( $ key = null , $ value = array ( ) ) { $ users = $ this -> _userids ( $ value ) ; $ this -> __set ( $ key , array_merge ( $ this -> __get ( $ key ) , $ users ) ) ; }
Add users to a table
46,753
public function remove ( $ key = null , $ value = array ( ) ) { $ users = $ this -> _userids ( $ value ) ; $ this -> __set ( $ key , array_diff ( $ this -> __get ( $ key ) , $ users ) ) ; }
Remove users form a table
46,754
static function iterate ( $ func ) { $ db = \ App :: get ( 'db' ) ; $ query = "SELECT cn FROM `#__xgroups`;" ; $ db -> setQuery ( $ query ) ; $ result = $ db -> loadColumn ( ) ; if ( $ result === false ) { return false ; } foreach ( $ result as $ row ) { call_user_func ( $ func , $ row ) ; } return true ; }
Iterate through each group and do something
46,755
public static function exists ( $ group , $ check_system = false ) { $ db = \ App :: get ( 'db' ) ; if ( empty ( $ group ) ) { return false ; } if ( $ check_system ) { if ( is_numeric ( $ group ) && posix_getgrgid ( $ group ) ) { return true ; } if ( ! is_numeric ( $ group ) && posix_getgrnam ( $ group ) ) { return true ; } } if ( Validate :: reserved ( 'group' , $ group ) ) { return true ; } if ( is_numeric ( $ group ) ) { $ query = 'SELECT gidNumber FROM `#__xgroups` WHERE gidNumber=' . $ db -> quote ( $ group ) ; } else { $ query = 'SELECT gidNumber FROM `#__xgroups` WHERE cn=' . $ db -> quote ( $ group ) ; } $ db -> setQuery ( $ query ) ; if ( ! $ db -> query ( ) ) { return false ; } if ( $ db -> loadResult ( ) > 0 ) { return true ; } return false ; }
Check if a group exists . Given the group id returns true if group exists .
46,756
public function is_member_of ( $ table , $ uid ) { if ( ! in_array ( $ table , array ( 'applicants' , 'members' , 'managers' , 'invitees' ) ) ) { return false ; } if ( ! is_numeric ( $ uid ) ) { $ uid = User :: oneByUsername ( $ uid ) -> get ( 'id' ) ; } return in_array ( $ uid , $ this -> get ( $ table ) ) ; }
Check if the user is a member of a given table
46,757
public function getEmails ( $ tbl = 'managers' ) { if ( ! in_array ( $ tbl , array ( 'applicants' , 'members' , 'managers' , 'invitees' ) ) ) { return false ; } $ db = \ App :: get ( 'db' ) ; if ( empty ( $ db ) ) { return false ; } $ query = 'SELECT u.email FROM #__users AS u, #__xgroups_' . $ tbl . ' AS gm WHERE gm.gidNumber=' . $ db -> quote ( $ this -> gidNumber ) . ' AND u.id=gm.uidNumber;' ; $ db -> setQuery ( $ query ) ; $ emails = $ db -> loadColumn ( ) ; return $ emails ; }
Get emails for users
46,758
public function getLogo ( $ what = '' ) { static $ default_logo ; if ( ! $ default_logo ) { $ default_logo = '/core/components/com_groups/site/assets/img/group_default_logo.png' ; } $ link = \ Route :: url ( 'index.php?option=com_groups&cn=' . $ this -> get ( 'cn' ) ) ; $ path = substr ( PATH_APP , strlen ( PATH_ROOT ) ) . '/site/groups/' . $ this -> get ( 'gidNumber' ) . DS . 'uploads' . DS . $ this -> get ( 'logo' ) ; $ src = ( $ this -> get ( 'logo' ) != '' && is_file ( PATH_ROOT . $ path ) ) ? $ path : $ default_logo ; $ members_and_invitees = array_merge ( $ this -> get ( 'members' ) , $ this -> get ( 'invitees' ) ) ; if ( $ this -> get ( 'discoverability' ) == 1 && ! in_array ( \ User :: get ( 'id' ) , $ members_and_invitees ) ) { $ src = $ default_logo ; } $ what = strtolower ( $ what ) ; if ( $ what == 'size' ) { return getimagesize ( PATH_ROOT . $ src ) ; } if ( $ what == 'path' ) { return $ src ; } return \ Request :: base ( true ) . $ src ; }
Return a groups logo
46,759
public function getBasePath ( ) { $ groupParams = \ Component :: params ( 'com_groups' ) ; $ uploadPath = $ groupParams -> get ( 'uploadpath' , '/site/groups' ) ; return $ uploadPath . DS . $ this -> get ( 'gidNumber' ) ; }
Get groups path
46,760
public function downloadLinkForPath ( $ base = 'uploads' , $ path = '' , $ type = 'file' ) { $ groupFolder = $ this -> getBasePath ( ) ; $ segments = array_map ( 'trim' , explode ( DS , $ path ) ) ; if ( $ base != 'uploads' ) { $ baseSegments = array_map ( 'trim' , explode ( DS , $ base ) ) ; $ segments = array_merge ( $ baseSegments , $ segments ) ; } $ link = \ Route :: url ( 'index.php?option=com_groups&cn=' . $ this -> get ( 'cn' ) ) ; $ link .= '/' . ucfirst ( $ type ) . ':' . implode ( '/' , $ segments ) ; return $ link ; }
Return serve up path
46,761
public function split ( $ format = null , $ path = null ) { $ format = $ format ? : 'php' ; $ path = $ path ? : PATH_APP . DS . 'config' ; $ writer = new \ Hubzero \ Config \ FileWriter ( $ format , $ path ) ; foreach ( $ this -> map as $ group => $ values ) { $ contents = array ( ) ; foreach ( $ values as $ key ) { $ contents [ $ key ] = $ this -> get ( $ group . '.' . $ key ) ; } $ writer -> write ( $ contents , $ group ) ; } }
Split the config file into new format
46,762
public function update ( $ file = null ) { $ file = ( $ file ? : $ this -> file ) ; $ contents = $ this -> toString ( 'PHP' , array ( 'class' => 'JConfig' , 'closingtag' => false ) ) ; $ original = '0640' ; if ( is_file ( $ file ) ) { $ original = '0' . decoct ( fileperms ( $ file ) & 0777 ) ; @ chmod ( $ file , octdec ( '0640' ) ) ; } $ result = file_put_contents ( $ file , $ contents ) ; if ( is_file ( $ file ) ) { @ chmod ( $ file , octdec ( $ original ) ) ; } return $ result ; }
Write the contents of the legacy config
46,763
public function setForm ( Form $ form ) { $ this -> form = $ form ; $ this -> formControl = $ form -> getFormControl ( ) ; return $ this ; }
Method to attach a Form object to the field .
46,764
protected function getLabel ( ) { $ label = '' ; if ( $ this -> hidden ) { return $ label ; } $ text = $ this -> element [ 'label' ] ? ( string ) $ this -> element [ 'label' ] : ( string ) $ this -> element [ 'name' ] ; $ text = $ this -> translateLabel ? Lang :: txt ( $ text ) : $ text ; $ class = ! empty ( $ this -> description ) ? 'hasTip' : '' ; $ class = $ this -> required == true ? $ class . ' required-field' : $ class ; $ class = ! empty ( $ this -> labelClass ) ? $ class . ' ' . $ this -> labelClass : $ class ; $ label .= '<label id="' . $ this -> id . '-lbl" for="' . $ this -> id . '" class="' . $ class . '"' ; if ( ! empty ( $ this -> description ) ) { $ label .= ' title="' . htmlspecialchars ( trim ( $ text , ':' ) . '::' . ( $ this -> translateDescription ? Lang :: txt ( $ this -> description ) : $ this -> description ) , ENT_COMPAT , 'UTF-8' ) . '"' ; } if ( $ this -> required ) { $ label .= '>' . $ text . ' <span class="required star">' . Lang :: txt ( 'JOPTION_REQUIRED' ) . '</span></label>' ; } else { $ label .= '>' . $ text . '</label>' ; } return $ label ; }
Method to get the field label markup .
46,765
public function getAttribute ( $ name , $ default = null ) { if ( $ this -> element instanceof SimpleXMLElement ) { $ attributes = $ this -> element -> attributes ( ) ; if ( property_exists ( $ attributes , $ name ) ) { $ value = $ attributes -> $ name ; if ( $ value !== null ) { return ( string ) $ value ; } } } return $ default ; }
Method to get an attribute of the field
46,766
public function parse ( $ path ) { $ data = @ parse_ini_file ( $ path , true ) ; if ( ! $ data ) { $ error = error_get_last ( ) ; throw new ParseException ( $ error ) ; } return $ data ; }
Parses an INI file as an array
46,767
private function preProcess ( Event $ event ) { foreach ( $ this -> dispatcher -> getListeners ( $ event ) as $ listener ) { if ( $ listener instanceof TraceableListener ) { continue ; } $ priority = $ this -> dispatcher -> getListenerPriority ( $ listener , $ event ) ; $ info = $ this -> getListenerInfo ( $ listener , $ event -> getName ( ) ) ; $ name = isset ( $ info [ 'class' ] ) ? $ info [ 'class' ] : $ info [ 'type' ] ; $ this -> dispatcher -> getListeners ( ) [ $ event -> getName ( ) ] -> remove ( $ listener ) ; $ this -> dispatcher -> getListeners ( ) [ $ event -> getName ( ) ] -> add ( new TraceableListener ( $ listener , $ name , $ this -> stopwatch ) , $ priority ) ; } }
Called before preTrigger
46,768
private function postProcess ( Event $ event ) { $ skipped = false ; foreach ( $ this -> dispatcher -> getListeners ( $ event ) as $ listener ) { if ( ! ( $ listener instanceof TraceableListener ) ) { continue ; } $ priority = $ this -> dispatcher -> getListenerPriority ( $ listener , $ event ) ; $ this -> dispatcher -> getListeners ( ) [ $ event -> getName ( ) ] -> remove ( $ listener ) ; $ this -> dispatcher -> getListeners ( ) [ $ event -> getName ( ) ] -> add ( $ listener -> getWrappedListener ( ) , $ priority ) ; $ info = $ this -> getListenerInfo ( $ listener -> getWrappedListener ( ) , $ event -> getName ( ) ) ; $ eventName = $ event -> getName ( ) ; if ( $ listener -> wasCalled ( ) ) { if ( null !== $ this -> logger ) { $ this -> logger -> debug ( sprintf ( 'Notified event "%s" to listener "%s".' , $ eventName , $ info [ 'pretty' ] ) ) ; } if ( ! isset ( $ this -> called [ $ eventName ] ) ) { $ this -> called [ $ eventName ] = new \ SplObjectStorage ( ) ; } $ this -> called [ $ eventName ] -> attach ( $ listener ) ; } if ( null !== $ this -> logger && $ skipped ) { $ this -> logger -> debug ( sprintf ( 'Listener "%s" was not called for event "%s".' , $ info [ 'pretty' ] , $ eventName ) ) ; } if ( $ listener -> stoppedPropagation ( ) ) { if ( null !== $ this -> logger ) { $ this -> logger -> debug ( sprintf ( 'Listener "%s" stopped propagation of the event "%s".' , $ info [ 'pretty' ] , $ eventName ) ) ; } $ skipped = true ; } } }
Called after postTrigger
46,769
public static function tld ( ) { $ arr = self :: _getConfigArray ( ) ; if ( is_empty ( $ arr ) ) { return '' ; } $ tld = end ( $ arr ) ; return $ tld ; }
Get top level domain
46,770
public static function domain ( ) { $ arr = self :: _getConfigArray ( ) ; array_shift ( $ arr ) ; if ( is_null ( $ arr ) ) { $ arr = [ ] ; } $ domain = implode ( '.' , $ arr ) ; return $ domain ; }
Get parent domain
46,771
public function fetch ( $ key , $ value ) { foreach ( $ this -> _data as $ data ) { if ( $ data -> get ( $ key ) == $ value ) { return $ data ; } } return null ; }
Fetch Item with key equal to value
46,772
public function lists ( $ key , $ default = null ) { $ results = array ( ) ; foreach ( $ this -> _data as $ data ) { array_push ( $ results , $ data -> get ( $ key ) ) ; } return $ results ; }
Lists a specific key from the item list
46,773
protected static function getSpecialized ( $ properties , $ adapter ) { if ( $ properties [ 'type' ] == 'dir' ) { return new Directory ( $ properties , $ adapter ) ; } if ( ! isset ( $ properties [ 'extension' ] ) ) { $ bits = explode ( '.' , $ properties [ 'path' ] ) ; if ( count ( $ bits ) > 1 ) { $ properties [ 'extension' ] = end ( $ bits ) ; } else { $ properties [ 'extension' ] = '' ; } } $ file = __DIR__ . '/Type/' . ucfirst ( $ properties [ 'extension' ] ) . '.php' ; if ( file_exists ( $ file ) ) { $ class = __NAMESPACE__ . '\\Type\\' . ucfirst ( $ properties [ 'extension' ] ) ; return new $ class ( $ properties , $ adapter ) ; } return new File ( $ properties , $ adapter ) ; }
Gets the most specialized object for a given entity type
46,774
public function isSafe ( $ remote = false ) { $ command = App :: get ( 'config' ) -> get ( 'virus_scanner' , 'clamscan -i -r --no-summary --block-encrypted' ) ; if ( $ this -> isLocal ( ) || ( ! $ this -> isLocal ( ) && $ remote ) ) { if ( ! $ this -> isLocal ( ) ) { $ temp = Manager :: getTempPath ( uniqid ( true ) . '.tmp' ) ; $ this -> copy ( $ temp ) ; $ path = $ temp -> getAbsolutePath ( ) ; } else { $ path = $ this -> getAbsolutePath ( ) ; } if ( strstr ( $ command , '%s' ) ) { $ command = sprintf ( $ command , escapeshellarg ( $ path ) ) ; } else { $ command .= ' ' . escapeshellarg ( $ path ) ; } exec ( $ command , $ output , $ status ) ; if ( ! $ this -> isLocal ( ) ) { $ temp -> delete ( ) ; } if ( $ status >= 1 ) { return false ; } } return true ; }
Checks to see if the entity is virus free
46,775
public function getParent ( $ raw = true ) { $ return = '' ; if ( isset ( $ this -> dirname ) ) { $ return = $ this -> dirname ; } else if ( $ path = $ this -> getPath ( ) ) { $ bits = explode ( '/' , $ path ) ; array_pop ( $ bits ) ; if ( count ( $ bits ) > 0 ) { $ return = implode ( '/' , $ bits ) ; } } return $ raw ? $ return : self :: fromPath ( $ return , $ this -> getAdapter ( ) ) ; }
Grabs the parent element if applicable
46,776
public function getTimestamp ( ) { if ( ! isset ( $ this -> timestamp ) ) { $ this -> timestamp = $ this -> hasAdapterOrFail ( ) -> adapter -> getTimestamp ( $ this -> getPath ( ) ) ; } return $ this -> timestamp ; }
Grabs the timestamp
46,777
public function getDirLevel ( ) { if ( ! trim ( $ this -> getPath ( ) ) ) { return 0 ; } $ dirParts = explode ( '/' , $ this -> getPath ( ) ) ; return count ( $ dirParts ) ; }
Computes the depth of the entity
46,778
public function move ( $ to ) { $ dest = $ to . '/' . $ this -> getDisplayName ( ) . '.' . $ this -> getExtension ( ) ; $ return = $ this -> hasAdapterOrFail ( ) -> adapter -> rename ( $ this -> getPath ( ) , $ dest ) ; if ( $ return ) { $ this -> path = $ dest ; } return $ return ; }
Moves the entity
46,779
public function rename ( $ to ) { $ dest = $ this -> getParent ( ) . '/' . $ to ; $ return = $ this -> hasAdapterOrFail ( ) -> adapter -> rename ( $ this -> getPath ( ) , $ dest ) ; if ( $ return ) { $ this -> path = $ dest ; } return $ return ; }
Renames the entity
46,780
public function copy ( $ to ) { if ( is_string ( $ to ) ) { return $ this -> hasAdapterOrFail ( ) -> adapter -> copy ( $ this -> getPath ( ) , $ to ) ; } else { return Manager :: copy ( $ this , $ to ) ; } }
Copies the entity
46,781
public static function clearStatics ( ) { self :: $ viewLevels = array ( ) ; self :: $ assetRules = array ( ) ; self :: $ userGroups = array ( ) ; self :: $ userGroupPaths = array ( ) ; self :: $ groupsByUser = array ( ) ; }
Method for clearing static caches .
46,782
public static function check ( $ userId , $ action , $ asset = null ) { $ userId = ( int ) $ userId ; $ action = strtolower ( preg_replace ( '#[\s\-]+#' , '.' , trim ( $ action ) ) ) ; $ asset = strtolower ( preg_replace ( '#[\s\-]+#' , '.' , trim ( $ asset ) ) ) ; if ( empty ( $ asset ) ) { $ asset = Asset :: getRootId ( ) ; } if ( empty ( self :: $ assetRules [ $ asset ] ) ) { self :: $ assetRules [ $ asset ] = self :: getAssetRules ( $ asset , true ) ; } $ identities = self :: getGroupsByUser ( $ userId ) ; array_unshift ( $ identities , $ userId * - 1 ) ; return self :: $ assetRules [ $ asset ] -> allow ( $ action , $ identities ) ; }
Method to check if a user is authorised to perform an action optionally on an asset .
46,783
public static function checkGroup ( $ groupId , $ action , $ asset = null ) { $ groupId = ( int ) $ groupId ; $ action = strtolower ( preg_replace ( '#[\s\-]+#' , '.' , trim ( $ action ) ) ) ; $ asset = strtolower ( preg_replace ( '#[\s\-]+#' , '.' , trim ( $ asset ) ) ) ; $ groupPath = self :: getGroupPath ( $ groupId ) ; if ( empty ( $ asset ) ) { $ rootId = Asset :: getRootId ( ) ; } if ( empty ( self :: $ assetRules [ $ asset ] ) ) { self :: $ assetRules [ $ asset ] = self :: getAssetRules ( $ asset , true ) ; } return self :: $ assetRules [ $ asset ] -> allow ( $ action , $ groupPath ) ; }
Method to check if a group is authorised to perform an action optionally on an asset .
46,784
public static function getAssetRules ( $ asset , $ recursive = false ) { $ model = Asset :: blank ( ) ; $ db = App :: get ( 'db' ) ; $ query = $ db -> getQuery ( ) -> select ( $ recursive ? 'b.rules' : 'a.rules' ) ; $ query -> from ( $ model -> getTableName ( ) , 'a' ) ; if ( is_numeric ( $ asset ) ) { $ query -> whereEquals ( 'a.id' , ( int ) $ asset ) ; } else { $ query -> whereEquals ( 'a.name' , $ asset ) ; } if ( $ recursive ) { $ query -> joinRaw ( $ model -> getTableName ( ) . ' AS b' , 'b.lft <= a.lft AND b.rgt >= a.rgt' , 'left' ) ; $ query -> order ( 'b.lft' , 'asc' ) ; } $ query -> group ( $ recursive ? 'b.id, b.rules, b.lft' : 'a.id, a.rules, a.lft' ) ; $ db -> setQuery ( $ query -> toString ( ) ) ; $ result = $ db -> loadColumn ( ) ; if ( empty ( $ result ) && $ recursive ) { $ result = Asset :: oneOrFail ( Asset :: getRootId ( ) ) ; $ result = array ( $ result -> get ( 'rules' ) ) ; } $ rules = new Rules ; $ rules -> mergeCollection ( $ result ) ; return $ rules ; }
Method to return the Rules object for an asset . The returned object can optionally hold only the rules explicitly set for the asset or the summation of all inherited rules from parent assets and explicit rules .
46,785
public static function getGroupsByUser ( $ userId , $ recursive = true ) { $ storeId = $ userId . ':' . ( int ) $ recursive ; if ( ! isset ( self :: $ groupsByUser [ $ storeId ] ) ) { if ( empty ( $ userId ) && ! $ recursive ) { $ result = array ( \ Component :: params ( 'com_members' ) -> get ( 'guest_usergroup' , 1 ) ) ; } else { $ db = App :: get ( 'db' ) ; $ query = $ db -> getQuery ( ) ; $ query -> select ( $ recursive ? 'b.id' : 'a.id' ) ; if ( empty ( $ userId ) ) { $ query -> from ( '#__usergroups' , 'a' ) -> whereEquals ( 'a.id' , ( int ) \ Component :: params ( 'com_members' ) -> get ( 'guest_usergroup' , 1 ) ) ; } else { $ query -> from ( '#__user_usergroup_map' , 'map' ) -> whereEquals ( 'map.user_id' , ( int ) $ userId ) -> join ( '#__usergroups AS a' , 'a.id' , 'map.group_id' , 'left' ) ; } if ( $ recursive ) { $ query -> joinRaw ( '#__usergroups AS b' , 'b.lft <= a.lft AND b.rgt >= a.rgt' , 'left' ) ; } $ db -> setQuery ( $ query -> toString ( ) ) ; $ result = $ db -> loadColumn ( ) ; Arr :: toInteger ( $ result ) ; if ( empty ( $ result ) ) { $ result = array ( '1' ) ; } else { $ result = array_unique ( $ result ) ; } } self :: $ groupsByUser [ $ storeId ] = $ result ; } return self :: $ groupsByUser [ $ storeId ] ; }
Method to return a list of user groups mapped to a user . The returned list can optionally hold only the groups explicitly mapped to the user or all groups both explicitly mapped and inherited by the user .
46,786
public static function getUsersByGroup ( $ groupId , $ recursive = false ) { $ test = $ recursive ? '>=' : '=' ; $ db = App :: get ( 'db' ) ; $ query = $ db -> getQuery ( ) -> select ( 'DISTINCT(user_id)' ) -> from ( '#__usergroups' , 'ug1' ) -> joinRaw ( '#__usergroups AS ug2' , 'ug2.lft' . $ test . 'ug1.lft AND ug1.rgt' . $ test . 'ug2.rgt' , 'inner' ) -> join ( '#__user_usergroup_map AS m' , 'm.group_id' , 'ug2.id' , 'inner' ) -> whereEquals ( 'ug1.id' , $ groupId ) ; $ db -> setQuery ( $ query -> toString ( ) ) ; $ result = $ db -> loadColumn ( ) ; Arr :: toInteger ( $ result ) ; return $ result ; }
Method to return a list of user Ids contained in a Group
46,787
public static function getAuthorisedViewLevels ( $ userId ) { $ groups = self :: getGroupsByUser ( $ userId ) ; if ( empty ( self :: $ viewLevels ) ) { $ levels = Viewlevel :: all ( ) -> rows ( ) ; foreach ( $ levels as $ level ) { self :: $ viewLevels [ $ level -> get ( 'id' ) ] = ( array ) json_decode ( $ level -> get ( 'rules' ) ) ; } } $ authorised = array ( 1 ) ; foreach ( self :: $ viewLevels as $ level => $ rule ) { foreach ( $ rule as $ id ) { if ( ( $ id < 0 ) && ( ( $ id * - 1 ) == $ userId ) ) { $ authorised [ ] = $ level ; break ; } elseif ( ( $ id >= 0 ) && in_array ( $ id , $ groups ) ) { $ authorised [ ] = $ level ; break ; } } } return $ authorised ; }
Method to return a list of view levels for which the user is authorised .
46,788
public static function getActionsFromFile ( $ file , $ xpath = "/access/section[@name='component']/" ) { if ( ! is_file ( $ file ) ) { return false ; } return self :: getActionsFromData ( self :: getXml ( $ file , true ) , $ xpath ) ; }
Method to return a list of actions from a file for which permissions can be set .
46,789
public static function getActionsFromData ( $ data , $ xpath = "/access/section[@name='component']/" ) { if ( ! ( $ data instanceof SimpleXMLElement ) && ! is_string ( $ data ) ) { return false ; } if ( is_string ( $ data ) ) { $ data = self :: getXml ( $ data , false ) ; if ( ! $ data ) { return false ; } } $ actions = array ( ) ; $ elements = $ data -> xpath ( $ xpath . 'action[@name][@title][@description]' ) ; if ( ! empty ( $ elements ) ) { foreach ( $ elements as $ action ) { $ actions [ ] = ( object ) array ( 'name' => ( string ) $ action [ 'name' ] , 'title' => ( string ) $ action [ 'title' ] , 'description' => ( string ) $ action [ 'description' ] ) ; } } return $ actions ; }
Method to return a list of actions from a string or from an xml for which permissions can be set .
46,790
public static function getXml ( $ data , $ isFile = true ) { libxml_use_internal_errors ( true ) ; if ( $ isFile ) { $ xml = simplexml_load_file ( $ data ) ; } else { $ xml = simplexml_load_string ( $ data ) ; } return $ xml ; }
Reads an XML file or string .
46,791
public static function getSessionWithUserId ( $ userid ) { $ sessions = \ App :: get ( 'session' ) -> getStore ( ) -> all ( array ( 'guest' => 0 , 'distinct' => 1 ) ) ; foreach ( $ sessions as $ session ) { if ( $ session -> userid == $ userid ) { return $ session ; } } return null ; }
Get Session by User Id
46,792
public static function isAvailable ( ) { $ conf = new \ Hubzero \ Config \ Repository ( 'site' ) ; return is_writable ( $ conf -> get ( 'cache_path' , PATH_APP . DIRECTORY_SEPARATOR . 'cache' ) ) ; }
Test to see if the cache storage is available .
46,793
public function getOpt ( $ key , $ default = false ) { return ( isset ( $ this -> opts [ $ key ] ) ) ? $ this -> opts [ $ key ] : $ default ; }
Getter for those additional options that a given command may use
46,794
public function parse ( ) { if ( isset ( $ this -> raw ) && count ( $ this -> raw ) > 0 ) { $ class = isset ( $ this -> raw [ 1 ] ) ? $ this -> raw [ 1 ] : 'help' ; $ task = ( isset ( $ this -> raw [ 2 ] ) && substr ( $ this -> raw [ 2 ] , 0 , 1 ) != "-" ) ? $ this -> raw [ 2 ] : 'execute' ; $ this -> class = self :: routeCommand ( $ class ) ; $ this -> task = self :: routeTask ( $ class , $ this -> class , $ task ) ; for ( $ i = 2 ; $ i < count ( $ this -> raw ) ; $ i ++ ) { if ( $ i == 2 && substr ( $ this -> raw [ $ i ] , 0 , 1 ) != "-" ) { continue ; } if ( strpos ( $ this -> raw [ $ i ] , "=" ) !== false ) { $ parts = explode ( "=" , $ this -> raw [ $ i ] , 2 ) ; $ key = preg_replace ( "/^([-]{1,2})/" , "" , $ parts [ 0 ] ) ; $ value = ( $ parts [ 1 ] ) ; if ( isset ( $ this -> opts [ $ key ] ) ) { $ this -> opts [ $ key ] = ( array ) $ this -> opts [ $ key ] ; array_push ( $ this -> opts [ $ key ] , $ value ) ; } else { $ this -> opts [ $ key ] = $ value ; } continue ; } elseif ( substr ( $ this -> raw [ $ i ] , 0 , 1 ) == '-' ) { if ( preg_match ( "/^-([[:alpha:]]{2,})/" , $ this -> raw [ $ i ] , $ matches ) ) { if ( isset ( $ matches [ 1 ] ) ) { foreach ( str_split ( $ matches [ 1 ] , 1 ) as $ k ) { $ this -> opts [ $ k ] = true ; } } continue ; } else { $ key = preg_replace ( "/^([-]{1,2})/" , "" , $ this -> raw [ $ i ] ) ; $ value = true ; } } else { $ key = $ i ; $ value = $ this -> raw [ $ i ] ; } $ this -> opts [ $ key ] = $ value ; } } }
Parse the raw arguments into command task and additional options
46,795
public static function routeCommand ( $ command = 'help' ) { if ( $ aliases = Config :: get ( 'aliases' ) ) { if ( array_key_exists ( $ command , $ aliases ) ) { if ( strpos ( $ aliases -> $ command , '::' ) !== false ) { $ bits = explode ( '::' , $ aliases -> $ command ) ; $ command = $ bits [ 0 ] ; $ aliasTask = $ bits [ 1 ] ; } else { $ command = $ aliases -> $ command ; } } } foreach ( self :: $ commandNamespaces as $ namespace ) { $ bits = [ ] ; if ( strpos ( $ command , ':' ) ) { $ bits = explode ( ':' , $ command ) ; } else { $ bits [ ] = $ command ; } $ bits = array_map ( 'ucfirst' , $ bits ) ; for ( $ i = 0 ; $ i < count ( $ bits ) ; $ i ++ ) { $ loc = $ i + 1 ; if ( strpos ( $ namespace , "{\$$loc}" ) ) { $ namespace = str_replace ( "{\$$loc}" , $ bits [ $ i ] , $ namespace ) ; unset ( $ bits [ $ i ] ) ; } } if ( count ( $ bits ) > 0 ) { $ namespace .= '\\' . implode ( '\\' , $ bits ) ; } if ( class_exists ( $ namespace ) ) { $ class = $ namespace ; break ; } } if ( ! isset ( $ class ) ) { throw new UnsupportedCommandException ( "Unknown command: {$command}." ) ; } return $ class ; }
Routes command to the proper file based on the input given
46,796
public static function routeTask ( $ command , $ class , $ task = 'execute' ) { if ( $ aliases = Config :: get ( 'aliases' ) ) { if ( array_key_exists ( $ command , $ aliases ) ) { if ( strpos ( $ aliases -> $ command , '::' ) !== false ) { $ bits = explode ( '::' , $ aliases -> $ command ) ; $ task = $ bits [ 1 ] ; } } } if ( ! method_exists ( $ class , $ task ) ) { throw new UnsupportedTaskException ( "{$class} does not support the {$task} method." ) ; } return $ task ; }
Routes task to the proper method based on the input given
46,797
private function normalizeExpandKeys ( $ expandKeys ) { $ expandKeys = array_map ( 'trim' , explode ( ',' , $ expandKeys ) ) ; $ normalized = [ ] ; foreach ( $ this -> acceptedKeys as $ type => $ acceptedKeys ) { foreach ( $ expandKeys as $ expandKey ) { if ( in_array ( $ expandKey , $ acceptedKeys ) ) { $ normalized [ $ expandKey ] = $ type ; } } } return $ normalized ; }
Normalize expand keys
46,798
private function convertExpandKeysInObjects ( $ expandKeys , $ object ) { if ( ! is_object ( $ object ) ) { return $ object ; } foreach ( array_keys ( get_object_vars ( $ object ) ) as $ key ) { if ( array_key_exists ( $ key , $ expandKeys ) ) { $ func = $ expandKeys [ $ key ] . 'Expander' ; if ( method_exists ( $ this , $ func ) ) { $ object -> $ key = $ this -> $ func ( $ object -> $ key ) ; } } } return $ object ; }
Convert keys in object
46,799
public static function getInstance ( $ instance ) { $ db = \ App :: get ( 'db' ) ; if ( empty ( $ db ) ) { return false ; } $ hzph = new self ( ) ; if ( is_numeric ( $ instance ) && $ instance > 0 ) { $ hzph -> user_id = $ instance ; } else { $ query = "SELECT id FROM `#__users` WHERE username=" . $ db -> quote ( $ instance ) . ";" ; $ db -> setQuery ( $ query ) ; $ result = $ db -> loadResult ( ) ; if ( is_numeric ( $ result ) && $ result > 0 ) { $ hzph -> user_id = $ result ; } } if ( empty ( $ hzph -> user_id ) ) { return false ; } return $ hzph ; }
Get an instance of a user s password History