idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
46,100
public function installPackage ( PackageInterface $ package , InstallerInterface $ installer , $ isDependency = false ) { if ( false !== strpos ( $ package -> getName ( ) , 'github' ) ) { $ name = basename ( $ package -> getName ( ) , '.git' ) ; $ repoUrl = $ package -> getName ( ) ; $ package = new Package ( $ name , $ package -> getRequiredVersion ( ) ) ; $ this -> repository -> setUrl ( $ repoUrl ) -> setHttpClient ( $ this -> githubClient ) ; $ package -> setRepository ( $ this -> repository ) ; $ packageTag = $ this -> repository -> findPackage ( $ package -> getRequiredVersion ( ) ) ; if ( is_null ( $ packageTag ) ) { throw new RuntimeException ( sprintf ( 'Cannot find package %s version %s.' , $ package -> getName ( ) , $ package -> getRequiredVersion ( ) ) ) ; } } else { $ packageTag = $ this -> getPackageTag ( $ package , true ) ; $ package -> setRepository ( $ this -> repository ) ; } $ package -> setVersion ( $ packageTag ) ; $ this -> updateBowerFile ( $ package , $ isDependency ) ; if ( $ this -> isPackageInstalled ( $ package ) ) { $ this -> output -> writelnInfoPackage ( $ package , 'validate' , sprintf ( '%s against %s#%s' , $ packageTag , $ package -> getName ( ) , $ package -> getRequiredVersion ( ) ) ) ; $ packageBower = $ this -> config -> getPackageBowerFileContent ( $ package ) ; if ( $ packageTag == $ packageBower [ 'version' ] ) { return ; } } $ this -> cachePackage ( $ package ) ; $ this -> output -> writelnInstalledPackage ( $ package ) ; $ installer -> install ( $ package ) ; $ overrides = $ this -> config -> getOverrideFor ( $ package -> getName ( ) ) ; if ( array_key_exists ( 'dependencies' , $ overrides ) ) { $ dependencies = $ overrides [ 'dependencies' ] ; } else { $ dependencies = $ package -> getRequires ( ) ; } if ( ! empty ( $ dependencies ) ) { foreach ( $ dependencies as $ name => $ version ) { $ depPackage = new Package ( $ name , $ version ) ; if ( ! $ this -> isPackageInstalled ( $ depPackage ) ) { $ this -> installPackage ( $ depPackage , $ installer , true ) ; } elseif ( $ this -> isNeedUpdate ( $ depPackage ) ) { $ this -> updatePackage ( $ depPackage , $ installer ) ; } } } }
Install a single package
46,101
public function installDependencies ( InstallerInterface $ installer ) { $ decode = $ this -> config -> getBowerFileContent ( ) ; if ( ! empty ( $ decode [ 'dependencies' ] ) ) { foreach ( $ decode [ 'dependencies' ] as $ name => $ requiredVersion ) { if ( false !== strpos ( $ requiredVersion , 'github' ) ) { list ( $ name , $ requiredVersion ) = explode ( '#' , $ requiredVersion ) ; } $ package = new Package ( $ name , $ requiredVersion ) ; $ this -> installPackage ( $ package , $ installer , true ) ; } } }
Install all dependencies
46,102
public function updatePackage ( PackageInterface $ package , InstallerInterface $ installer ) { if ( ! $ this -> isPackageInstalled ( $ package ) ) { throw new RuntimeException ( sprintf ( 'Package %s is not installed.' , $ package -> getName ( ) ) ) ; } if ( is_null ( $ package -> getRequiredVersion ( ) ) ) { $ decode = $ this -> config -> getBowerFileContent ( ) ; if ( empty ( $ decode [ 'dependencies' ] ) || empty ( $ decode [ 'dependencies' ] [ $ package -> getName ( ) ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Package %s not found in bower.json' , $ package -> getName ( ) ) ) ; } $ package -> setRequiredVersion ( $ decode [ 'dependencies' ] [ $ package -> getName ( ) ] ) ; } $ bower = $ this -> config -> getPackageBowerFileContent ( $ package ) ; $ package -> setInfo ( $ bower ) ; $ package -> setVersion ( $ bower [ 'version' ] ) ; $ package -> setRequires ( isset ( $ bower [ 'dependencies' ] ) ? $ bower [ 'dependencies' ] : null ) ; $ packageTag = $ this -> getPackageTag ( $ package ) ; $ this -> output -> writelnInfoPackage ( $ package , 'validate' , sprintf ( '%s against %s#%s' , $ packageTag , $ package -> getName ( ) , $ package -> getRequiredVersion ( ) ) ) ; $ package -> setRepository ( $ this -> repository ) ; if ( $ packageTag == $ package -> getVersion ( ) ) { return ; } $ package -> setVersion ( $ packageTag ) ; $ this -> cachePackage ( $ package ) ; $ this -> output -> writelnUpdatingPackage ( $ package ) ; $ installer -> update ( $ package ) ; $ overrides = $ this -> config -> getOverrideFor ( $ package -> getName ( ) ) ; if ( array_key_exists ( 'dependencies' , $ overrides ) ) { $ dependencies = $ overrides [ 'dependencies' ] ; } else { $ dependencies = $ package -> getRequires ( ) ; } if ( ! empty ( $ dependencies ) ) { foreach ( $ dependencies as $ name => $ requiredVersion ) { $ depPackage = new Package ( $ name , $ requiredVersion ) ; if ( ! $ this -> isPackageInstalled ( $ depPackage ) ) { $ this -> installPackage ( $ depPackage , $ installer , true ) ; } elseif ( $ this -> isNeedUpdate ( $ depPackage ) ) { $ this -> updatePackage ( $ depPackage , $ installer ) ; } } } }
Update a single package
46,103
public function updatePackages ( InstallerInterface $ installer ) { $ decode = $ this -> config -> getBowerFileContent ( ) ; if ( ! empty ( $ decode [ 'dependencies' ] ) ) { foreach ( $ decode [ 'dependencies' ] as $ packageName => $ requiredVersion ) { $ this -> updatePackage ( new Package ( $ packageName , $ requiredVersion ) , $ installer ) ; } } }
Update all dependencies
46,104
public function uninstallPackage ( PackageInterface $ package , InstallerInterface $ installer ) { if ( ! $ this -> isPackageInstalled ( $ package ) ) { throw new RuntimeException ( sprintf ( 'Package %s is not installed.' , $ package -> getName ( ) ) ) ; } $ installer -> uninstall ( $ package ) ; }
Uninstall a single package
46,105
public function searchPackages ( $ name ) { try { $ url = $ this -> config -> getBasePackagesUrl ( ) . 'search/' . $ name ; $ response = $ this -> githubClient -> getHttpClient ( ) -> get ( $ url ) ; return json_decode ( $ response -> getBody ( true ) , true ) ; } catch ( RequestException $ e ) { throw new RuntimeException ( sprintf ( 'Cannot get package list from %s.' , str_replace ( '/packages/' , '' , $ this -> config -> getBasePackagesUrl ( ) ) ) ) ; } }
Search packages by name
46,106
public function isPackageInstalled ( PackageInterface $ package ) { return $ this -> filesystem -> exists ( $ this -> config -> getInstallDir ( ) . '/' . $ package -> getName ( ) . '/.bower.json' ) ; }
Check if package is installed
46,107
public function isNeedUpdate ( $ package ) { $ packageBower = $ this -> config -> getPackageBowerFileContent ( $ package ) ; $ semver = new version ( $ packageBower [ 'version' ] ) ; return ! $ semver -> satisfies ( new expression ( $ package -> getRequiredVersion ( ) ) ) ; }
Update only if needed is greater version
46,108
protected function filterZipFiles ( ZipArchive $ archive , array $ ignore = [ ] , array $ force = [ ] ) { $ dirName = $ archive -> getNameIndex ( 0 ) ; $ return = [ ] ; $ numFiles = $ archive -> getNumFiles ( ) ; for ( $ i = 0 ; $ i < $ numFiles ; ++ $ i ) { $ stat = $ archive -> statIndex ( $ i ) ; $ return [ ] = $ stat [ 'name' ] ; } $ that = $ this ; $ filter = array_filter ( $ return , function ( $ var ) use ( $ ignore , $ force , $ dirName , $ that ) { return ! $ that -> isIgnored ( $ var , $ ignore , $ force , $ dirName ) ; } ) ; return array_values ( $ filter ) ; }
Filter archive files based on an ignore list .
46,109
public function isIgnored ( $ name , array $ ignore , array $ force , $ dirName ) { $ vName = substr ( $ name , strlen ( $ dirName ) ) ; if ( in_array ( $ vName , $ force , true ) ) { return false ; } foreach ( $ ignore as $ pattern ) { if ( 0 !== strpos ( $ pattern , '!' ) ) { continue ; } $ pattern = ltrim ( $ pattern , '!' ) ; if ( $ this -> isIgnored ( $ name , [ $ pattern ] , $ force , $ dirName ) ) { return false ; } } foreach ( $ ignore as $ pattern ) { if ( false !== strpos ( $ pattern , '**' ) ) { $ pattern = str_replace ( '**' , '*' , $ pattern ) ; if ( '/' == substr ( $ pattern , 0 , 1 ) ) { $ vName = '/' . $ vName ; } if ( '.' == substr ( $ vName , 0 , 1 ) ) { $ vName = '/' . $ vName ; } if ( fnmatch ( $ pattern , $ vName , FNM_PATHNAME ) ) { return true ; } elseif ( '*/*' === $ pattern && fnmatch ( '*' , $ vName , FNM_PATHNAME ) ) { return true ; } } elseif ( '/' == substr ( $ pattern , - 1 ) ) { if ( '/' == substr ( $ pattern , 0 , 1 ) ) { $ pattern = substr ( $ pattern , 1 ) ; } $ escPattern = str_replace ( [ '.' , '*' ] , [ '\.' , '.*' ] , $ pattern ) ; if ( preg_match ( '#^' . $ escPattern . '#' , $ vName ) > 0 ) { return true ; } } elseif ( false === strpos ( $ pattern , '/' ) ) { $ escPattern = str_replace ( [ '.' , '*' ] , [ '\.' , '.*' ] , $ pattern ) ; if ( preg_match ( '#^' . $ escPattern . '#' , $ vName ) > 0 ) { return true ; } } elseif ( '/' == substr ( $ pattern , 0 , 1 ) ) { $ escPattern = str_replace ( [ '.' , '*' ] , [ '\.' , '.*' ] , $ pattern ) ; if ( preg_match ( '#^' . $ escPattern . '#' , '/' . $ vName ) > 0 ) { return true ; } } else { $ escPattern = str_replace ( [ '.' , '*' ] , [ '\.' , '.*' ] , $ pattern ) ; if ( preg_match ( '#^' . $ escPattern . '#' , $ vName ) > 0 ) { return true ; } } } return false ; }
Check if a file should be ignored
46,110
protected function canRetry ( RequestException $ exception ) { if ( $ exception instanceof NetworkException ) { if ( $ exception -> getCode ( ) === 0 || $ exception -> getCode ( ) >= 500 ) { return true ; } } elseif ( $ exception instanceof ApiException ) { return in_array ( $ exception -> getCode ( ) , [ ApiException :: AUTHENTICATION_TEMPORARILY_UNAVAILABLE , ApiException :: SERVER_TEMPORARILY_UNAVAILABLE , ApiException :: INITIALIZATION_ERROR , ApiException :: OPERATION_ERROR , ApiException :: EXCEEDED_LIMIT_CONCURRENT_REQUESTS , ApiException :: TEMPORARILY_UNAVAILABLE , ] ) ; } return false ; }
Checks that a request can be retried .
46,111
private function symfonyDoRun ( InputInterface $ input , OutputInterface $ output , $ default = 'list-commands' ) { if ( true === $ input -> hasParameterOption ( [ '--version' , '-V' ] ) ) { $ output -> writeln ( $ this -> getLongVersion ( ) ) ; return 0 ; } $ name = $ this -> getCommandName ( $ input ) ; if ( true === $ input -> hasParameterOption ( [ '--help' , '-h' ] ) ) { if ( ! $ name ) { $ name = 'help' ; $ input = new ArrayInput ( [ 'command' => 'help' ] ) ; } else { $ this -> wantHelps = true ; } } if ( ! $ name ) { $ name = $ default ; $ input = new ArrayInput ( [ 'command' => $ default ] ) ; } $ command = $ this -> find ( $ name ) ; $ this -> runningCommand = $ command ; $ exitCode = $ this -> doRunCommand ( $ command , $ input , $ output ) ; $ this -> runningCommand = null ; return $ exitCode ; }
Copy of original Symfony doRun to allow a default command
46,112
public function writelnJson ( $ jsonString ) { $ keyColor = preg_replace ( '/"(\w+)": /' , '<info>$1</info>: ' , $ jsonString ) ; $ valColor = preg_replace ( '/"([^"]+)"/' , "<fg=cyan>'$1'</fg=cyan>" , $ keyColor ) ; $ this -> output -> writeln ( stripslashes ( $ valColor ) ) ; }
Rewrite json with colors and unescaped slashes
46,113
protected function invoke ( $ method , array $ params = [ ] ) { $ qualifiedClassName = get_class ( $ this ) ; if ( false !== $ pos = strrpos ( $ qualifiedClassName , '\\' ) ) { $ methodRef = substr ( $ qualifiedClassName , $ pos + 1 ) . ':' . $ method ; } else { $ methodRef = $ qualifiedClassName . ':' . $ method ; } $ invoker = $ this -> user -> getInvoker ( ) ; return $ invoker ( function ( ) use ( $ methodRef , $ method , $ params ) { $ this -> dispatcher -> dispatch ( Events :: BEFORE_REQUEST , new PreCallEvent ( $ methodRef , $ params , $ this -> user ) ) ; try { $ response = $ this -> __soapCall ( $ method , $ params ) ; } catch ( \ Exception $ ex ) { if ( $ ex instanceof \ SoapFault ) { if ( strtolower ( $ ex -> faultcode ) === 'http' ) { $ ex = new NetworkException ( $ ex -> getMessage ( ) , 0 , $ ex ) ; } else { $ ex = $ this -> handleFault ( $ ex , $ methodRef , $ params ) ; } } $ this -> dispatcher -> dispatch ( Events :: FAIL_REQUEST , new FailCallEvent ( $ methodRef , $ params , $ this -> user , $ this , $ ex , $ this -> fetchUtits ( ) ) ) ; throw $ ex ; } $ this -> dispatcher -> dispatch ( Events :: AFTER_REQUEST , new PostCallEvent ( $ methodRef , $ params , $ this -> user , $ this , $ response , $ this -> fetchUtits ( ) ) ) ; return $ response ; } ) ; }
Invokes API method with specified name .
46,114
public function addItem ( Item $ item ) { $ item -> source = $ this -> link ; $ this -> items [ ] = $ item ; return $ this ; }
Adds an Item to the feed .
46,115
public function get ( $ value , $ default = null ) { return array_key_exists ( $ value , $ this -> config ) ? $ this -> config [ $ value ] : $ default ; }
Helper function to retrieve config values
46,116
public function hash ( $ email ) { if ( ! filter_var ( $ email , FILTER_VALIDATE_EMAIL ) ) { throw new InvalidEmailException ( 'Please specify a valid email address' ) ; } return md5 ( strtolower ( trim ( $ email ) ) ) ; }
Helper function to hash an email address .
46,117
public function parameters ( ) { $ build = array ( ) ; foreach ( get_class_methods ( $ this ) as $ method ) { if ( substr ( $ method , - strlen ( 'Parameter' ) ) !== 'Parameter' ) { continue ; } if ( $ called = call_user_func ( array ( $ this , $ method ) ) ) { $ build = array_replace ( $ build , $ called ) ; } } return '?' . http_build_query ( $ build ) ; }
Get querystring of parameters
46,118
public function sizeParameter ( ) { if ( ! $ this -> get ( 'size' ) || ! is_integer ( $ this -> get ( 'size' ) ) ) { return null ; } return array ( 's' => ( int ) $ this -> get ( 'size' ) ) ; }
Get size parameter
46,119
public function toString ( ) { $ this -> _generateBaseString ( ) ; $ this -> _addName ( ) ; $ this -> _addType ( ) ; $ this -> _addRestriction ( ) ; $ this -> _addDefault ( ) ; return $ this -> _asString ; }
Returns string representation of add column statement
46,120
public function url ( $ url , $ xhtml = true , $ ssl = null ) { if ( ( strpos ( $ url , '&' ) !== 0 ) && ( strpos ( $ url , 'index.php' ) !== 0 ) ) { return $ url ; } $ uri = $ this -> build ( $ url ) ; $ url = $ uri -> toString ( array ( 'scheme' , 'host' , 'port' , 'path' , 'query' , 'fragment' ) ) ; $ url = preg_replace ( '/\s/u' , '%20' , $ url ) ; if ( ( int ) $ ssl ) { $ scheme = ( ( int ) $ ssl === 1 ) ? 'https' : 'http' ; if ( ! preg_match ( '#^/#' , $ url ) ) { $ url = '/' . $ url ; } $ url = $ scheme . '://' . $ this -> prefix . $ url ; } if ( $ xhtml ) { $ url = htmlspecialchars ( $ url ) ; } return $ url ; }
Translates an internal URL to a humanly readable URL .
46,121
public function rules ( $ type ) { $ type = strtolower ( trim ( $ type ) ) ; if ( ! isset ( $ this -> rules [ $ type ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Rule type of %s not supported' , $ type ) ) ; } return $ this -> rules [ $ type ] ; }
Get a set of rules
46,122
public function build ( $ uri ) { $ uri = $ this -> createUri ( $ uri ) ; foreach ( $ this -> rules [ 'build' ] as $ rule ) { $ uri = $ rule ( $ uri ) ; } return $ uri ; }
Function to convert an internal URI to a route
46,123
public function parse ( $ uri ) { $ uri = $ this -> createUri ( $ uri ) ; $ this -> bind ( $ uri -> getQuery ( true ) ) ; foreach ( $ this -> rules [ 'parse' ] as $ rule ) { if ( $ rule ( $ uri ) ) { break ; } } $ vars = array_merge ( $ uri -> getQuery ( true ) , $ this -> vars ( ) ) ; $ this -> bind ( $ vars ) ; return $ this -> vars ( ) ; }
Function to convert a route to an internal URI
46,124
public function set ( $ key , $ value , $ create = true ) { if ( $ create || array_key_exists ( $ key , $ this -> vars ) ) { $ this -> vars [ $ key ] = $ value ; } return $ this ; }
Set a router variable creating it if it doesn t exist
46,125
public function bind ( $ vars = array ( ) , $ merge = true ) { if ( $ merge ) { $ this -> vars = array_merge ( $ this -> vars , $ vars ) ; } else { $ this -> vars = $ vars ; } return $ this ; }
Set the router variable array
46,126
public function get ( $ key ) { $ result = null ; if ( isset ( $ this -> vars [ $ key ] ) ) { $ result = $ this -> vars [ $ key ] ; } return $ result ; }
Get a router variable
46,127
public function forget ( $ key ) { if ( array_key_exists ( $ key , $ this -> vars ) ) { unset ( $ this -> vars [ $ key ] ) ; } return $ this ; }
Unset a router variable
46,128
protected function createUri ( $ url ) { if ( $ url instanceof Uri ) { return $ url ; } if ( substr ( $ url , 0 , 1 ) == '&' ) { $ vars = array ( ) ; if ( strpos ( $ url , '&amp;' ) !== false ) { $ url = str_replace ( '&amp;' , '&' , $ url ) ; } parse_str ( $ url , $ vars ) ; $ vars = array_merge ( $ this -> vars ( ) , $ vars ) ; foreach ( $ vars as $ key => $ var ) { if ( $ var == '' ) { unset ( $ vars [ $ key ] ) ; } } $ url = 'index.php?' . urldecode ( http_build_query ( $ vars , '' , '&' ) ) ; } return new Uri ( $ url ) ; }
Create a uri based on a full or partial url string
46,129
public function addScriptDeclaration ( $ content , $ type = 'text/javascript' ) { if ( ! isset ( $ this -> _script [ strtolower ( $ type ) ] ) ) { $ this -> _script [ strtolower ( $ type ) ] = array ( $ content ) ; } else { $ this -> _script [ strtolower ( $ type ) ] [ ] = chr ( 13 ) . $ content ; } return $ this ; }
Adds a script to the page
46,130
public function addStyleDeclaration ( $ content , $ type = 'text/css' ) { if ( ! isset ( $ this -> _style [ strtolower ( $ type ) ] ) ) { $ this -> _style [ strtolower ( $ type ) ] = $ content ; } else { $ this -> _style [ strtolower ( $ type ) ] .= chr ( 13 ) . $ content ; } return $ this ; }
Adds a stylesheet declaration to the page
46,131
public function setMimeEncoding ( $ type = 'text/html' , $ sync = true ) { $ this -> _mime = strtolower ( $ type ) ; if ( $ sync ) { $ this -> setMetaData ( 'content-type' , $ type , true , false ) ; } return $ this ; }
Sets the document MIME encoding that is sent to the browser .
46,132
public function setLineEnd ( $ style ) { switch ( $ style ) { case 'win' : $ this -> _lineEnd = "\15\12" ; break ; case 'unix' : $ this -> _lineEnd = "\12" ; break ; case 'mac' : $ this -> _lineEnd = "\15" ; break ; default : $ this -> _lineEnd = $ style ; } return $ this ; }
Sets the line end style to Windows Mac Unix or a custom string .
46,133
public function loadRenderer ( $ type ) { $ class = __NAMESPACE__ . '\\Type\\' . ucfirst ( $ this -> _type ) . '\\' . ucfirst ( $ type ) ; if ( ! class_exists ( $ class ) ) { throw new \ InvalidArgumentException ( \ Lang :: txt ( 'Unable to load renderer class' ) , 500 ) ; } return new $ class ( $ this ) ; }
Load a renderer
46,134
public function render ( $ cache = false , $ params = array ( ) ) { if ( $ mdate = $ this -> getModifiedDate ( ) ) { \ App :: get ( 'response' ) -> headers -> set ( 'Last-Modified' , $ mdate ) ; } \ App :: get ( 'response' ) -> headers -> set ( 'Content-Type' , $ this -> _mime . ( $ this -> _charset ? '; charset=' . $ this -> _charset : '' ) ) ; }
Outputs the document
46,135
protected function getOptions ( ) { $ folder = $ this -> element [ 'folder' ] ; if ( ! empty ( $ folder ) ) { $ db = App :: get ( 'db' ) ; $ query = $ db -> getQuery ( ) -> select ( 'element' , 'value' ) -> select ( 'name' , 'text' ) -> from ( '#__extensions' ) -> whereEquals ( 'folder' , $ folder ) -> whereEquals ( 'enabled' , '1' ) -> order ( 'ordering' , 'asc' ) -> order ( 'name' , 'asc' ) ; $ db -> setQuery ( $ query -> toString ( ) ) ; $ options = $ db -> loadObjectList ( ) ; $ lang = App :: get ( 'language' ) ; foreach ( $ options as $ i => $ item ) { $ extension = 'plg_' . $ folder . '_' . $ item -> value ; $ lang -> load ( $ extension . '.sys' , PATH_APP . '/plugins/' . $ folder . '/' . $ item -> value , null , false , true ) || $ lang -> load ( $ extension . '.sys' , PATH_CORE . '/plugins/' . $ folder . '/' . $ item -> value , null , false , true ) ; $ options [ $ i ] -> text = $ lang -> txt ( $ item -> text ) ; } if ( $ db -> getErrorMsg ( ) ) { return '' ; } } else { App :: abort ( 500 , App :: get ( 'language' ) -> txt ( 'JFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY' ) ) ; } $ options = array_merge ( parent :: getOptions ( ) , $ options ) ; return $ options ; }
Method to get a list of options for a list input .
46,136
public function render ( & $ definition ) { $ html = null ; $ cls = array ( ) ; if ( isset ( $ definition [ 9 ] ) ) { $ cls = array_pop ( $ definition ) ; } $ id = call_user_func_array ( array ( & $ this , 'fetchId' ) , $ definition ) ; $ action = call_user_func_array ( array ( & $ this , 'fetchButton' ) , $ definition ) ; if ( $ id ) { $ id = 'id="' . $ id . '"' ; } $ html .= '<li class="button ' . implode ( ' ' , $ cls ) . '" ' . $ id . ">\n" ; $ html .= $ action ; $ html .= "</li>\n" ; return $ html ; }
Get the HTML to render the button
46,137
protected function cleanup ( ) { $ items = $ this -> getParent ( false ) -> listContents ( ) ; foreach ( $ items as $ item ) { if ( in_array ( $ item -> getName ( ) , [ '.svn' , 'CVS' , '.DS_Store' , '__MACOSX' ] ) ) { if ( ! $ item -> delete ( ) ) { return false ; } } } return true ; }
Cleans the archive of OS - specific files
46,138
public static function iterate_profiles ( $ func ) { $ db = \ App :: get ( 'db' ) ; $ db -> setQuery ( "SELECT uidNumber FROM `#__xprofiles`;" ) ; $ result = $ db -> loadColumn ( ) ; if ( $ result === false ) { throw new Exception ( 'Error retrieving data from xprofiles table: ' . $ db -> getErrorMsg ( ) , 500 ) ; return false ; } foreach ( $ result as $ row ) { $ func ( $ row ) ; } return true ; }
Run a callback across all profiles
46,139
public static function find_by_email ( $ email ) { if ( empty ( $ email ) ) { return false ; } $ db = \ App :: get ( 'db' ) ; $ db -> setQuery ( "SELECT username FROM `#__xprofiles` WHERE `email`=" . $ db -> quote ( $ email ) ) ; $ result = $ db -> loadColumn ( ) ; if ( empty ( $ result ) ) { return false ; } return $ result ; }
Find a username by email address
46,140
public static function thumbit ( $ thumb ) { $ dot = strrpos ( $ thumb , '.' ) + 1 ; $ ext = substr ( $ thumb , $ dot ) ; return preg_replace ( '#\.[^.]*$#' , '' , $ thumb ) . '_thumb.' . $ ext ; }
Generate a thumbnail file name format example . jpg - > example_thumb . jpg
46,141
public static function calendar ( $ name , $ value = null , $ options = array ( ) ) { static $ done ; if ( $ done === null ) { $ done = array ( ) ; } $ readonly = isset ( $ options [ 'readonly' ] ) && $ options [ 'readonly' ] == 'readonly' ; $ disabled = isset ( $ options [ 'disabled' ] ) && $ options [ 'disabled' ] == 'disabled' ; $ time = isset ( $ options [ 'time' ] ) ? ( bool ) $ options [ 'time' ] : true ; $ format = 'yy-mm-dd' ; if ( isset ( $ options [ 'format' ] ) ) { $ format = $ options [ 'format' ] ? $ options [ 'format' ] : $ format ; unset ( $ options [ 'format' ] ) ; } if ( ! isset ( $ options [ 'class' ] ) ) { $ options [ 'class' ] = 'calendar-field' ; } else { $ options [ 'class' ] = ' calendar-field' ; } if ( ! $ readonly && ! $ disabled ) { Behavior :: calendar ( ) ; Behavior :: tooltip ( ) ; $ id = self :: getIdAttribute ( $ name , $ options ) ; if ( ! in_array ( $ id , $ done ) ) { if ( $ format == 'Y-m-d H:i:s' || $ format == '%Y-%m-%d %H:%M:%S' ) { $ time = true ; } $ altformats = array ( 'Y-m-d H:i:s' , '%Y-%m-%d %H:%M:%S' , 'Y-m-d' , '%Y-%m-%d' ) ; $ format = ( in_array ( $ format , $ altformats ) ? 'yy-mm-dd' : $ format ) ; \ App :: get ( 'document' ) -> addScriptDeclaration ( " jQuery(document).ready(function($){ " . ( $ time ? "$('#" . $ id . "').datetimepicker({" : "$('#" . $ id . "').datepicker({" ) . " duration: '', showTime: true, constrainInput: false, stepMinutes: 1, stepHours: 1, altTimeField: '', time24h: true, dateFormat: '" . $ format . "'" . ( $ time ? ", timeFormat: 'HH:mm:00'" : "" ) . " }); }); " ) ; $ done [ ] = $ id ; } return '<span class="input-datetime">' . self :: text ( $ name , $ value , $ options ) . '</span>' ; } else { $ value = ( 0 !== ( int ) $ value ? with ( new Date ( $ value ) ) -> format ( 'Y-m-d H:i:s' ) : '' ) ; return self :: text ( $ name . 'disabled' , ( 0 !== ( int ) $ value ? with ( new Date ( $ value ) ) -> format ( 'Y-m-d H:i:s' ) : '' ) , $ options ) . self :: hidden ( $ name , $ value , $ options ) ; } }
Displays a calendar control field
46,142
public static function colorpicker ( $ name , $ value = null , $ options = array ( ) ) { static $ done ; if ( $ done === null ) { $ done = array ( ) ; } $ readonly = isset ( $ options [ 'readonly' ] ) && $ options [ 'readonly' ] == 'readonly' ; $ disabled = isset ( $ options [ 'disabled' ] ) && $ options [ 'disabled' ] == 'disabled' ; $ options [ 'class' ] = 'input-colorpicker' ; $ value = $ value ? '#' . ltrim ( $ value , '#' ) : '' ; if ( ! $ readonly && ! $ disabled ) { $ id = self :: getIdAttribute ( $ name , $ options ) ; if ( ! in_array ( $ id , $ done ) ) { Behavior :: colorpicker ( ) ; $ done [ ] = $ id ; } return '<span class="input-color">' . self :: text ( $ name , $ value , $ options ) . '</span>' ; } return self :: text ( $ name . 'disabled' , $ value , $ options ) . self :: hidden ( $ name , $ value , $ options ) ; }
Displays a color picker control field
46,143
public function logout ( $ userid = null , $ options = array ( ) ) { $ user = ( $ userid ? \ User :: getInstance ( $ userid ) : \ User :: getInstance ( ) ) ; $ parameters [ 'username' ] = $ user -> get ( 'username' ) ; $ parameters [ 'id' ] = $ user -> get ( 'id' ) ; if ( ! isset ( $ options [ 'clientid' ] ) ) { $ options [ 'clientid' ] = $ this -> app [ 'client' ] -> id ; } $ results = $ this -> app [ 'dispatcher' ] -> trigger ( 'user.onUserLogout' , array ( $ parameters , $ options ) ) ; if ( ! in_array ( false , $ results , true ) ) { $ cookie_domain = $ this -> app [ 'config' ] -> get ( 'cookie_domain' , '' ) ; $ cookie_path = $ this -> app [ 'config' ] -> get ( 'cookie_path' , '/' ) ; setcookie ( $ this -> app -> hash ( 'JLOGIN_REMEMBER' ) , false , time ( ) - 86400 , $ cookie_path , $ cookie_domain ) ; return true ; } $ this -> app [ 'dispatcher' ] -> trigger ( 'user.onUserLogoutFailure' , array ( $ parameters ) ) ; return false ; }
Logout a user
46,144
public function getRateLimitData ( $ applicationId , $ userId ) { $ sql = "SELECT * FROM `#__developer_rate_limit` WHERE `application_id` = " . $ this -> db -> quote ( $ applicationId ) . " AND `uidNumber` = " . $ this -> db -> quote ( $ userId ) . " ORDER BY `created` LIMIT 1" ; $ this -> db -> setQuery ( $ sql ) ; return $ this -> db -> loadObject ( ) ; }
Get record by application & user is
46,145
public function createRateLimitData ( $ applicationId , $ userId , $ ip , $ limitShort , $ limitLong , $ countShort , $ countLong , $ expiresShort , $ expiresLong , $ created ) { $ sql = "INSERT INTO `#__developer_rate_limit` (`application_id`, `uidNumber`, `ip`, `limit_short`, `limit_long`, `count_short`, `count_long`, `expires_short`, `expires_long`, `created`) VALUES (" . $ this -> db -> quote ( $ applicationId ) . ", " . $ this -> db -> quote ( $ userId ) . ", " . $ this -> db -> quote ( $ ip ) . ", " . $ this -> db -> quote ( $ limitShort ) . ", " . $ this -> db -> quote ( $ limitLong ) . ", " . $ this -> db -> quote ( $ countShort ) . ", " . $ this -> db -> quote ( $ countLong ) . ", " . $ this -> db -> quote ( $ expiresShort ) . ", " . $ this -> db -> quote ( $ expiresLong ) . ", " . $ this -> db -> quote ( $ created ) . ")" ; $ this -> db -> setQuery ( $ sql ) ; $ this -> db -> query ( ) ; return $ this -> getRateLimitData ( $ applicationId , $ userId ) ; }
Create initial rate limit record
46,146
public function incrementRateLimitData ( $ id , $ increment = 1 ) { $ sql = "UPDATE `#__developer_rate_limit` SET `count_short` = `count_short` + " . $ this -> db -> quote ( $ increment ) . ", `count_long` = `count_long` + " . $ this -> db -> quote ( $ increment ) . " WHERE `id` = " . $ this -> db -> quote ( $ id ) ; $ this -> db -> setQuery ( $ sql ) ; return $ this -> db -> query ( ) ; }
Increment rate limit record
46,147
public function resetLong ( $ id , $ toCount , $ toDate ) { $ sql = "UPDATE `#__developer_rate_limit` SET `count_long` = " . $ this -> db -> quote ( $ toCount ) . ", `expires_long` = " . $ this -> db -> quote ( $ toDate ) . " WHERE `id` = " . $ this -> db -> quote ( $ id ) ; $ this -> db -> setQuery ( $ sql ) ; return $ this -> db -> query ( ) ; }
Reset long count & expiration
46,148
public function toString ( ) { $ privateProperties = with ( new \ ReflectionClass ( $ this ) ) -> getProperties ( \ ReflectionProperty :: IS_PROTECTED ) ; foreach ( $ privateProperties as $ prop ) { $ name = ( string ) $ prop -> name ; unset ( $ this -> $ name ) ; } return json_encode ( $ this ) ; }
To String object
46,149
public function getInviteEmails ( $ gid , $ email_only = false ) { $ final = array ( ) ; $ invitees = self :: all ( ) -> whereEquals ( 'gidNumber' , $ gid ) -> ordered ( ) -> rows ( ) ; if ( $ email_only ) { foreach ( $ invitees as $ invitee ) { $ final [ ] = $ invitee -> get ( 'email' ) ; } } else { $ final = $ invitees ; } return $ final ; }
Get a list of email invites for a group
46,150
public function addInvites ( $ gid , $ emails ) { $ exists = array ( ) ; $ added = array ( ) ; $ current = $ this -> getInviteEmails ( $ gid , true ) ; foreach ( $ emails as $ e ) { if ( in_array ( $ e , $ current ) ) { $ exists [ ] = $ e ; } else { $ added [ ] = $ e ; } } if ( count ( $ added ) > 0 ) { foreach ( $ added as $ a ) { $ model = self :: blank ( ) ; $ model -> set ( [ 'email' => $ a , 'gidNumber' => $ gid , 'token' => md5 ( $ a ) ] ) ; $ model -> save ( ) ; } } $ return [ 'exists' ] = $ exists ; $ return [ 'added' ] = $ added ; return $ return ; }
Add a list of emails to a group as invitees
46,151
public function removeInvites ( $ gid , $ emails ) { foreach ( $ emails as $ email ) { $ model = self :: all ( ) -> whereEquals ( 'gidNumber' , $ gid ) -> whereEquals ( 'email' , $ email ) -> row ( ) ; if ( $ model -> get ( 'id' ) ) { $ model -> destroy ( ) ; } } }
Remove Invite Emails
46,152
public function getDBO ( ) { $ db = \ App :: get ( 'db' ) ; if ( ! $ db -> connected ( ) ) { $ this -> log ( 'PDO connection failed' , 'error' ) ; return false ; } $ tables = $ db -> getTableList ( ) ; $ prefix = $ db -> getPrefix ( ) ; $ tableset = false ; if ( in_array ( 'migrations' , $ tables ) ) { $ this -> setTableName ( 'migrations' ) ; $ tableset = true ; } if ( in_array ( $ prefix . 'migrations' , $ tables ) ) { if ( $ tableset ) { $ this -> log ( 'Tables `migrations` and `' . $ prefix . 'migrations` both exist' , 'error' ) ; return false ; } $ this -> setTableName ( '#__migrations' ) ; $ tableset = true ; } if ( ! $ tableset ) { if ( $ this -> createMigrationsTable ( $ db ) === false ) { return false ; } } $ this -> registerCallback ( 'migration' , $ this ) ; return $ db ; }
Setup database connect test return object
46,153
public function find ( $ extension = null , $ file = null ) { $ exclude = array ( "." , ".." ) ; $ files = [ ] ; $ ext = '' ; foreach ( $ this -> searchPaths as $ path ) { if ( ! is_dir ( $ path . DS . 'migrations' ) ) { continue ; } $ found = array_diff ( scandir ( $ path . DS . 'migrations' ) , $ exclude ) ; foreach ( $ found as $ f ) { $ files [ $ path . DS . 'migrations' . DS . $ f ] = $ f ; } } asort ( $ files ) ; if ( ! is_null ( $ file ) ) { if ( in_array ( $ file , $ files ) ) { $ this -> files [ ] = array_search ( $ file , $ files ) ; return true ; } else { $ this -> log ( "Provided file ({$file}) could not be found." , 'error' ) ; return false ; } } if ( ! is_null ( $ extension ) ) { $ parts = explode ( '_' , $ extension ) ; foreach ( $ parts as $ part ) { $ ext .= ucfirst ( $ part ) ; } } foreach ( $ files as $ path => $ file ) { if ( preg_match ( '/^Migration[0-9]{14}[[:alnum:]]+\.php$/' , $ file ) ) { if ( empty ( $ ext ) || ( ! empty ( $ ext ) && preg_match ( '/Migration[0-9]{14}' . $ ext . '\.php/' , $ file ) ) ) { $ this -> files [ ] = $ path ; } } } return true ; }
Find all migration scripts
46,154
public function recordMigration ( $ file , $ scope , $ hash , $ direction , $ status = 'success' ) { if ( ! $ this -> db -> tableHasField ( $ this -> get ( 'tbl_name' ) , 'status' ) && $ status != 'success' ) { return true ; } try { $ date = new \ Hubzero \ Utility \ Date ( ) ; $ obj = ( object ) array ( 'file' => $ file , 'hash' => $ hash , 'direction' => $ direction , 'date' => $ date -> toSql ( ) , 'action_by' => ( php_sapi_name ( ) == 'cli' ) ? exec ( "whoami" ) : \ User :: get ( 'id' ) ) ; if ( $ this -> db -> tableHasField ( $ this -> get ( 'tbl_name' ) , 'scope' ) ) { $ obj -> scope = $ scope ; } if ( $ this -> db -> tableHasField ( $ this -> get ( 'tbl_name' ) , 'status' ) ) { $ obj -> status = $ status ; } $ this -> db -> insertObject ( $ this -> get ( 'tbl_name' ) , $ obj ) ; return true ; } catch ( \ Hubzero \ Database \ Exception \ QueryFailedException $ e ) { $ this -> log ( "Failed inserting migration record: {$e->getMessage()}" , 'error' ) ; return false ; } }
Record migration in migrations table
46,155
public function history ( ) { try { $ query = "SELECT * FROM " . $ this -> db -> quoteName ( $ this -> get ( 'tbl_name' ) ) ; $ this -> db -> setQuery ( $ query ) ; $ results = $ this -> db -> loadObjectList ( ) ; return $ results ; } catch ( \ Hubzero \ Database \ Exception \ QueryFailedException $ e ) { $ this -> log ( "Failed to retrieve history." , 'error' ) ; return false ; } }
Return migration run history
46,156
private function createMigrationsTable ( $ db ) { $ this -> log ( 'Migrations table did not exist...attempting to create it now' ) ; $ query = "CREATE TABLE `{$this->get('tbl_name')}` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `file` varchar(255) NOT NULL DEFAULT '', `scope` varchar(255) NOT NULL, `hash` char(32) NOT NULL DEFAULT '', `direction` varchar(10) NOT NULL DEFAULT '', `date` datetime NOT NULL, `action_by` varchar(255) NOT NULL DEFAULT '', `status` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;" ; try { $ db -> setQuery ( $ query ) ; $ db -> query ( ) ; $ this -> log ( 'Migrations table successfully created' ) ; return true ; } catch ( \ Hubzero \ Database \ Exception \ QueryFailedException $ e ) { $ this -> log ( 'Unable to create needed migrations table' , 'error' ) ; return false ; } }
Attempt to create needed migrations table
46,157
public function current ( ) { $ doc = new DOMDocument ( ) ; $ object = simplexml_import_dom ( $ doc -> importNode ( $ this -> reader -> expand ( ) , true ) ) ; return json_decode ( json_encode ( $ object ) ) ; }
Get the current XML node
46,158
public function rewind ( ) { $ this -> reader -> open ( $ this -> file , 'UTF-8' , XMLReader :: VALIDATE | XMLReader :: SUBST_ENTITIES ) ; while ( $ this -> reader -> read ( ) && $ this -> reader -> name !== $ this -> key ) { } }
Move to the first node that matches our key
46,159
public function menu ( $ menu = null , $ options = array ( ) ) { $ menu = $ menu ? : $ this -> getDefaultMenu ( ) ; if ( ! isset ( $ this -> menus [ $ menu ] ) ) { $ this -> menus [ $ menu ] = $ this -> createMenu ( $ menu , $ options ) ; } return $ this -> menus [ $ menu ] ; }
Get a menu instance .
46,160
protected function createMenu ( $ menu , $ options = array ( ) ) { $ cls = __NAMESPACE__ . '\\Type\\' . ucfirst ( $ menu ) ; if ( class_exists ( $ cls ) ) { return new $ cls ( $ options ) ; } throw new \ InvalidArgumentException ( "Menu [$menu] not supported." ) ; }
Create a new menu instance .
46,161
public function headers ( ) { if ( ! $ this -> headers ) { $ this -> rewind ( ) ; $ row = fgetcsv ( $ this -> file , self :: ROW_LENGTH , $ this -> delimiter ) ; $ this -> position ++ ; if ( $ this -> position == 1 ) { $ this -> headers = $ row ; } $ this -> rewind ( ) ; } return $ this -> headers ; }
Get the first row of headers
46,162
public function credit_adjustment ( $ amount ) { $ amount = intval ( $ amount ) ; $ this -> credit = ( $ amount > 0 ? $ amount : 0 ) ; $ this -> _saveBalance ( 'update' ) ; }
Make credit adjustment
46,163
public function _creditCheck ( $ amount ) { $ b = $ this -> balance ; $ b -= $ amount ; $ c = $ this -> credit ; $ ccheck = $ b - $ c ; if ( $ b >= 0 && $ ccheck >= 0 ) { return true ; } $ this -> setError ( 'Not enough points in user account to process transaction.' ) ; return false ; }
Check that they have enough in their account to perform the transaction .
46,164
public function _saveBalance ( $ type ) { if ( $ type == 'creation' ) { $ model = Account :: blank ( ) ; } else { $ model = Account :: oneByUserId ( $ this -> uid ) ; } $ model -> set ( [ 'uid' => $ this -> uid , 'balance' => $ this -> balance , 'earnings' => $ this -> earnings , 'credit' => $ this -> credit ] ) ; if ( ! $ model -> save ( ) ) { $ this -> setError ( $ model -> getError ( ) ) ; return false ; } return true ; }
Save the current balance
46,165
public function _saveTransaction ( $ type , $ amount , $ desc , $ cat , $ ref ) { $ transaction = Transaction :: blank ( ) -> set ( array ( 'uid' => $ this -> uid , 'type' => $ type , 'amount' => $ amount , 'description' => $ desc , 'category' => $ cat , 'referenceid' => $ ref , 'balance' => $ this -> balance ) ) ; if ( ! $ transaction -> save ( ) ) { $ this -> setError ( $ transaction -> getError ( ) ) ; return false ; } return true ; }
Record the transaction
46,166
public function prepend ( $ name , $ link = '' ) { $ b = new Item ( $ name , $ link ) ; array_unshift ( $ this -> items , $ b ) ; return $ this ; }
Create and prepend an item to the pathway .
46,167
public function names ( ) { $ names = array ( ) ; foreach ( $ this -> items as $ item ) { $ names [ ] = $ item -> name ; } return array_values ( $ names ) ; }
Create and return an array of the crumb names .
46,168
public function authenticate ( $ params = array ( ) , $ options = array ( ) ) { $ response = [ 'user_id' => null ] ; Event :: trigger ( 'before_auth' ) ; $ oauthServer = new Server ( new MysqlStorage , $ options ) ; $ oauthRequest = \ OAuth2 \ Request :: createFromGlobals ( ) ; $ oauthResponse = new \ OAuth2 \ Response ( ) ; $ oauthServer -> verifyResourceRequest ( $ oauthRequest , $ oauthResponse ) ; $ this -> token = $ oauthServer -> getAccessTokenData ( $ oauthRequest ) ; if ( isset ( $ this -> token [ 'uidNumber' ] ) ) { $ response [ 'user_id' ] = $ this -> token [ 'uidNumber' ] ; $ user = User :: oneOrNew ( $ response [ 'user_id' ] ) ; if ( $ user -> get ( 'id' ) ) { $ user -> set ( 'guest' , false ) ; } $ this -> app [ 'session' ] -> set ( 'user' , $ user ) ; } Event :: trigger ( 'after_auth' ) ; return $ response ; }
Validates incoming request via OAuth2 specification
46,169
public function isValid ( $ type = 'both' ) { $ type = strtolower ( $ type ) ; $ flags = 0 ; if ( $ type === 'ipv4' ) { $ flags = FILTER_FLAG_IPV4 ; } if ( $ type === 'ipv6' ) { $ flags = FILTER_FLAG_IPV6 ; } return ( bool ) filter_var ( $ this -> ip , FILTER_VALIDATE_IP , [ 'flags' => $ flags ] ) ; }
Checks to see if the ip address is of valid form
46,170
private function isRelativeTo ( $ threshold , $ above = true ) { $ threshold = ip2long ( $ threshold ) ; if ( ! $ threshold ) { throw new \ RuntimeException ( 'Invalid input, not an IP address' ) ; } return $ above ? ( $ this -> ipLong >= $ threshold ) : ( $ this -> ipLong <= $ threshold ) ; }
Checks to see if the ip address is less than or greater than the given
46,171
public function boot ( ) { if ( function_exists ( 'xdebug_disable' ) ) { xdebug_disable ( ) ; } ini_set ( 'zlib.output_compression' , '0' ) ; ini_set ( 'output_handler' , '' ) ; ini_set ( 'implicit_flush' , '0' ) ; $ this -> app [ 'config' ] -> set ( 'debug' , 0 ) ; $ this -> app [ 'config' ] -> set ( 'debug_lang' , 0 ) ; static $ types = array ( 'xml' => 'application/xml' , 'html' => 'text/html' , 'xhtml' => 'application/xhtml+xml' , 'json' => 'application/json' , 'text' => 'text/plain' , 'txt' => 'text/plain' , 'plain' => 'text/plain' , 'php' => 'application/php' , 'php_serialized' => 'application/vnd.php.serialized' ) ; $ format = $ this -> app [ 'request' ] -> getWord ( 'format' , 'json' ) ; $ format = ( isset ( $ types [ $ format ] ) ? $ format : 'json' ) ; $ this -> app [ 'response' ] -> setStatusCode ( 404 ) ; $ this -> app [ 'response' ] -> headers -> addCacheControlDirective ( 'no-store' , true ) ; $ this -> app [ 'response' ] -> headers -> addCacheControlDirective ( 'must-revalidate' , true ) ; $ this -> app [ 'response' ] -> headers -> set ( 'Content-Type' , $ types [ $ format ] ) ; }
Force debugging off .
46,172
public function save ( $ data ) { if ( ! is_array ( $ data ) ) { return false ; } if ( isset ( $ data [ 0 ] ) && is_array ( $ data [ 0 ] ) ) { foreach ( $ data as $ d ) { if ( ! parent :: save ( $ d ) ) { return false ; } } } else { if ( ! parent :: save ( $ data ) ) { return false ; } } return true ; }
Saves new related models with the given data
46,173
public function saveAll ( $ models ) { foreach ( $ models as $ model ) { if ( ! $ this -> associate ( $ model ) -> save ( ) ) { return false ; } } return true ; }
Saves all of the given models
46,174
public function seedWithData ( $ rows , $ data , $ name ) { $ resultsByRelatedKey = $ this -> getResultsByRelatedKey ( $ data ) ; return $ this -> seed ( $ rows , $ resultsByRelatedKey , $ name ) ; }
Loads the relationship content with the provided data
46,175
public static function existing ( $ all = false , $ translate = false ) { if ( empty ( self :: $ items ) ) { $ db = App :: get ( 'db' ) ; $ query = $ db -> getQuery ( ) -> select ( 'a.lang_code' , 'value' ) -> select ( 'a.title' , 'text' ) -> select ( 'a.title_native' ) -> from ( '#__languages' , 'a' ) -> where ( 'a.published' , '>=' , '0' ) -> order ( 'a.title' , 'asc' ) ; $ db -> setQuery ( $ query -> toString ( ) ) ; self :: $ items = $ db -> loadObjectList ( ) ; if ( $ all ) { array_unshift ( self :: $ items , new Obj ( array ( 'value' => '*' , 'text' => $ translate ? Lang :: alt ( 'JALL' , 'language' ) : 'JALL_LANGUAGE' ) ) ) ; } if ( $ db -> getErrorNum ( ) ) { throw new RuntimeException ( $ db -> getErrorMsg ( ) , 500 , E_WARNING ) ; } } return self :: $ items ; }
Get a list of the available content language items .
46,176
private function isValidExtension ( $ extension , $ base ) { $ ext = explode ( '_' , $ extension ) ; $ dir = '' ; switch ( $ ext [ 0 ] ) { case 'com' : $ dir = $ base . DS . 'components' . DS . $ extension ; break ; case 'mod' : $ dir = $ base . DS . 'modules' . DS . $ extension ; break ; case 'plg' : $ dir = $ base . DS . 'plugins' . DS . $ ext [ 1 ] . DS . $ ext [ 2 ] ; break ; default : return false ; break ; } return ( is_dir ( $ dir ) ) ? true : false ; }
Simple helper function to check validity of provided extension name
46,177
private function showCreateTable ( $ tableName ) { $ prefix = App :: get ( 'db' ) -> getPrefix ( ) ; $ create = App :: get ( 'db' ) -> getTableCreate ( $ tableName ) ; $ create = $ create [ $ tableName ] ; $ create = str_replace ( "CREATE TABLE `{$prefix}" , 'CREATE TABLE `#__' , $ create ) ; $ create = str_replace ( "\n" , "\n\t\t\t\t" , $ create ) ; $ create = preg_replace ( '/(AUTO_INCREMENT=)([0-9]*)/' , '${1}0' , $ create ) ; return $ create ; }
Get table creation string
46,178
public function addFilter ( $ name , $ query = array ( ) , $ tag = 'root_type' ) { $ this -> adapter -> addFilter ( $ name , $ query , $ tag ) ; return $ this ; }
Adds a filter to the query
46,179
public static function getXDomainId ( $ domain ) { $ db = \ App :: get ( 'db' ) ; if ( empty ( $ domain ) || ( $ domain == 'hubzero' ) ) { return false ; } $ query = 'SELECT domain_id FROM `#__xdomains` WHERE domain=' . $ db -> quote ( $ domain ) . ';' ; $ db -> setQuery ( $ query ) ; $ result = $ db -> loadObject ( ) ; if ( empty ( $ result ) ) { return false ; } return $ result -> domain_id ; }
Get domain ID
46,180
public static function getXDomainUserId ( $ domain_username , $ domain ) { $ db = \ App :: get ( 'db' ) ; if ( empty ( $ domain ) || ( $ domain == 'hubzero' ) ) { return $ domain_username ; } $ query = 'SELECT uidNumber FROM #__xdomain_users,#__xdomains WHERE ' . '#__xdomains.domain_id=#__xdomain_users.domain_id AND ' . '#__xdomains.domain=' . $ db -> quote ( $ domain ) . ' AND ' . '#__xdomain_users.domain_username=' . $ db -> quote ( $ domain_username ) ; $ db -> setQuery ( $ query ) ; $ result = $ db -> loadObject ( ) ; if ( empty ( $ result ) ) { return false ; } return $ result -> uidNumber ; }
Get domain user ID
46,181
public static function deleteXDomainUserId ( $ id ) { $ db = \ App :: get ( 'db' ) ; if ( empty ( $ id ) ) { return false ; } $ id = intval ( $ id ) ; if ( $ id <= 0 ) { return false ; } $ query = 'DELETE FROM `#__xdomain_users` WHERE uidNumber=' . $ db -> quote ( $ id ) . ';' ; $ db -> setQuery ( $ query ) ; $ db -> query ( ) ; return true ; }
Delete a record by user ID
46,182
public static function isXDomainUser ( $ uid ) { $ db = \ App :: get ( 'db' ) ; $ query = 'SELECT uidNumber FROM `#__xdomain_users` WHERE #__xdomain_users.uidNumber=' . $ db -> quote ( $ uid ) ; $ db -> setQuery ( $ query ) ; $ result = $ db -> loadObject ( ) ; if ( empty ( $ result ) ) { return false ; } return true ; }
Check if a user has a domain record
46,183
public static function createXDomain ( $ domain ) { $ db = \ App :: get ( 'db' ) ; if ( empty ( $ domain ) || ( $ domain == 'hubzero' ) ) { return false ; } $ query = 'SELECT domain_id FROM `#__xdomains` WHERE ' . '#__xdomains.domain=' . $ db -> quote ( $ domain ) ; $ db -> setQuery ( $ query ) ; $ result = $ db -> loadObject ( ) ; if ( empty ( $ result ) ) { $ query = 'INSERT INTO `#__xdomains` (domain) VALUES (' . $ db -> quote ( $ domain ) . ')' ; $ db -> setQuery ( $ query ) ; $ db -> query ( ) ; $ domain_id = $ db -> insertid ( ) ; } else { $ domain_id = $ result -> domain_id ; } return $ domain_id ; }
Creeate a domain record
46,184
public static function mapXDomainUser ( $ domain_username , $ domain , $ uidNumber ) { $ db = \ App :: get ( 'db' ) ; if ( empty ( $ domain ) ) { return 0 ; } $ query = 'SELECT domain_id FROM `#__xdomains` WHERE ' . '#__xdomains.domain=' . $ db -> quote ( $ domain ) ; $ db -> setQuery ( $ query ) ; $ result = $ db -> loadObject ( ) ; if ( empty ( $ result ) ) { $ query = 'INSERT INTO `#__xdomains` (domain) VALUES (' . $ db -> quote ( $ domain ) . ')' ; $ db -> setQuery ( $ query ) ; $ db -> query ( ) ; $ domain_id = $ db -> insertid ( ) ; } else { $ domain_id = $ result -> domain_id ; } $ query = 'INSERT INTO `#__xdomain_users` (domain_id,domain_username,uidNumber) ' . ' VALUES (' . $ db -> quote ( $ domain_id ) . ',' . $ db -> quote ( $ domain_username ) . ',' . $ db -> quote ( $ uidNumber ) . ')' ; $ db -> setQuery ( $ query ) ; if ( ! $ db -> query ( ) ) { return false ; } return true ; }
Map a domain to a user
46,185
public static function getGroups ( $ uid , $ type = 'all' , $ cat = null ) { $ db = \ App :: get ( 'db' ) ; $ g = '' ; if ( $ cat == 1 ) { $ g .= "(g.type='" . $ cat . "' OR g.type='3') AND" ; } elseif ( $ cat !== null ) { $ g .= "g.type=" . $ db -> quote ( $ cat ) . " AND " ; } $ query1 = "SELECT g.gidNumber, g.published, g.approved, g.cn, g.description, g.join_policy, '1' AS registered, '0' AS regconfirmed, '0' AS manager FROM #__xgroups AS g, #__xgroups_applicants AS m WHERE $g m.gidNumber=g.gidNumber AND m.uidNumber=" . $ uid ; $ query2 = "SELECT g.gidNumber, g.published, g.approved, g.cn, g.description, g.join_policy, '1' AS registered, '1' AS regconfirmed, '0' AS manager FROM #__xgroups AS g, #__xgroups_members AS m WHERE $g m.gidNumber=g.gidNumber AND m.uidNumber=" . $ uid ; $ query3 = "SELECT g.gidNumber, g.published, g.approved, g.cn, g.description, g.join_policy, '1' AS registered, '1' AS regconfirmed, '1' AS manager FROM #__xgroups AS g, #__xgroups_managers AS m WHERE $g m.gidNumber=g.gidNumber AND m.uidNumber=" . $ uid ; $ query4 = "SELECT g.gidNumber, g.published, g.approved, g.cn, g.description, g.join_policy, '0' AS registered, '1' AS regconfirmed, '0' AS manager FROM #__xgroups AS g, #__xgroups_invitees AS m WHERE $g m.gidNumber=g.gidNumber AND m.uidNumber=" . $ uid ; switch ( $ type ) { case 'all' : $ query = "( $query1 ) UNION ( $query2 ) UNION ( $query3 ) UNION ( $query4 )" ; break ; case 'applicants' : $ query = $ query1 . " ORDER BY description, cn" ; break ; case 'members' : $ query = $ query2 . " ORDER BY description, cn" ; break ; case 'managers' : $ query = $ query3 . " ORDER BY description, cn" ; break ; case 'invitees' : $ query = $ query4 . " ORDER BY description, cn" ; break ; } $ db -> setQuery ( $ query ) ; $ result = $ db -> loadObjectList ( ) ; if ( empty ( $ result ) ) { return false ; } return $ result ; }
Get a list of groups for a user
46,186
public static function removeUserFromGroups ( $ uid ) { $ db = \ App :: get ( 'db' ) ; $ tables = array ( '#__xgroups_members' , '#__xgroups_managers' , '#__xgroups_invitees' , '#__xgroups_applicants' ) ; foreach ( $ tables as $ table ) { $ sql = "DELETE FROM `" . $ table . "` WHERE uidNumber=" . $ db -> quote ( $ uid ) ; $ db -> setQuery ( $ sql ) ; $ db -> query ( ) ; } return true ; }
Remove User From Groups
46,187
public static function getCommonGroups ( $ uid , $ pid ) { $ xgroups = self :: getGroups ( $ uid , 'all' , 1 ) ; $ usersgroups = array ( ) ; if ( ! empty ( $ xgroups ) ) { foreach ( $ xgroups as $ group ) { if ( $ group -> regconfirmed ) { $ usersgroups [ ] = $ group -> cn ; } } } $ pgroups = self :: getGroups ( $ pid , 'all' , 1 ) ; $ profilesgroups = array ( ) ; if ( ! empty ( $ pgroups ) ) { foreach ( $ pgroups as $ group ) { if ( $ group -> regconfirmed ) { $ profilesgroups [ ] = $ group -> cn ; } } } return array_intersect ( $ usersgroups , $ profilesgroups ) ; }
Get common groups between two users
46,188
private function traverse ( $ request , $ data ) { if ( is_array ( $ data ) ) { foreach ( $ data as $ key => $ value ) { $ data [ $ key ] = $ this -> convert ( $ request , $ key , $ value ) ; } } else if ( is_object ( $ data ) ) { foreach ( array_keys ( get_object_vars ( $ data ) ) as $ key ) { $ data -> $ key = $ this -> convert ( $ request , $ key , $ data -> $ key ) ; } } return $ data ; }
Look for keys in data and convert found values
46,189
private function convert ( $ request , $ key , $ value ) { if ( is_array ( $ value ) || is_object ( $ value ) ) { return $ this -> traverse ( $ request , $ value ) ; } if ( ! in_array ( $ key , $ this -> keys , true ) ) { return $ value ; } if ( substr ( $ value , 0 , 4 ) == 'http' ) { return $ value ; } return rtrim ( str_replace ( '/api' , '' , $ request -> root ( ) ) , '/' ) . '/' . ltrim ( $ value , '/' ) ; }
Convert a URI
46,190
public function setImageType ( $ type ) { if ( $ type ) { $ this -> image_type = $ type ; } if ( $ this -> image_type == IMAGETYPE_PNG && $ this -> resource ) { imagealphablending ( $ this -> resource , false ) ; imagesavealpha ( $ this -> resource , true ) ; } }
Set the image type
46,191
private function checkPackageRequirements ( $ package = '' ) { if ( $ package == '' ) { return false ; } $ installed_exts = get_loaded_extensions ( ) ; if ( ! in_array ( $ package , $ installed_exts ) ) { $ this -> setError ( \ Lang :: txt ( '[ERROR] You are missing the required PHP package %s.' , $ package ) ) ; return false ; } return true ; }
Check if a required package is installed
46,192
public function getGeoLocation ( ) { if ( ! $ this -> checkPackageRequirements ( 'exif' ) ) { $ this -> setError ( \ Lang :: txt ( 'You need the PHP exif library installed to rotate image based on Exif Orientation value.' ) ) ; return false ; } try { $ this -> exif_data = exif_read_data ( $ this -> source ) ; } catch ( Exception $ e ) { $ this -> exif_data = array ( ) ; } if ( isset ( $ this -> exif_data [ 'GPSLatitude' ] ) ) { $ lat = $ this -> exif_data [ 'GPSLatitude' ] ; $ lat_dir = $ this -> exif_data [ 'GPSLatitudeRef' ] ; $ long = $ this -> exif_data [ 'GPSLongitude' ] ; $ long_dir = $ this -> exif_data [ 'GPSLongitudeRef' ] ; $ latitude = $ this -> geo_single_fracs2dec ( $ lat ) ; $ longitude = $ this -> geo_single_fracs2dec ( $ long ) ; $ latitude_formatted = $ this -> geo_pretty_fracs2dec ( $ lat ) . $ lat_dir ; $ longitude_formatted = $ this -> geo_pretty_fracs2dec ( $ long ) . $ long_dir ; if ( $ lat_dir == 'S' ) { $ latitude *= - 1 ; } if ( $ long_dir == 'W' ) { $ longitude *= - 1 ; } $ geo = array ( 'latitude' => $ latitude , 'longitude' => $ longitude , 'latitude_formatted' => $ latitude_formatted , 'longitude_formatted' => $ longitude_formatted ) ; } else { $ geo = array ( ) ; } return $ geo ; }
Image Geo Location Data
46,193
private function geo_frac2dec ( $ str ) { list ( $ n , $ d ) = explode ( '/' , $ str ) ; if ( ! empty ( $ d ) ) { return $ n / $ d ; } return $ str ; }
Convert a fraction to decimal
46,194
private function geo_pretty_fracs2dec ( $ fracs ) { return $ this -> geo_frac2dec ( $ fracs [ 0 ] ) . '&deg; ' . $ this -> geo_frac2dec ( $ fracs [ 1 ] ) . '&prime; ' . $ this -> geo_frac2dec ( $ fracs [ 2 ] ) . '&Prime; ' ; }
Convert fractions to decimals with formatting
46,195
private function geo_single_fracs2dec ( $ fracs ) { return $ this -> geo_frac2dec ( $ fracs [ 0 ] ) + $ this -> geo_frac2dec ( $ fracs [ 1 ] ) / 60 + $ this -> geo_frac2dec ( $ fracs [ 2 ] ) / 3600 ; }
Convert fractions to decimals
46,196
public function inline ( ) { ob_start ( ) ; $ this -> output ( null ) ; $ image_data = ob_get_contents ( ) ; ob_end_clean ( ) ; $ base64 = base64_encode ( $ image_data ) ; $ image_atts = getimagesize ( $ this -> source ) ; return 'data:' . $ image_atts [ 'mime' ] . ';base64,' . $ base64 ; }
Display an image inline
46,197
private function output ( $ save_path ) { if ( $ this -> resource != null ) { switch ( $ this -> image_type ) { case IMAGETYPE_PNG : imagepng ( $ this -> resource , $ save_path ) ; break ; case IMAGETYPE_GIF : imagegif ( $ this -> resource , $ save_path ) ; break ; case IMAGETYPE_JPEG : imagejpeg ( $ this -> resource , $ save_path ) ; break ; } } }
Generate an image and save to a location
46,198
public function write ( $ contents , $ group , $ client = null ) { $ path = $ this -> getPath ( $ client , $ group ) ; if ( ! $ path ) { return false ; } $ contents = $ this -> toContent ( $ contents , $ this -> format , $ this -> options ) ; return ! ( $ this -> putContent ( $ path , $ contents ) === false ) ; }
Create a new file configuration loader .
46,199
private function getPath ( $ client , $ group ) { $ path = $ this -> path ; if ( is_null ( $ path ) ) { return null ; } $ file = $ path . DIRECTORY_SEPARATOR . ( $ client ? $ client . DIRECTORY_SEPARATOR : '' ) . $ group . '.' . $ this -> format ; return $ file ; }
Generate the path to write