idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
46,600
public static function save ( $ data ) { $ instance = self :: getInstance ( ) ; $ data = $ instance -> merge ( $ instance -> config -> toArray ( ) , $ data ) ; $ data = $ instance -> unique ( $ data ) ; $ instance -> config = new Registry ( $ data ) ; $ instance -> write ( ) ; return true ; }
Saves the data to the config file
46,601
private function merge ( $ existing , $ incoming ) { foreach ( $ incoming as $ k => $ v ) { if ( is_array ( $ v ) ) { $ existing [ $ k ] = isset ( $ existing [ $ k ] ) ? $ this -> merge ( $ existing [ $ k ] , $ v ) : $ this -> merge ( array ( ) , $ v ) ; } else { if ( is_numeric ( $ k ) ) { $ existing [ ] = $ v ; } else { $ existing [ $ k ] = $ v ; } } } return $ existing ; }
Merge multiple arrays into one recursively
46,602
private function unique ( $ var ) { if ( is_array ( $ var ) ) { if ( isset ( $ var [ 0 ] ) ) { $ var = array_map ( 'unserialize' , array_unique ( array_map ( 'serialize' , $ var ) ) ) ; } foreach ( $ var as & $ sub ) { if ( is_array ( $ sub ) ) { $ sub = $ this -> unique ( $ sub ) ; } } } return $ var ; }
Multi - dimensional array_unique function
46,603
private function discoverComponentSections ( ) { $ loader = null ; if ( App :: has ( 'component' ) ) { $ loader = App :: get ( 'component' ) ; } $ roots = array ( PATH_CORE , PATH_APP ) ; foreach ( $ roots as $ base ) { foreach ( glob ( $ base . DS . 'components' . DS . 'com_*' . DS . 'api' ) as $ path ) { $ pieces = explode ( DS , $ path ) ; array_pop ( $ pieces ) ; $ component = str_replace ( 'com_' , '' , array_pop ( $ pieces ) ) ; if ( $ loader && ! $ loader -> isEnabled ( 'com_' . $ component ) ) { continue ; } $ this -> sections [ $ component ] = glob ( $ path . DS . 'controllers' . DS . '*.php' ) ; } } }
Load api controller files and group by component
46,604
private function parseClassFromFile ( $ file , $ returnAsParts = false ) { $ file = str_replace ( array ( PATH_CORE . DS . 'components' . DS . 'com_' , PATH_APP . DS . 'components' . DS . 'com_' , '.php' ) , array ( '' , '' , '' ) , $ file ) ; $ parts = explode ( DS , $ file ) ; array_unshift ( $ parts , 'components' ) ; if ( $ returnAsParts ) { $ parts [ 'namespace' ] = $ parts [ 0 ] ; $ parts [ 'component' ] = $ parts [ 1 ] ; $ parts [ 'client' ] = $ parts [ 2 ] ; $ parts [ 'controller' ] = $ parts [ 4 ] ; $ b = explode ( 'v' , $ parts [ 4 ] ) ; $ parts [ 'version' ] = end ( $ b ) ; return $ parts ; } $ parts = array_map ( 'ucfirst' , $ parts ) ; return str_replace ( '.' , '_' , implode ( '\\' , $ parts ) ) ; }
Get class name based on file
46,605
public static function isImage ( $ image ) { if ( ! trim ( $ image ) ) { return false ; } $ dot = strrpos ( $ image , '.' ) + 1 ; $ ext = substr ( $ image , $ dot ) ; $ ext = strtolower ( $ ext ) ; if ( ! in_array ( $ ext , array ( 'gif' , 'jpg' , 'jpe' , 'jpeg' , 'png' , 'bmp' ) ) ) { return false ; } return true ; }
Check if a filename is a supported image type
46,606
public static function addComponentStylesheet ( $ component , $ stylesheet = '' , $ dir = 'css' ) { if ( $ dir != 'css' ) { $ stylesheet = $ dir . '/' . $ stylesheet ; } $ asset = new Stylesheet ( $ component , $ stylesheet ) ; if ( defined ( 'JPATH_GROUPCOMPONENT' ) ) { $ base = substr ( JPATH_GROUPCOMPONENT , strlen ( PATH_ROOT ) ) ; $ asset -> setPath ( 'source' , $ base . DS . 'assets' . DS . 'css' . DS . $ asset -> file ( ) ) ; $ asset -> setPath ( 'override' , $ base . DS . 'assets' . DS . 'css' . DS . $ asset -> file ( ) ) ; } if ( $ asset -> exists ( ) ) { if ( $ document = self :: app ( 'document' ) ) { $ document -> addStyleSheet ( $ asset -> link ( ) ) ; } } }
Adds a linked stylesheet from a component to the page
46,607
public static function addComponentScript ( $ component , $ script = '' , $ dir = 'js' ) { if ( $ dir != 'js' ) { $ script = $ dir . '/' . $ script ; } $ asset = new Javascript ( $ component , $ script ) ; if ( defined ( 'JPATH_GROUPCOMPONENT' ) ) { $ base = substr ( JPATH_GROUPCOMPONENT , strlen ( PATH_ROOT ) ) ; $ asset -> setPath ( 'source' , $ base . DS . 'assets' . DS . ( $ dir ? DS . $ dir : '' ) . DS . $ asset -> file ( ) ) ; $ asset -> setPath ( 'override' , $ base . DS . 'assets' . DS . ( $ dir ? DS . $ dir : '' ) . DS . $ asset -> file ( ) ) ; } if ( $ asset -> exists ( ) ) { if ( $ document = self :: app ( 'document' ) ) { $ document -> addScript ( $ asset -> link ( ) ) ; } } }
Adds a linked script from a component to the page
46,608
public static function addSystemStylesheet ( $ stylesheet , $ dir = 'css' ) { if ( $ dir != 'css' ) { $ stylesheet = $ dir . '/' . $ stylesheet ; } $ asset = new Stylesheet ( 'system' , $ stylesheet ) ; if ( $ asset -> exists ( ) ) { if ( $ document = self :: app ( 'document' ) ) { $ document -> addStyleSheet ( $ asset -> link ( ) ) ; } } }
Adds a linked stylesheet from the system to the page
46,609
public static function addSystemScript ( $ script , $ dir = 'js' ) { if ( $ dir != 'js' ) { $ script = $ dir . '/' . $ script ; } $ asset = new Javascript ( 'system' , $ script ) ; if ( $ asset -> exists ( ) ) { if ( $ document = self :: app ( 'document' ) ) { $ document -> addScript ( $ asset -> link ( ) ) ; } } }
Adds a linked script from the system to the page
46,610
public static function getComponentStylesheet ( $ component , $ stylesheet , $ dir = 'css' ) { $ template = 'system' ; if ( $ t = self :: app ( 'template' ) ) { $ template = self :: app ( 'template' ) -> template ; } $ paths = array ( ) ; $ paths [ ] = DS . 'templates' . DS . $ template . DS . 'html' . DS . $ component . DS . $ stylesheet ; $ paths [ ] = DS . 'components' . DS . $ component . DS . 'assets' . ( $ dir ? DS . $ dir : '' ) . DS . $ stylesheet ; $ paths [ ] = DS . 'components' . DS . $ component . DS . $ folder . DS . $ stylesheet ; $ root = self :: base ( ) ; foreach ( $ paths as $ path ) { if ( file_exists ( $ root . $ path ) ) { return rtrim ( Request :: base ( true ) , '/' ) . $ path ; } } }
Gets the path to a component stylesheet checks template overrides first then component
46,611
public static function getModuleImage ( $ module , $ image , $ dir = 'img' ) { $ image = ltrim ( $ image , DS ) ; if ( ! self :: isImage ( $ image ) ) { return $ image ; } $ template = 'system' ; if ( $ t = self :: app ( 'template' ) ) { $ template = self :: app ( 'template' ) -> template ; } $ paths = array ( ) ; $ paths [ ] = DS . 'templates' . DS . $ template . DS . 'html' . DS . $ module . DS . 'images' . DS . $ image ; $ paths [ ] = DS . 'modules' . DS . $ module . DS . 'assets' . ( $ dir ? DS . $ dir : '' ) . DS . $ image ; $ paths [ ] = DS . 'modules' . DS . $ module . DS . 'images' . DS . $ image ; $ root = self :: base ( ) ; foreach ( $ paths as $ path ) { if ( file_exists ( $ root . $ path ) ) { return rtrim ( Request :: base ( true ) , '/' ) . $ path ; } } }
Gets the path to a module image checks template overrides first then module
46,612
public static function addModuleStyleSheet ( $ module , $ stylesheet = '' , $ dir = 'css' ) { if ( $ dir != 'css' ) { $ stylesheet = $ dir . '/' . $ stylesheet ; } $ asset = new Stylesheet ( $ module , $ stylesheet ) ; if ( $ asset -> exists ( ) ) { if ( $ document = self :: app ( 'document' ) ) { $ document -> addStyleSheet ( $ asset -> link ( ) ) ; } } }
Adds a linked stylesheet from a module to the page
46,613
public static function getPluginImage ( $ folder , $ plugin , $ image , $ dir = 'img' ) { $ image = ltrim ( $ image , DS ) ; if ( ! self :: isImage ( $ image ) ) { return $ image ; } $ template = 'system' ; if ( $ t = self :: app ( 'template' ) ) { $ template = self :: app ( 'template' ) -> template ; } $ paths = array ( ) ; $ paths [ ] = DS . 'templates' . DS . $ template . DS . 'html' . DS . 'plg_' . $ folder . '_' . $ plugin . DS . 'images' . DS . $ image ; $ paths [ ] = DS . 'plugins' . DS . $ folder . DS . $ plugin . DS . 'assets' . ( $ dir ? DS . $ dir : '' ) . DS . $ image ; $ paths [ ] = DS . 'plugins' . DS . $ folder . DS . $ plugin . DS . 'images' . DS . $ image ; foreach ( $ paths as $ i => $ path ) { $ root = JPATH_SITE ; if ( $ i == 0 ) { $ root = JPATH_ADMINISTRATOR ; } if ( file_exists ( $ root . $ path ) ) { if ( $ i == 0 ) { $ b = rtrim ( Request :: base ( true ) , DS ) ; } else { $ b = str_replace ( '/administrator' , '' , rtrim ( Request :: base ( true ) , DS ) ) ; } return $ b . $ path ; } } }
Gets the path to a plugin image checks template overrides first then plugin folder
46,614
public static function addPluginStyleSheet ( $ folder , $ plugin , $ stylesheet = '' , $ dir = 'css' ) { if ( $ dir != 'css' ) { $ stylesheet = $ dir . '/' . $ stylesheet ; } $ asset = new Stylesheet ( 'plg_' . $ folder . '_' . $ plugin , $ stylesheet ) ; if ( $ asset -> exists ( ) ) { if ( $ document = self :: app ( 'document' ) ) { $ document -> addStyleSheet ( $ asset -> link ( ) ) ; } } }
Adds a linked stylesheet from a plugin to the page
46,615
public static function getSystemImage ( $ image , $ dir = 'images' ) { $ image = ltrim ( $ image , DS ) ; if ( ! self :: isImage ( $ image ) ) { return $ image ; } $ template = DS . 'core' . DS . 'templates' . DS . 'system' ; if ( $ t = self :: app ( 'template' ) ) { $ template = substr ( $ t -> path , strlen ( PATH_ROOT ) ) ; } $ paths = array ( ) ; $ paths [ ] = $ template . DS . 'html' . DS . 'system' . ( $ dir ? DS . $ dir : '' ) . DS . $ image ; $ paths [ ] = DS . 'core' . DS . 'assets' . DS . $ dir . DS . $ image ; foreach ( $ paths as $ path ) { if ( file_exists ( PATH_ROOT . $ path ) ) { return str_replace ( '/administrator' , '' , rtrim ( Request :: base ( true ) , '/' ) ) . $ path ; } } }
Gets the path to a system image
46,616
public function getRecords ( $ uid , $ type = null ) { $ entries = self :: all ( ) -> whereEquals ( 'uid' , $ uid ) ; if ( $ type ) { $ entries -> whereEquals ( 'type' , $ type ) ; } return $ entries -> order ( 'priority' , 'asc' ) -> rows ( ) ; }
Get records for a user
46,617
public function css ( $ stylesheet = '' , $ extension = null , $ attributes = array ( ) ) { $ extension = $ extension ? : $ this -> detectExtensionName ( ) ; $ attr = array_merge ( array ( 'type' => 'text/css' , 'media' => null , 'attribs' => array ( ) ) , $ attributes ) ; $ asset = new Stylesheet ( $ extension , $ stylesheet ) ; $ asset = $ this -> isSuperGroupAsset ( $ asset ) ; if ( $ asset -> exists ( ) ) { if ( $ asset -> isDeclaration ( ) ) { \ App :: get ( 'document' ) -> addStyleDeclaration ( $ asset -> contents ( ) ) ; } else { \ App :: get ( 'document' ) -> addStyleSheet ( $ asset -> link ( ) , $ attr [ 'type' ] , $ attr [ 'media' ] , $ attr [ 'attribs' ] ) ; } } return $ this ; }
Push CSS to the document
46,618
public function js ( $ asset = '' , $ extension = null , $ attributes = array ( ) ) { $ extension = $ extension ? : $ this -> detectExtensionName ( ) ; $ attr = array_merge ( array ( 'type' => 'text/javascript' , 'defer' => false , 'async' => false ) , $ attributes ) ; $ asset = new Javascript ( $ extension , $ asset ) ; $ asset = $ this -> isSuperGroupAsset ( $ asset ) ; if ( $ asset -> exists ( ) ) { if ( $ asset -> isDeclaration ( ) ) { \ App :: get ( 'document' ) -> addScriptDeclaration ( $ asset -> contents ( ) ) ; } else { \ App :: get ( 'document' ) -> addScript ( $ asset -> link ( ) , $ attr [ 'type' ] , $ attr [ 'defer' ] , $ attr [ 'async' ] ) ; } } return $ this ; }
Push JS to the document
46,619
protected function isSuperGroupAsset ( $ asset ) { if ( $ asset -> extensionType ( ) != 'components' || $ asset -> isDeclaration ( ) || $ asset -> isExternal ( ) ) { return $ asset ; } if ( defined ( 'JPATH_GROUPCOMPONENT' ) ) { $ base = JPATH_GROUPCOMPONENT ; $ asset -> setPath ( 'source' , $ base . DS . 'assets' . DS . $ asset -> type ( ) . DS . $ asset -> file ( ) ) ; } return $ asset ; }
Modify paths if in a super group
46,620
protected function getInput ( ) { $ options = array ( ) ; $ attr = '' ; $ attr .= $ this -> element [ 'class' ] ? ' class="' . ( string ) $ this -> element [ 'class' ] . '"' : '' ; $ attr .= ( ( string ) $ this -> element [ 'disabled' ] == 'true' ) ? ' disabled="disabled"' : '' ; $ attr .= $ this -> element [ 'size' ] ? ' size="' . ( int ) $ this -> element [ 'size' ] . '"' : '' ; $ attr .= $ this -> multiple ? ' multiple="multiple"' : '' ; $ attr .= $ this -> element [ 'onchange' ] ? ' onchange="' . ( string ) $ this -> element [ 'onchange' ] . '"' : '' ; foreach ( $ this -> element -> children ( ) as $ option ) { if ( $ option -> getName ( ) != 'option' ) { continue ; } $ tmp = Dropdown :: option ( ( string ) $ option [ 'value' ] , trim ( ( string ) $ option ) , 'value' , 'text' , ( ( string ) $ option [ 'disabled' ] == 'true' ) ) ; $ tmp -> class = ( string ) $ option [ 'class' ] ; $ tmp -> onclick = ( string ) $ option [ 'onclick' ] ; $ options [ ] = $ tmp ; } return Access :: usergroup ( $ this -> name , $ this -> value , $ attr , $ options , $ this -> id ) ; }
Method to get the user group field input markup .
46,621
public function setUploadDir ( $ path ) { $ path = str_replace ( ' ' , '_' , trim ( $ path ) ) ; $ path = Util :: normalizePath ( $ path ) ; $ this -> uploadDir = ( $ path ? $ path : $ this -> uploadDir ) ; return $ this ; }
Set the upload path
46,622
public function automaticFilename ( $ data ) { $ filename = $ data [ 'filename' ] ; $ filename = preg_replace ( "/[^A-Za-z0-9.]/i" , '-' , $ filename ) ; $ ext = strrchr ( $ filename , '.' ) ; $ prefix = substr ( $ filename , 0 , - strlen ( $ ext ) ) ; if ( strlen ( $ prefix ) > 240 ) { $ prefix = substr ( $ prefix , 0 , 240 ) ; $ filename = $ prefix . $ ext ; } $ data [ 'filename' ] = $ filename ; return $ data [ 'filename' ] ; }
Ensure no invalid characters
46,623
public function uniqueFilename ( $ data ) { $ filename = $ this -> automaticFilename ( $ data ) ; if ( file_exists ( $ this -> getUploadDir ( ) . DS . $ data [ 'comment_id' ] . DS . $ filename ) ) { $ ext = strrchr ( $ filename , '.' ) ; $ prefix = substr ( $ filename , 0 , - strlen ( $ ext ) ) ; $ i = 1 ; while ( is_file ( $ this -> getUploadDir ( ) . DS . $ data [ 'comment_id' ] . DS . $ filename ) ) { $ filename = $ prefix . ++ $ i . $ ext ; } } $ data [ 'filename' ] = $ filename ; return $ data [ 'filename' ] ; }
Ensure no conflicting file names by renaming the incoming file if the name already exists
46,624
public function size ( ) { if ( $ this -> size === null ) { $ this -> size = 0 ; $ path = $ this -> path ( ) ; if ( file_exists ( $ path ) ) { $ this -> size = filesize ( $ path ) ; } } return $ this -> size ; }
Is the file an image?
46,625
public function dimensions ( ) { if ( ! $ this -> dimensions ) { $ this -> dimensions = array ( 0 , 0 ) ; if ( $ this -> isImage ( ) && file_exists ( $ this -> path ( ) ) ) { $ this -> dimensions = getimagesize ( $ this -> path ( ) ) ; } } return $ this -> dimensions ; }
File width and height
46,626
public function objectToString ( $ object , $ options = array ( ) ) { if ( is_string ( $ object ) ) { return $ object ; } return SymfonyYaml :: dump ( ( array ) $ this -> asArray ( $ object ) , 2 ) ; }
Converts an object into a YAML formatted string .
46,627
public function stringToObject ( $ data , $ options = array ( ) ) { if ( is_object ( $ data ) ) { return $ data ; } $ data = trim ( $ data ) ; try { $ parsed = SymfonyYaml :: parse ( $ data , true ) ; } catch ( Exception $ e ) { throw new ParseException ( array ( 'message' => 'Error parsing YAML' , 'exception' => $ e , ) ) ; } if ( ! $ parsed ) { $ parsed = '' ; } return ( is_string ( $ parsed ) ? $ parsed : $ this -> toObject ( $ parsed ) ) ; }
Parse a YAML formatted string and convert it into an object .
46,628
public function get ( $ property , $ default = null ) { if ( isset ( $ this -> metadata [ $ property ] ) ) { return $ this -> metadata [ $ property ] ; } return $ default ; }
Get a metadata language property .
46,629
public function setLanguage ( $ lang ) { $ this -> lang = $ lang ; $ this -> metadata = $ this -> getMetadata ( $ this -> lang ) ; return $ this ; }
Set the language attributes to the given language .
46,630
public function getLocale ( ) { if ( ! isset ( $ this -> locale ) ) { $ locale = str_replace ( ' ' , '' , isset ( $ this -> metadata [ 'locale' ] ) ? $ this -> metadata [ 'locale' ] : '' ) ; if ( $ locale ) { $ this -> locale = explode ( ',' , $ locale ) ; } else { $ this -> locale = false ; } } return $ this -> locale ; }
Get the language locale based on current language .
46,631
public function detect ( ) { if ( isset ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ) { $ browserLangs = explode ( ',' , $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ; $ systemLangs = $ this -> available ( ) ; foreach ( $ browserLangs as $ browserLang ) { $ browserLang = substr ( $ browserLang , 0 , strcspn ( $ browserLang , ';' ) ) ; $ primary_browserLang = substr ( $ browserLang , 0 , 2 ) ; foreach ( $ systemLangs as $ systemLang ) { $ Jinstall_lang = $ systemLang -> lang_code ; if ( strlen ( $ Jinstall_lang ) < 6 ) { if ( strtolower ( $ browserLang ) == strtolower ( substr ( $ systemLang -> lang_code , 0 , strlen ( $ browserLang ) ) ) ) { return $ systemLang -> lang_code ; } elseif ( $ primary_browserLang == substr ( $ systemLang -> lang_code , 0 , 2 ) ) { $ primaryDetectedLang = $ systemLang -> lang_code ; } } } if ( isset ( $ primaryDetectedLang ) ) { return $ primaryDetectedLang ; } } } return null ; }
Tries to detect the language .
46,632
public function available ( $ key = 'default' ) { static $ languages ; if ( empty ( $ languages ) ) { if ( \ App :: get ( 'client' ) -> id == 2 ) { $ languages [ $ key ] = array ( ) ; $ knownLangs = self :: getKnownLanguages ( PATH_APP . DS . 'bootstrap' . DS . $ this -> client ) ; foreach ( $ knownLangs as $ metadata ) { $ languages [ $ key ] [ ] = new Object ( array ( 'lang_code' => $ metadata [ 'tag' ] ) ) ; } } else { $ cache = \ App :: get ( 'cache.store' ) ; if ( ! $ languages = $ cache -> get ( 'com_languages.languages' ) ) { $ db = \ App :: get ( 'db' ) ; $ query = $ db -> getQuery ( ) -> select ( '*' ) -> from ( '#__languages' ) -> whereEquals ( 'published' , 1 ) -> order ( 'ordering' , 'asc' ) ; $ db -> setQuery ( $ query -> toString ( ) ) ; $ languages [ 'default' ] = $ db -> loadObjectList ( ) ; $ languages [ 'sef' ] = array ( ) ; $ languages [ 'lang_code' ] = array ( ) ; if ( isset ( $ languages [ 'default' ] [ 0 ] ) ) { foreach ( $ languages [ 'default' ] as $ lang ) { $ languages [ 'sef' ] [ $ lang -> sef ] = $ lang ; $ languages [ 'lang_code' ] [ $ lang -> lang_code ] = $ lang ; } } $ cache -> put ( 'com_languages.languages' , $ languages , \ App :: get ( 'config' ) -> get ( 'cachetime' , 15 ) ) ; } } } return $ languages [ $ key ] ; }
Get available languages
46,633
public function isMultilang ( ) { static $ tested = false ; static $ enabled = false ; if ( \ App :: isSite ( ) ) { return \ App :: get ( 'language.filter' ) ; } if ( ! $ tested ) { $ db = \ App :: get ( 'db' ) ; $ query = $ db -> getQuery ( ) -> select ( 'enabled' ) -> from ( '#__extensions' ) -> whereEquals ( 'type' , 'plugin' ) -> whereEquals ( 'folder' , 'system' ) -> whereEquals ( 'element' , 'languagefilter' ) ; $ db -> setQuery ( $ query -> toString ( ) ) ; $ enabled = $ db -> loadResult ( ) ; $ tested = true ; } return $ enabled ; }
Method to determine if the language filter plugin is enabled . This works for both site and administrator .
46,634
public function getConstrainedKeys ( $ constraint ) { $ this -> related -> select ( $ this -> relatedKey ) ; return $ this -> getConstrained ( $ constraint ) -> fieldsByKey ( $ this -> relatedKey ) ; }
Gets keys based on a given constraint
46,635
public function getConstrainedRows ( $ constraint ) { $ this -> related -> select ( $ this -> related -> getQualifiedFieldName ( '*' ) ) ; return $ this -> getConstrained ( $ constraint ) ; }
Gets rows based on given constraint
46,636
public function join ( ) { $ this -> model -> select ( $ this -> model -> getQualifiedFieldName ( '*' ) ) -> join ( $ this -> related -> getTableName ( ) , $ this -> model -> getQualifiedFieldName ( $ this -> localKey ) , $ this -> related -> getQualifiedFieldName ( $ this -> relatedKey ) , 'LEFT OUTER' ) ; return $ this ; }
Joins the related table together for the pending query
46,637
public function save ( $ data ) { $ related = $ this -> related ; $ model = $ related :: newFromResults ( $ data ) ; return $ this -> associate ( $ model ) -> save ( ) ; }
Saves a new related model with the given data
46,638
public function seedWithRelation ( $ rows , $ name , $ constraint = null , $ subs = null ) { if ( ! $ keys = $ rows -> fieldsByKey ( $ this -> localKey ) ) { return $ rows ; } $ relations = $ this -> getRelations ( $ keys , $ constraint ) ; if ( isset ( $ subs ) ) { $ relations -> including ( $ subs ) ; } $ resultsByRelatedKey = $ this -> getResultsByRelatedKey ( $ relations ) ; return $ this -> seed ( $ rows , $ resultsByRelatedKey , $ name ) ; }
Loads the relationship content and sets it on the related model
46,639
public function clear ( ) { $ confirm = 'no' ; if ( ! $ this -> output -> isInteractive ( ) && ! $ this -> arguments -> getOpt ( 'f' ) ) { $ this -> output -> addLine ( 'To forcibly clear all terms of use agreements for all users, please provide the -f flag. This action is irreversable.' , 'warning' ) ; return ; } else if ( ! $ this -> output -> isInteractive ( ) && $ this -> arguments -> getOpt ( 'f' ) ) { $ confirm = 'yes' ; } else if ( $ this -> output -> isInteractive ( ) ) { $ confirm = $ this -> output -> getResponse ( 'Are you sure you want to clear Terms of Use for all users? This will also require users to agree to new terms with next login? (yes/no)' ) ; } if ( strtolower ( $ confirm ) == 'yes' || strtolower ( $ confirm ) == 'y' ) { $ dbo = App :: get ( 'db' ) ; $ params = \ Component :: params ( 'com_members' ) ; $ currentTOU = $ params -> get ( 'registrationTOU' , 'RHRH' ) ; $ newTOU = substr_replace ( $ currentTOU , 'R' , 3 ) ; $ params -> set ( 'registrationTOU' , $ newTOU ) ; $ query = "UPDATE `#__extensions` SET `params`=" . $ dbo -> quote ( $ params -> toString ( ) ) . " WHERE `name`='com_members'" ; $ dbo -> setQuery ( $ query ) ; if ( ! $ dbo -> query ( ) ) { $ this -> output -> error ( 'Unable to set registration field TOU to required on next update.' ) ; } if ( $ dbo -> tableExists ( '#__users' ) && $ dbo -> tableHasField ( '#__users' , 'usageAgreement' ) ) { $ dbo -> setQuery ( "UPDATE `#__users` SET `usageAgreement`=0;" ) ; if ( ! $ dbo -> query ( ) ) { $ this -> output -> error ( 'Unable to clear users terms of use.' ) ; } } if ( $ dbo -> tableExists ( '#__xprofiles' ) && $ dbo -> tableHasField ( '#__xprofiles' , 'usageAgreement' ) ) { $ dbo -> setQuery ( "UPDATE `#__xprofiles` SET `usageAgreement`=0;" ) ; if ( ! $ dbo -> query ( ) ) { $ this -> output -> error ( 'Unable to clear xprofiles terms of use.' ) ; } } $ this -> output -> addLine ( 'Terms of Use successfully cleared & registration param updated!' , 'success' ) ; } else { $ this -> output -> addLine ( 'Operation aborted.' ) ; } }
Clear terms of use agreements
46,640
public function getMimetype ( ) { if ( ! isset ( $ this -> mimetype ) ) { $ this -> mimetype = $ this -> hasAdapterOrFail ( ) -> adapter -> getMimetype ( $ this -> getPath ( ) ) ; } return $ this -> mimetype ; }
Gets the file mimetype
46,641
public function getSize ( $ raw = false ) { if ( ! isset ( $ this -> size ) ) { $ this -> size = $ this -> hasAdapterOrFail ( ) -> adapter -> getSize ( $ this -> getPath ( ) ) ; } return ( $ raw ) ? $ this -> size : \ Hubzero \ Utility \ Number :: formatBytes ( $ this -> size ) ; }
Grabs the item size
46,642
public function getExtension ( ) { if ( ! isset ( $ this -> extension ) ) { $ bits = explode ( '.' , $ this -> getName ( ) ) ; if ( count ( $ bits ) > 1 ) { $ this -> extension = end ( $ bits ) ; } else { $ this -> extension = '' ; } } return $ this -> extension ; }
Grabs the entity extension
46,643
public function getFilename ( ) { $ filename = $ this -> getDisplayName ( ) ; if ( $ this -> getExtension ( ) != '' ) { $ filename .= '.' . $ this -> getExtension ( ) ; } return $ filename ; }
Grabs the name of a file with its extension
46,644
public function save ( $ scan = true ) { if ( ! isset ( $ this -> contents ) ) { return false ; } $ method = ( is_resource ( $ this -> contents ) && get_resource_type ( $ this -> contents ) == 'stream' ) ? 'putStream' : 'put' ; if ( ! $ this -> $ method ( $ this -> contents ) ) { return false ; } if ( $ scan && ! $ this -> isSafe ( ) ) { $ this -> delete ( ) ; return false ; } return true ; }
Saves the file contents that are already set on the object
46,645
public function serve ( $ as = null ) { $ server = new \ Hubzero \ Content \ Server ( ) ; $ server -> disposition ( 'attachment' ) ; $ server -> acceptranges ( false ) ; if ( ! $ this -> isLocal ( ) ) { $ temp = tmpfile ( ) ; fwrite ( $ temp , $ this -> read ( ) ) ; $ server -> filename ( stream_get_meta_data ( $ temp ) [ 'uri' ] ) ; } else { $ server -> filename ( $ this -> getAbsolutePath ( ) ) ; } $ server -> saveas ( $ as ? : $ this -> getFileName ( ) ) ; $ result = $ server -> serve ( ) ; if ( isset ( $ temp ) && is_resource ( $ temp ) ) { fclose ( $ temp ) ; } return $ result ; }
Serves up the file to the web
46,646
public static function timingSafeCompare ( $ known , $ unknown ) { $ known .= chr ( 0 ) ; $ unknown .= chr ( 0 ) ; $ knownLength = strlen ( $ known ) ; $ unknownLength = strlen ( $ unknown ) ; $ result = $ knownLength - $ unknownLength ; for ( $ i = 0 ; $ i < $ unknownLength ; $ i ++ ) { $ result |= ( ord ( $ known [ $ i % $ knownLength ] ) ^ ord ( $ unknown [ $ i ] ) ) ; } return $ result === 0 ; }
A timing safe comparison method . This defeats hacking attempts that use timing based attack vectors .
46,647
public static function valid ( $ str ) { $ mState = 0 ; $ mUcs4 = 0 ; $ mBytes = 1 ; $ len = strlen ( $ str ) ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ in = ord ( $ str { $ i } ) ; if ( $ mState == 0 ) { if ( 0 == ( 0x80 & ( $ in ) ) ) { $ mBytes = 1 ; } elseif ( 0xC0 == ( 0xE0 & ( $ in ) ) ) { $ mUcs4 = ( $ in ) ; $ mUcs4 = ( $ mUcs4 & 0x1F ) << 6 ; $ mState = 1 ; $ mBytes = 2 ; } elseif ( 0xE0 == ( 0xF0 & ( $ in ) ) ) { $ mUcs4 = ( $ in ) ; $ mUcs4 = ( $ mUcs4 & 0x0F ) << 12 ; $ mState = 2 ; $ mBytes = 3 ; } elseif ( 0xF0 == ( 0xF8 & ( $ in ) ) ) { $ mUcs4 = ( $ in ) ; $ mUcs4 = ( $ mUcs4 & 0x07 ) << 18 ; $ mState = 3 ; $ mBytes = 4 ; } elseif ( 0xF8 == ( 0xFC & ( $ in ) ) ) { $ mUcs4 = ( $ in ) ; $ mUcs4 = ( $ mUcs4 & 0x03 ) << 24 ; $ mState = 4 ; $ mBytes = 5 ; } elseif ( 0xFC == ( 0xFE & ( $ in ) ) ) { $ mUcs4 = ( $ in ) ; $ mUcs4 = ( $ mUcs4 & 1 ) << 30 ; $ mState = 5 ; $ mBytes = 6 ; } else { return false ; } } else { if ( 0x80 == ( 0xC0 & ( $ in ) ) ) { $ shift = ( $ mState - 1 ) * 6 ; $ tmp = $ in ; $ tmp = ( $ tmp & 0x0000003F ) << $ shift ; $ mUcs4 |= $ tmp ; if ( 0 == -- $ mState ) { if ( ( ( 2 == $ mBytes ) && ( $ mUcs4 < 0x0080 ) ) || ( ( 3 == $ mBytes ) && ( $ mUcs4 < 0x0800 ) ) || ( ( 4 == $ mBytes ) && ( $ mUcs4 < 0x10000 ) ) || ( 4 < $ mBytes ) || ( ( $ mUcs4 & 0xFFFFF800 ) == 0xD800 ) || ( $ mUcs4 > 0x10FFFF ) ) { return false ; } $ mState = 0 ; $ mUcs4 = 0 ; $ mBytes = 1 ; } } else { return false ; } } } return true ; }
Tests a string as to whether it s valid UTF - 8 and supported by the Unicode standard .
46,648
public function clear ( ) { $ cvars = get_class_vars ( __CLASS__ ) ; $ this -> _updatedkeys = array ( ) ; foreach ( $ cvars as $ key => $ value ) { if ( $ key { 0 } != '_' ) { unset ( $ this -> $ key ) ; $ this -> $ key = null ; } } $ this -> _updatedkeys = array ( ) ; }
Clear internal data
46,649
public static function isPasswordExpired ( $ user = null ) { $ hzup = self :: getInstance ( $ user ) ; if ( ! is_object ( $ hzup ) ) { return false ; } if ( empty ( $ hzup -> shadowLastChange ) ) { return false ; } if ( $ hzup -> shadowMax === '0' ) { return true ; } if ( empty ( $ hzup -> shadowMax ) ) { return false ; } $ chgtime = time ( ) ; $ chgtime = intval ( $ chgtime / 86400 ) ; if ( ( $ hzup -> shadowLastChange + $ hzup -> shadowMax ) >= $ chgtime ) { return false ; } return true ; }
Check if a password is expired
46,650
public static function getPasshash ( $ password ) { $ config = \ Component :: params ( 'com_members' ) ; $ type = $ config -> get ( 'passhash_mechanism' , 'CRYPT_SHA512' ) ; switch ( $ type ) { case 'MD5' : $ passhash = "{MD5}" . base64_encode ( pack ( 'H*' , md5 ( $ password ) ) ) ; break ; case 'CRYPT_SHA512' : default : $ encrypted = crypt ( $ password , '$6$' . self :: genRandomPassword ( 8 ) . '$' ) ; $ passhash = "{CRYPT}" . $ encrypted ; break ; } return $ passhash ; }
Get a hash of a password
46,651
public static function changePasshash ( $ user = null , $ passhash ) { $ config = \ Component :: params ( 'com_members' ) ; $ shadowMin = $ config -> get ( 'shadowMin' , '0' ) ; $ shadowMax = $ config -> get ( 'shadowMax' , null ) ; $ shadowWarning = $ config -> get ( 'shadowWarning' , '7' ) ; $ shadowMax = ( $ shadowMax == '' ) ? null : $ shadowMax ; $ hzup = self :: getInstance ( $ user ) ; if ( ! $ hzup ) { return false ; } $ oldhash = $ hzup -> __get ( 'passhash' ) ; $ hzup -> __set ( 'passhash' , $ passhash ) ; $ hzup -> __set ( 'shadowFlag' , null ) ; $ hzup -> __set ( 'shadowLastChange' , intval ( time ( ) / 86400 ) ) ; $ hzup -> __set ( 'shadowMin' , $ shadowMin ) ; $ hzup -> __set ( 'shadowMax' , $ shadowMax ) ; $ hzup -> __set ( 'shadowWarning' , $ shadowWarning ) ; $ hzup -> __set ( 'shadowInactive' , '0' ) ; $ hzup -> __set ( 'shadowExpire' , null ) ; $ hzup -> update ( ) ; $ db = \ App :: get ( 'db' ) ; $ db -> setQuery ( "UPDATE `#__xprofiles` SET userPassword=" . $ db -> quote ( $ passhash ) . " WHERE uidNumber=" . $ db -> quote ( $ hzup -> get ( 'user_id' ) ) ) ; $ db -> query ( ) ; $ db -> setQuery ( "UPDATE `#__users` SET password=" . $ db -> quote ( $ passhash ) . " WHERE id=" . $ db -> quote ( $ hzup -> get ( 'user_id' ) ) ) ; $ db -> query ( ) ; if ( ! empty ( $ oldhash ) ) { History :: addPassword ( $ oldhash , $ user ) ; } return true ; }
Change a user s pass hash
46,652
public static function getSalt ( $ encryption = 'md5-hex' , $ seed = '' , $ plaintext = '' ) { switch ( $ encryption ) { case 'crypt' : case 'crypt-des' : if ( $ seed ) { return substr ( preg_replace ( '|^{crypt}|i' , '' , $ seed ) , 0 , 2 ) ; } else { return substr ( md5 ( mt_rand ( ) ) , 0 , 2 ) ; } break ; case 'crypt-md5' : if ( $ seed ) { return substr ( preg_replace ( '|^{crypt}|i' , '' , $ seed ) , 0 , 12 ) ; } else { return '$1$' . substr ( md5 ( mt_rand ( ) ) , 0 , 8 ) . '$' ; } break ; case 'crypt-blowfish' : if ( $ seed ) { return substr ( preg_replace ( '|^{crypt}|i' , '' , $ seed ) , 0 , 16 ) ; } else { return '$2$' . substr ( md5 ( mt_rand ( ) ) , 0 , 12 ) . '$' ; } break ; case 'crypt-sha512' : if ( $ seed ) { return substr ( preg_replace ( '|^{crypt}|i' , '' , $ seed ) , 0 , 12 ) ; } else { return '$6$' . substr ( md5 ( mt_rand ( ) ) , 0 , 8 ) . '$' ; } break ; case 'ssha' : if ( $ seed ) { return substr ( preg_replace ( '|^{SSHA}|' , '' , $ seed ) , - 20 ) ; } else { return mhash_keygen_s2k ( MHASH_SHA1 , $ plaintext , substr ( pack ( 'h*' , md5 ( mt_rand ( ) ) ) , 0 , 8 ) , 4 ) ; } break ; case 'smd5' : if ( $ seed ) { return substr ( preg_replace ( '|^{SMD5}|' , '' , $ seed ) , - 16 ) ; } else { return mhash_keygen_s2k ( MHASH_MD5 , $ plaintext , substr ( pack ( 'h*' , md5 ( mt_rand ( ) ) ) , 0 , 8 ) , 4 ) ; } break ; case 'aprmd5' : $ APRMD5 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' ; if ( $ seed ) { return substr ( preg_replace ( '/^\$apr1\$(.{8}).*/' , '\\1' , $ seed ) , 0 , 8 ) ; } else { $ salt = '' ; for ( $ i = 0 ; $ i < 8 ; $ i ++ ) { $ salt .= $ APRMD5 { rand ( 0 , 63 ) } ; } return $ salt ; } break ; default : $ salt = '' ; if ( $ seed ) { $ salt = $ seed ; } return $ salt ; break ; } }
Returns a salt for the appropriate kind of password encryption . Optionally takes a seed and a plaintext password to extract the seed of an existing password or for encryption types that use the plaintext in the generation of the salt .
46,653
protected static function _toAPRMD5 ( $ value , $ count ) { $ APRMD5 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' ; $ aprmd5 = '' ; $ count = abs ( $ count ) ; while ( -- $ count ) { $ aprmd5 .= $ APRMD5 [ $ value & 0x3f ] ; $ value >>= 6 ; } return $ aprmd5 ; }
Converts to allowed 64 characters for APRMD5 passwords .
46,654
protected static function _bin ( $ hex ) { $ bin = '' ; $ length = strlen ( $ hex ) ; for ( $ i = 0 ; $ i < $ length ; $ i += 2 ) { $ tmp = sscanf ( substr ( $ hex , $ i , 2 ) , '%x' ) ; $ bin .= chr ( array_shift ( $ tmp ) ) ; } return $ bin ; }
Converts hexadecimal string to binary data .
46,655
public static function passwordMatches ( $ user = null , $ password , $ alltables = false ) { $ passhash = null ; $ hzup = self :: getInstance ( $ user ) ; if ( is_object ( $ hzup ) && ! empty ( $ hzup -> passhash ) ) { $ passhash = $ hzup -> passhash ; } else if ( $ alltables ) { $ profile = Profile :: getInstance ( $ user ) ; if ( is_object ( $ profile ) && ( $ profile -> get ( 'userPassword' ) != '' ) ) { $ passhash = $ profile -> get ( 'userPassword' ) ; } else { $ user = \ User :: getInstance ( $ user ) ; if ( is_object ( $ user ) && ! empty ( $ user -> password ) ) { $ passhash = $ user -> password ; } } } return self :: comparePasswords ( $ passhash , $ password ) ; }
Check if a password matches
46,656
public static function invalidatePassword ( $ user = null ) { $ hzup = self :: getInstance ( $ user ) ; $ hzup -> __set ( 'shadowFlag' , '-1' ) ; $ hzup -> update ( ) ; return true ; }
Invalidate a user s password
46,657
public static function currentOrFailByDomain ( $ domain ) { $ factor = static :: all ( ) -> whereEquals ( 'user_id' , User :: get ( 'id' ) ) -> whereEquals ( 'domain' , $ domain ) -> row ( ) ; return ( $ factor -> isNew ( ) ) ? false : $ factor ; }
Gets one result or fails by domain and user_id
46,658
public static function getInstance ( $ userAgent = null , $ accept = null ) { $ signature = serialize ( array ( $ userAgent , $ accept ) ) ; if ( empty ( self :: $ instances [ $ signature ] ) ) { self :: $ instances [ $ signature ] = new self ( $ userAgent , $ accept ) ; } return self :: $ instances [ $ signature ] ; }
Returns the global Browser object only creating it if it doesn t already exist .
46,659
public function match ( $ userAgent = null , $ accept = null ) { if ( is_null ( $ userAgent ) ) { if ( isset ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ) { $ this -> agent = trim ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ; } } else { $ this -> agent = $ userAgent ; } $ this -> lowerAgent = strtolower ( $ this -> agent ) ; if ( is_null ( $ accept ) ) { if ( isset ( $ _SERVER [ 'HTTP_ACCEPT' ] ) ) { $ this -> accept = strtolower ( trim ( $ _SERVER [ 'HTTP_ACCEPT' ] ) ) ; } } else { $ this -> accept = strtolower ( $ accept ) ; } if ( ! empty ( $ this -> agent ) ) { $ this -> _setPlatform ( ) ; foreach ( $ this -> regexes as $ regex ) { if ( preg_match ( $ regex [ 'regex' ] , $ this -> agent , $ version ) ) { $ this -> browser = strtolower ( $ regex [ 'name' ] ) ; $ this -> platform = ( $ regex [ 'platform' ] ? $ regex [ 'platform' ] : $ this -> platform ) ; if ( ! $ this -> mobile ) { $ this -> mobile = $ regex [ 'mobile' ] ; } if ( isset ( $ regex [ 'version' ] ) ) { if ( preg_match ( $ regex [ 'version' ] , $ this -> agent , $ ver ) ) { $ version = $ ver ; } } if ( ! empty ( $ version ) && isset ( $ version [ 1 ] ) ) { $ bits = explode ( '.' , $ version [ 1 ] ) ; $ this -> majorVersion = $ bits [ 0 ] ; $ this -> minorVersion = ( isset ( $ bits [ 1 ] ) ? $ bits [ 1 ] : 0 ) ; } break ; } } } }
Parses the user agent string and inititializes the object with all the known features and quirks for the given browser .
46,660
public function version ( $ for = '' ) { switch ( strtolower ( $ for ) ) { case 'major' : return $ this -> major ( ) ; break ; case 'minor' : return $ this -> minor ( ) ; break ; case 'platform' : return $ this -> platformVersion ( ) ; break ; default : return $ this -> majorVersion . '.' . $ this -> minorVersion ; break ; } }
Retrieve the current browser s version .
46,661
public function isViewable ( $ mimetype ) { $ mimetype = strtolower ( $ mimetype ) ; list ( $ type , $ subtype ) = explode ( '/' , $ mimetype ) ; if ( ! empty ( $ this -> accept ) ) { $ wildcard_match = false ; if ( strpos ( $ this -> accept , $ mimetype ) !== false ) { return true ; } if ( strpos ( $ this -> accept , '*/*' ) !== false ) { $ wildcard_match = true ; if ( $ type != 'image' ) { return true ; } } if ( $ this -> isBrowser ( 'mozilla' ) && ( $ mimetype == 'image/pjpeg' ) && ( strpos ( $ this -> accept , 'image/jpeg' ) !== false ) ) { return true ; } if ( ! $ wildcard_match ) { return false ; } } if ( ! $ this -> hasFeature ( 'images' ) || ( $ type != 'image' ) ) { return false ; } return ( in_array ( $ subtype , $ this -> images ) ) ; }
Determines if a browser can display a given MIME type .
46,662
public function def ( $ property , $ default = null ) { $ value = $ this -> get ( $ property , $ default ) ; return $ this -> set ( $ property , $ value ) ; }
Sets a default value if not alreay assigned
46,663
public function unserialize ( $ data ) { $ this -> __construct ( ) ; $ data = unserialize ( $ data ) ; if ( isset ( $ data [ 'guest' ] ) ) { $ this -> guest = $ data [ 'guest' ] ; unset ( $ data [ 'guest' ] ) ; } $ this -> set ( $ data ) ; }
Unserializes the data into a new model
46,664
public function get ( $ key , $ default = null ) { if ( $ key == 'guest' ) { return $ this -> isGuest ( ) ; } if ( $ key == 'uidNumber' ) { $ key = 'id' ; } if ( ( $ key == 'givenName' || $ key == 'middleName' || $ key == 'surname' ) && parent :: get ( $ key , null ) == null ) { return $ this -> parseName ( $ key ) ; } if ( $ key == 'id' && is_null ( $ default ) ) { $ default = 0 ; } return parent :: get ( $ key , $ default ) ; }
Gets an attribute by key
46,665
public function transformParams ( ) { if ( ! isset ( $ this -> userParams ) ) { $ this -> userParams = new Registry ( $ this -> get ( 'params' ) ) ; } return $ this -> userParams ; }
Transform parameters into object
46,666
public static function oneByEmail ( $ email ) { if ( ! filter_var ( $ email , FILTER_VALIDATE_EMAIL ) ) { return self :: oneByUsername ( $ email ) ; } return self :: all ( ) -> whereEquals ( 'email' , $ email ) -> row ( ) ; }
Finds a user by email
46,667
public function setLastVisit ( $ timestamp = 'now' ) { $ timestamp = new Date ( $ timestamp ) ; $ query = $ this -> getQuery ( ) -> update ( $ this -> getTableName ( ) ) -> set ( array ( 'lastvisitDate' => $ timestamp -> toSql ( ) ) ) -> whereEquals ( 'id' , $ this -> get ( 'id' ) ) ; return $ query -> execute ( ) ; }
Pass through method to the table for setting the last visit date
46,668
public function authorise ( $ action , $ assetname = null ) { if ( $ this -> isRoot === null ) { $ this -> isRoot = false ; $ rootUser = \ App :: get ( 'config' ) -> get ( 'root_user' ) ; if ( is_numeric ( $ rootUser ) && $ this -> get ( 'id' ) > 0 && $ this -> get ( 'id' ) == $ rootUser ) { $ this -> isRoot = true ; } elseif ( $ this -> username && $ this -> username == $ rootUser ) { $ this -> isRoot = true ; } else { $ identities = $ this -> getAuthorisedGroups ( ) ; array_unshift ( $ identities , $ this -> get ( 'id' ) * - 1 ) ; if ( Access :: getAssetRules ( 1 ) -> allow ( 'core.admin' , $ identities ) ) { $ this -> isRoot = true ; return true ; } } } return $ this -> isRoot ? true : Access :: check ( $ this -> get ( 'id' ) , $ action , $ assetname ) ; }
Method to check User object authorisation against an access control object and optionally an access extension object
46,669
public function getAuthorisedCategories ( $ component , $ action ) { $ db = \ App :: get ( 'db' ) ; $ query = $ db -> getQuery ( ) -> select ( 'c.id' , 'id' ) -> select ( 'a.name' , 'asset_name' ) -> from ( '#__categories' , 'c' ) -> join ( '#__assets AS a' , 'c.asset_id' , 'a.id' , 'inner' ) -> whereEquals ( 'c.extension' , $ component ) -> whereEquals ( 'c.published' , '1' ) ; $ db -> setQuery ( $ query -> toString ( ) ) ; $ allCategories = $ db -> loadObjectList ( 'id' ) ; $ allowedCategories = array ( ) ; foreach ( $ allCategories as $ category ) { if ( $ this -> authorise ( $ action , $ category -> asset_name ) ) { $ allowedCategories [ ] = ( int ) $ category -> id ; } } return $ allowedCategories ; }
Method to return a list of all categories that a user has permission for a given action
46,670
public function getAuthorisedViewLevels ( ) { if ( is_null ( $ this -> authLevels ) ) { $ this -> authLevels = array ( ) ; } if ( empty ( $ this -> _authLevels ) ) { $ this -> authLevels = Access :: getAuthorisedViewLevels ( $ this -> get ( 'id' ) ) ; } return $ this -> authLevels ; }
Gets an array of the authorised access levels for the user
46,671
public function getAuthorisedGroups ( ) { if ( is_null ( $ this -> authGroups ) ) { $ this -> authGroups = array ( ) ; } if ( empty ( $ this -> authGroups ) ) { $ this -> authGroups = Access :: getGroupsByUser ( $ this -> get ( 'id' ) ) ; } return $ this -> authGroups ; }
Gets an array of the authorised user groups
46,672
public function destroy ( ) { $ data = $ this -> toArray ( ) ; Event :: trigger ( 'user.onUserBeforeDelete' , array ( $ data ) ) ; if ( $ this -> reputation -> get ( 'id' ) ) { if ( ! $ this -> reputation -> destroy ( ) ) { $ this -> addError ( $ this -> reputation -> getError ( ) ) ; return false ; } } foreach ( $ this -> tokens ( ) -> rows ( ) as $ token ) { if ( ! $ token -> destroy ( ) ) { $ this -> addError ( $ token -> getError ( ) ) ; return false ; } } Map :: destroyByUser ( $ this -> get ( 'id' ) ) ; $ result = parent :: destroy ( ) ; if ( $ result ) { Event :: trigger ( 'user.onUserAfterDelete' , array ( $ data , true , $ this -> getError ( ) ) ) ; } return $ result ; }
Delete the record and associated data
46,673
private function parseName ( $ key = null ) { $ name = $ this -> get ( 'name' ) ; if ( $ name ) { $ firstname = "" ; $ middlename = "" ; $ lastname = "" ; $ words = array_map ( 'trim' , explode ( ' ' , $ this -> get ( 'name' ) ) ) ; $ count = count ( $ words ) ; if ( $ count == 1 ) { $ firstname = $ words [ 0 ] ; } else if ( $ count == 2 ) { $ firstname = $ words [ 0 ] ; $ lastname = $ words [ 1 ] ; } else if ( $ count == 3 ) { $ firstname = $ words [ 0 ] ; $ middlename = $ words [ 1 ] ; $ lastname = $ words [ 2 ] ; } else { $ firstname = $ words [ 0 ] ; $ lastname = $ words [ $ count - 1 ] ; $ middlename = $ words [ 1 ] ; for ( $ i = 2 ; $ i < $ count - 1 ; $ i ++ ) { $ middlename .= ' ' . $ words [ $ i ] ; } } switch ( $ key ) { case 'givenName' : return trim ( $ firstname ) ; break ; case 'middleName' : return trim ( $ middlename ) ; break ; case 'surname' : return trim ( $ lastname ) ; break ; default : return '' ; } } }
Parse a users name and set the name parts on the instance
46,674
public function read ( $ session_id ) { $ session = $ this -> database -> hgetall ( $ this -> key ( $ session_id ) ) ; return ( isset ( $ session [ 'data' ] ) ) ? $ session [ 'data' ] : null ; }
Read session hash for Id
46,675
public function destroy ( $ session_id ) { if ( ! $ this -> database -> del ( $ this -> key ( $ session_id ) ) ) { return false ; } return true ; }
Delete session hash
46,676
public static function prepare ( $ text , $ params = null , $ context = 'text' ) { if ( $ params === null ) { $ params = new Obj ; } $ article = new \ stdClass ; $ article -> text = $ text ; \ App :: get ( 'dispatcher' ) -> trigger ( 'content.onContentPrepare' , array ( $ context , & $ article , & $ params , 0 ) ) ; return $ article -> text ; }
Fire onContentPrepare for content that isn t part of an article .
46,677
public function addString ( $ message , $ styles = null ) { $ this -> addLine ( $ message , $ styles , false ) ; return $ this ; }
Add a new string to the output buffer
46,678
public function addParagraph ( $ paragraph , $ styles = array ( ) ) { $ paragraph = str_replace ( "\n" , " " , $ paragraph ) ; $ paragraph = str_replace ( " " , " " , $ paragraph ) ; $ paragraph = str_replace ( "\t" , "" , $ paragraph ) ; do { if ( strlen ( $ paragraph ) > 70 && $ break = strpos ( $ paragraph , " " , 70 ) ) { $ message = substr ( $ paragraph , 0 , $ break ) ; $ paragraph = trim ( substr ( $ paragraph , $ break ) ) ; } else { $ message = trim ( $ paragraph ) ; $ break = false ; } $ this -> addLine ( $ message , $ styles ) ; } while ( $ break !== false ) ; return $ this ; }
Add a paragraph to the output buffer . This will chop the text up to maintain lines of approximately 80 characters .
46,679
public function addTable ( $ rows , $ headers = false ) { $ maxLengths = [ ] ; foreach ( $ rows as $ i => $ row ) { foreach ( $ row as $ k => $ field ) { $ maxLengths [ $ k ] = isset ( $ maxLengths [ $ k ] ) ? $ maxLengths [ $ k ] : 0 ; $ maxLengths [ $ k ] = strlen ( $ field ) > $ maxLengths [ $ k ] ? strlen ( $ field ) : $ maxLengths [ $ k ] ; } } $ width = array_sum ( $ maxLengths ) + ( ( count ( $ row ) - 1 ) * 3 ) + 2 ; $ this -> addLine ( '/' . str_repeat ( '-' , ( $ width ) ) . '\\' ) ; foreach ( $ rows as $ i => $ row ) { $ styles = ( $ i == 0 && $ headers ) ? [ 'format' => 'underline' ] : null ; foreach ( $ row as $ k => $ field ) { $ padding = $ maxLengths [ $ k ] - strlen ( $ field ) ; $ this -> addString ( '| ' ) ; $ this -> addString ( $ field , $ styles ) ; $ this -> addString ( ' ' . str_repeat ( ' ' , $ padding ) ) ; } $ this -> addLine ( '|' ) ; } $ this -> addLine ( '\\' . str_repeat ( '-' , ( $ width ) ) . '/' ) ; }
Renders rows in a table - like structure
46,680
public function addRaw ( $ text ) { $ this -> response [ ] = array ( 'message' => $ text ) ; if ( $ this -> isInteractive ( ) ) { $ this -> render ( true ) ; } }
Add raw text to output buffer
46,681
public function addLinesFromArray ( $ lines ) { foreach ( $ lines as $ line ) { $ this -> addLine ( $ line [ 'message' ] , ( ( isset ( $ line [ 'type' ] ) ) ? $ line [ 'type' ] : null ) ) ; } }
Helper method to add an array of lines to the output buffer .
46,682
public function addRawFromAssocArray ( $ lines , $ indentation = 0 ) { foreach ( $ lines as $ key => $ value ) { if ( is_array ( $ value ) ) { $ this -> addLine ( $ key . ': [' , array ( "indentation" => $ indentation ) ) ; $ this -> addRawFromAssocArray ( $ value , $ indentation + 1 ) ; $ this -> addLine ( ']' , array ( "indentation" => $ indentation ) ) ; } else { $ this -> addLine ( $ key . ': ' . $ value , array ( "indentation" => $ indentation ) ) ; } } }
Helper method to add an associative array to the output buffer .
46,683
public function getResponse ( $ prompt ) { $ prompt = trim ( $ prompt ) ; $ this -> addString ( "{$prompt} " ) ; $ response = fgets ( STDIN ) ; $ response = trim ( $ response ) ; return $ response ; }
Get response from the user
46,684
public function setDefaultIndentation ( $ indentation ) { $ ind = '' ; for ( $ i = 0 ; $ i < ( int ) $ indentation ; $ i ++ ) { $ ind .= ' ' ; } $ this -> defaultIndentation = $ ind ; }
Set the default indentation . This will be used unless an indentation is explicitly given while adding a line .
46,685
private function formatLine ( & $ message , $ styles ) { $ style = array ( 'format' => '0' , 'color' => '' , 'indentation' => $ this -> defaultIndentation ) ; if ( is_array ( $ styles ) && count ( $ styles ) > 0 ) { foreach ( $ styles as $ k => $ v ) { switch ( $ k ) { case 'color' : $ style [ 'color' ] = $ this -> translateColor ( $ v ) ; break ; case 'format' : $ style [ 'format' ] = $ this -> translateFormat ( $ v ) ; break ; case 'indentation' : $ style [ 'indentation' ] = '' ; for ( $ i = 0 ; $ i < $ v ; $ i ++ ) { $ style [ 'indentation' ] .= ' ' ; } break ; } } } elseif ( is_string ( $ styles ) ) { switch ( $ styles ) { case 'warning' : $ style [ 'color' ] = '43' ; break ; case 'error' : $ style [ 'format' ] = '1' ; $ style [ 'color' ] = '41' ; break ; case 'info' : $ style [ 'color' ] = $ this -> translateColor ( 'blue' ) ; break ; case 'success' : $ style [ 'color' ] = $ this -> translateColor ( 'green' ) ; break ; } } if ( ! Config :: get ( 'color' , $ this -> colored ) ) { $ message = $ style [ 'indentation' ] . $ message ; } else { $ messageStyles = $ style [ 'format' ] ; $ messageStyles .= ( $ style [ 'color' ] ) ? ';' . $ style [ 'color' ] : '' ; $ message = chr ( 27 ) . "[" . $ messageStyles . "m" . $ style [ 'indentation' ] . $ message . chr ( 27 ) . "[0m" ; } }
Take line of text and styles and give back a formatted line .
46,686
public function isEnabled ( $ option , $ strict = false ) { $ result = $ this -> load ( $ option , $ strict ) ; return ( $ result -> enabled == 1 ) ; }
Checks if the component is enabled
46,687
public function path ( $ option ) { $ result = $ this -> load ( $ option ) ; if ( ! isset ( $ result -> path ) ) { $ result -> path = '' ; $ paths = array ( PATH_APP . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . substr ( $ result -> option , 4 ) , PATH_APP . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . $ result -> option , PATH_CORE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . substr ( $ result -> option , 4 ) , PATH_CORE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . $ result -> option ) ; foreach ( $ paths as $ path ) { if ( is_dir ( $ path ) ) { $ result -> path = $ path ; break ; } } } return $ result -> path ; }
Get the base path to a component
46,688
public function canonical ( $ option ) { if ( is_array ( $ option ) ) { $ option = implode ( '' , $ option ) ; } $ option = preg_replace ( '/[^A-Z0-9_\.-]/i' , '' , $ option ) ; if ( substr ( $ option , 0 , strlen ( 'com_' ) ) != 'com_' ) { $ option = 'com_' . $ option ; } return $ option ; }
Make sure component name follows naming conventions
46,689
protected function execute ( $ path ) { ob_start ( ) ; if ( file_exists ( $ path ) ) { $ this -> executePath ( $ path ) ; } else { $ this -> executeBootstrap ( $ path ) ; } $ contents = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ contents ; }
Execute the component .
46,690
public function router ( $ option , $ client = null , $ version = null ) { $ option = $ this -> canonical ( $ option ) ; $ client = ( $ client ? $ client : $ this -> app [ 'client' ] -> alias ) ; $ key = $ option . $ client ; if ( ! isset ( self :: $ routers [ $ key ] ) ) { $ compname = ucfirst ( substr ( $ option , 4 ) ) ; $ client = ucfirst ( $ client ) ; $ legacy = $ compname . 'Router' ; $ name = '\\Components\\' . $ compname . '\\' . $ client . '\\Router' ; if ( ! class_exists ( $ name ) && ! class_exists ( $ legacy ) ) { $ paths = array ( ) ; if ( ! is_null ( $ version ) ) { $ paths [ ] = $ this -> path ( $ option ) . DIRECTORY_SEPARATOR . strtolower ( $ client ) . DIRECTORY_SEPARATOR . 'routerv' . $ version . '.php' ; } $ paths [ ] = $ this -> path ( $ option ) . DIRECTORY_SEPARATOR . strtolower ( $ client ) . DIRECTORY_SEPARATOR . 'router.php' ; $ paths [ ] = $ this -> path ( $ option ) . DIRECTORY_SEPARATOR . 'router.php' ; foreach ( $ paths as $ path ) { if ( file_exists ( $ path ) ) { require_once $ path ; break ; } } } if ( class_exists ( $ name ) ) { $ reflection = new ReflectionClass ( $ name ) ; if ( in_array ( 'Hubzero\\Component\\Router\\RouterInterface' , $ reflection -> getInterfaceNames ( ) ) ) { self :: $ routers [ $ key ] = new $ name ; } } else if ( class_exists ( $ legacy ) ) { $ reflection = new ReflectionClass ( $ legacy ) ; if ( in_array ( 'Hubzero\\Component\\Router\\RouterInterface' , $ reflection -> getInterfaceNames ( ) ) ) { self :: $ routers [ $ key ] = new $ legacy ; } } if ( ! isset ( self :: $ routers [ $ key ] ) ) { self :: $ routers [ $ key ] = new Legacy ( $ compname ) ; } } return self :: $ routers [ $ key ] ; }
Get component router
46,691
public function load ( $ option , $ strict = false ) { $ option = $ this -> canonical ( $ option ) ; if ( isset ( self :: $ components [ $ option ] ) ) { return self :: $ components [ $ option ] ; } if ( $ this -> app -> has ( 'db' ) ) { $ db = $ this -> app -> get ( 'db' ) ; $ query = $ db -> getQuery ( ) -> select ( 'extension_id' , 'id' ) -> select ( 'element' , '"option"' ) -> select ( 'params' ) -> select ( 'enabled' ) -> from ( '#__extensions' ) -> whereEquals ( 'type' , 'component' ) -> whereEquals ( 'element' , $ option ) ; $ db -> setQuery ( $ query -> toString ( ) ) ; if ( ! $ this -> app -> has ( 'cache.store' ) || ! ( $ cache = $ this -> app [ 'cache.store' ] ) ) { $ cache = new \ Hubzero \ Cache \ Storage \ None ( ) ; } if ( ! ( $ data = $ cache -> get ( '_system.' . $ option ) ) ) { $ data = $ db -> loadObject ( ) ; $ cache -> put ( '_system.' . $ option , $ data , $ this -> app [ 'config' ] -> get ( 'cachetime' , 15 ) ) ; } self :: $ components [ $ option ] = $ data ; if ( $ error = $ db -> getErrorMsg ( ) ) { throw new Exception ( $ this -> app [ 'language' ] -> translate ( 'JLIB_APPLICATION_ERROR_COMPONENT_NOT_LOADING' , $ option , $ error ) , 500 ) ; } } if ( empty ( self :: $ components [ $ option ] ) ) { self :: $ components [ $ option ] = new stdClass ; self :: $ components [ $ option ] -> option = $ option ; self :: $ components [ $ option ] -> enabled = $ strict ? 0 : 1 ; self :: $ components [ $ option ] -> params = '' ; self :: $ components [ $ option ] -> id = 0 ; } if ( is_string ( self :: $ components [ $ option ] -> params ) ) { self :: $ components [ $ option ] -> params = new Registry ( self :: $ components [ $ option ] -> params ) ; } return self :: $ components [ $ option ] ; }
Load the installed components into the components property .
46,692
public function getUInt ( $ name , $ default = 0 , $ hash = 'input' ) { $ result = $ this -> getInt ( $ name , $ default , $ hash ) ; return ( ! is_null ( $ result ) ? abs ( $ result ) : $ default ) ; }
Get unsigned integer
46,693
public function getString ( $ name , $ default = null , $ hash = 'input' ) { $ result = $ this -> getVar ( $ name , $ default , $ hash ) ; $ result = is_array ( $ result ) ? implode ( '' , $ result ) : $ result ; return ( string ) $ result ; }
Fetches and returns a given variable as a string .
46,694
public function root ( $ pathonly = false ) { $ root = rtrim ( ( $ pathonly ? '' : $ this -> getSchemeAndHttpHost ( ) ) . $ this -> getBasePath ( ) , '/' ) ; $ root = explode ( '/' , $ root ) ; if ( in_array ( end ( $ root ) , array ( 'administrator' , 'api' ) ) ) { array_pop ( $ root ) ; } return implode ( '/' , $ root ) . '/' ; }
Get the root URL for the application .
46,695
public function status ( ) { $ mode = $ this -> output -> getMode ( ) ; $ status = $ this -> mechanism -> status ( ) ; $ message = ( ! empty ( $ status ) ) ? 'This repository is managed by ' . $ this -> mechanism -> getName ( ) . ' and has the following divergence:' : 'This repository is managed by ' . $ this -> mechanism -> getName ( ) . ' and is clean' ; if ( $ mode != 'minimal' ) { $ this -> output -> addLine ( $ message , array ( 'color' => 'blue' ) ) ; } $ colorMap = array ( 'added' => 'green' , 'modified' => 'yellow' , 'deleted' => 'cyan' , 'renamed' => 'yellow' , 'copied' => 'yellow' , 'untracked' => 'black' , 'unmerged' => 'red' , 'merged' => 'blue' ) ; if ( is_array ( $ status ) && count ( $ status ) > 0 ) { foreach ( $ status as $ k => $ v ) { if ( count ( $ v ) > 0 ) { if ( $ mode == 'minimal' ) { $ this -> output -> addLine ( array ( $ k => $ v ) ) ; } else { $ this -> output -> addSpacer ( ) ; $ this -> output -> addLine ( ucfirst ( $ k ) . ' files:' ) ; foreach ( $ v as $ file ) { $ this -> output -> addLine ( $ file , array ( 'color' => $ colorMap [ $ k ] , 'indentation' => 2 ) ) ; } } } } } }
Check the current status of the repository
46,696
public function clean ( ) { if ( $ this -> output -> isInteractive ( ) ) { $ performed = 0 ; $ proceed = $ this -> output -> getResponse ( 'Do you want to purge all rollback points except the latest? [y|n]' ) ; if ( $ proceed == 'y' || $ proceed == 'yes' ) { $ this -> mechanism -> purgeRollbackPoints ( ) ; $ this -> output -> addLine ( 'Purging rollback points.' ) ; $ performed ++ ; } $ proceed = $ this -> output -> getResponse ( 'Do you want to purge all stashed changes? [y|n]' ) ; if ( $ proceed == 'y' || $ proceed == 'yes' ) { $ this -> mechanism -> purgeStash ( ) ; $ this -> output -> addLine ( 'Purging repository stash.' ) ; $ performed ++ ; } $ this -> output -> addLine ( "Clean up complete. Performed ({$performed}/2) cleanup operations available." ) ; } else { $ didSomething = false ; if ( $ this -> arguments -> getOpt ( 'purge-rollback-points' ) ) { $ this -> mechanism -> purgeRollbackPoints ( ) ; $ this -> output -> addLine ( 'Purging rollback points.' ) ; $ didSomething = true ; } if ( $ this -> arguments -> getOpt ( 'purge-stash' ) ) { $ this -> mechanism -> purgeStash ( ) ; $ this -> output -> addLine ( 'Purging repository stash.' ) ; $ didSomething = true ; } if ( ! $ didSomething ) { $ this -> output -> addLine ( 'Please specify which cleanup operations to perform' ) ; } } }
Do some repository cleanup
46,697
public static function destroyByGroup ( $ group_id ) { $ group_id = ( is_array ( $ group_id ) ? $ group_id : array ( $ group_id ) ) ; $ blank = self :: blank ( ) ; $ query = $ blank -> getQuery ( ) -> delete ( $ blank -> getTableName ( ) ) -> whereIn ( 'group_id' , $ group_id ) ; if ( ! $ query -> execute ( ) ) { return false ; } return true ; }
Delete objects of this type by Access Group ID
46,698
public static function destroyByUser ( $ user_id ) { $ user_id = ( is_array ( $ user_id ) ? $ user_id : array ( $ user_id ) ) ; $ blank = self :: blank ( ) ; $ query = $ blank -> getQuery ( ) -> delete ( $ blank -> getTableName ( ) ) -> whereIn ( 'user_id' , $ user_id ) ; if ( ! $ query -> execute ( ) ) { return false ; } return true ; }
Delete objects of this type by User ID
46,699
public static function addUserToGroup ( $ user_id , $ group_id ) { $ entries = self :: all ( ) -> whereEquals ( 'user_id' , $ user_id ) -> rows ( ) ; $ existing = array ( ) ; foreach ( $ entries as $ entry ) { $ existing [ ] = $ entry -> get ( 'group_id' ) ; } $ group_id = ( is_array ( $ group_id ) ? $ group_id : array ( $ group_id ) ) ; $ blank = self :: blank ( ) ; foreach ( $ group_id as $ group ) { $ group = intval ( $ group ) ; if ( in_array ( $ group , $ existing ) ) { continue ; } $ query = $ blank -> getQuery ( ) -> insert ( $ blank -> getTableName ( ) ) -> values ( array ( 'user_id' => $ user_id , 'group_id' => $ group ) ) ; if ( ! $ query -> execute ( ) ) { return false ; } } return true ; }
Add a user to access groups