idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
46,800
public function add ( $ passhash = null , $ invalidated = null ) { $ db = \ App :: get ( 'db' ) ; if ( empty ( $ db ) ) { return false ; } if ( empty ( $ passhash ) ) { $ passhash = null ; } if ( empty ( $ invalidated ) ) { $ invalidated = "UTC_TIMESTAMP()" ; } else { $ invalidated = $ db -> quote ( $ invalidated ) ; } $ user_id = $ this -> user_id ; $ query = "INSERT INTO `#__users_password_history` (user_id," . "passhash,invalidated)" . " VALUES ( " . $ db -> quote ( $ user_id ) . "," . $ db -> quote ( $ passhash ) . "," . $ invalidated . ");" ; $ db -> setQuery ( $ query ) ; $ result = $ db -> query ( ) ; if ( $ result !== false || $ db -> getErrorNum ( ) == 1062 ) { return true ; } return false ; }
Add a passhash to a user s history
46,801
public function exists ( $ password = null , $ since = null ) { $ db = \ App :: get ( 'db' ) ; if ( empty ( $ db ) ) { return false ; } $ query = "SELECT `passhash` FROM `#__users_password_history` WHERE user_id = " . $ db -> quote ( $ this -> user_id ) ; if ( ! empty ( $ since ) ) { $ query .= " AND invalidated >= " . $ db -> quote ( $ since ) ; } $ db -> setQuery ( $ query ) ; $ results = $ db -> loadObjectList ( ) ; if ( $ results && count ( $ results ) > 0 ) { foreach ( $ results as $ result ) { $ compare = \ Hubzero \ User \ Password :: comparePasswords ( $ result -> passhash , $ password ) ; if ( $ compare ) { return true ; } } } return false ; }
Check if a password exists for a user
46,802
public function remove ( $ passhash , $ timestamp ) { if ( $ this -> user_id <= 0 ) { return false ; } $ db = \ App :: get ( 'db' ) ; if ( empty ( $ db ) ) { return false ; } $ db -> setQuery ( "DELETE FROM `#__users_password_history` WHERE user_id= " . $ db -> quote ( $ this -> user_id ) . " AND passhash = " . $ db -> quote ( $ passhash ) . " AND invalidated = " . $ db -> quote ( $ timestamp ) . ";" ) ; if ( ! $ db -> query ( ) ) { return false ; } return true ; }
Remove a passhash from a user s history
46,803
public static function addPassword ( $ passhash , $ user = null ) { $ hzuph = self :: getInstance ( $ user ) ; $ hzuph -> add ( $ passhash ) ; return true ; }
Shortcut helper method for adding a password to a user s history
46,804
public static function isWatching ( $ item_id , $ item_type , $ created_by ) { if ( $ item_id && $ item_type && $ created_by ) { $ total = self :: all ( ) -> whereEquals ( 'state' , 1 ) -> whereEquals ( 'created_by' , ( int ) $ created_by ) -> whereEquals ( 'item_id' , ( int ) $ item_id ) -> whereEquals ( 'item_type' , ( string ) $ item_type ) -> total ( ) ; if ( $ total ) { return true ; } } return false ; }
Is user watching item?
46,805
public function getExtension ( $ mimetype ) { $ key = array_search ( $ mimetype , $ this -> mimeTypes ) ; if ( ! $ key ) { $ key = '' ; } return $ key ; }
Retrieve the corresponding file extension for a given MIME type if one exists
46,806
private function _getExtension ( $ file = null ) { if ( ! is_null ( $ file ) ) { $ dot = strrpos ( $ file , '.' ) + 1 ; return strtolower ( substr ( $ file , $ dot ) ) ; } return '##INVALID_FILE##' ; }
Gets the file extension from a string
46,807
public static function getFavicon ( $ url , $ attributes = [ ] ) { $ attr = trim ( self :: arrayToString ( $ attributes ) ) ; if ( ! empty ( $ attr ) ) { $ attr = " $attr" ; } return sprintf ( '<img src="https://www.google.com/s2/favicons?domain=%s"%s/>' , urlencode ( $ url ) , $ attr ) ; }
Get a Website favicon image .
46,808
public static function getQRcode ( $ string , $ width = 150 , $ height = 150 , $ attributes = [ ] ) { $ protocol = 'http://' ; if ( self :: isHttps ( ) ) { $ protocol = 'https://' ; } $ attr = trim ( self :: arrayToString ( $ attributes ) ) ; $ apiUrl = $ protocol . 'chart.apis.google.com/chart?chs=' . $ width . 'x' . $ height . '&cht=qr&chl=' . urlencode ( $ string ) ; return '<img src="' . $ apiUrl . '" ' . $ attr . ' />' ; }
Get a QR code .
46,809
public static function getGravatar ( $ email , $ size = 80 , $ default = 'mm' , $ rating = 'g' , $ attributes = [ ] ) { $ attr = trim ( self :: arrayToString ( $ attributes ) ) ; $ url = 'https://www.gravatar.com/' ; return sprintf ( '<img src="%savatar.php?gravatar_id=%s&default=%s&size=%s&rating=%s" width="%spx" height="%spx" %s />' , $ url , md5 ( strtolower ( trim ( $ email ) ) ) , $ default , $ size , $ rating , $ size , $ size , $ attr ) ; }
Get a Gravatar for email .
46,810
public static function createLinkTag ( $ link , $ text = '' , $ attributes = [ ] ) { $ linkTag = '<a href="' . str_replace ( [ '"' , "'" ] , [ urlencode ( '"' ) , urlencode ( "'" ) ] , $ link ) . '"' ; if ( self :: validateEmail ( $ link ) ) { $ linkTag = '<a href="mailto:' . $ link . '"' ; } if ( ! isset ( $ attributes [ 'title' ] ) && ! empty ( $ text ) ) { $ linkTag .= ' title="' . str_replace ( '"' , '' , strip_tags ( $ text ) ) . '" ' ; } if ( empty ( $ text ) ) { $ text = $ link ; } $ attr = trim ( self :: arrayToString ( $ attributes ) ) ; $ linkTag .= $ attr . '>' . htmlspecialchars ( $ text , ENT_QUOTES , 'UTF-8' ) . '</a>' ; return $ linkTag ; }
Create HTML A Tag .
46,811
public static function validateEmail ( $ address , $ tempEmailAllowed = true ) { strpos ( $ address , '@' ) ? list ( , $ mailDomain ) = explode ( '@' , $ address ) : $ mailDomain = null ; if ( filter_var ( $ address , FILTER_VALIDATE_EMAIL ) && ! is_null ( $ mailDomain ) && checkdnsrr ( $ mailDomain , 'MX' ) ) { if ( $ tempEmailAllowed ) { return true ; } else { $ handle = fopen ( __DIR__ . '/banned.txt' , 'r' ) ; $ temp = [ ] ; while ( ( $ line = fgets ( $ handle ) ) !== false ) { $ temp [ ] = trim ( $ line ) ; } if ( in_array ( $ mailDomain , $ temp ) ) { return false ; } return true ; } } return false ; }
Validate Email address .
46,812
public static function rssReader ( $ url ) { if ( strpos ( $ url , 'http' ) !== 0 ) { $ url = 'http://' . $ url ; } $ feed = self :: curl ( $ url ) ; $ xml = simplexml_load_string ( $ feed , 'SimpleXMLElement' , LIBXML_NOCDATA ) ; return self :: objectToArray ( $ xml ) ; }
Read RSS feed as array . requires simplexml .
46,813
public static function arrayToObject ( array $ array = [ ] ) { if ( ! is_array ( $ array ) ) { throw new \ Exception ( 'Not an array' ) ; } $ object = new \ stdClass ( ) ; if ( is_array ( $ array ) && count ( $ array ) > 0 ) { foreach ( $ array as $ name => $ value ) { if ( is_array ( $ value ) ) { $ object -> { $ name } = self :: arrayToObject ( $ value ) ; } else { $ object -> { $ name } = $ value ; } } } return $ object ; }
Convert array to the object .
46,814
public static function arrayToString ( array $ array = [ ] , $ delimiter = ' ' ) { $ pairs = [ ] ; foreach ( $ array as $ key => $ value ) { $ pairs [ ] = "$key=\"$value\"" ; } return implode ( $ delimiter , $ pairs ) ; }
Convert Array to string .
46,815
public static function hex2rgb ( $ color ) { $ color = str_replace ( '#' , '' , $ color ) ; $ hex = strlen ( $ color ) == 3 ? [ $ color [ 0 ] . $ color [ 0 ] , $ color [ 1 ] . $ color [ 1 ] , $ color [ 2 ] . $ color [ 2 ] ] : [ $ color [ 0 ] . $ color [ 1 ] , $ color [ 2 ] . $ color [ 3 ] , $ color [ 4 ] . $ color [ 5 ] ] ; list ( $ r , $ g , $ b ) = $ hex ; return sprintf ( 'rgb(%s, %s, %s)' , hexdec ( $ r ) , hexdec ( $ g ) , hexdec ( $ b ) ) ; }
Takes HEX color code value and converts to a RGB value .
46,816
public static function generateRandomPassword ( $ length = 8 , $ customAlphabet = null ) { $ pass = [ ] ; if ( strlen ( trim ( $ customAlphabet ) ) ) { $ alphabet = trim ( $ customAlphabet ) ; } else { $ alphabet = 'abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789' ; } $ alphaLength = strlen ( $ alphabet ) - 1 ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ n = rand ( 0 , $ alphaLength ) ; $ pass [ ] = $ alphabet [ $ n ] ; } return implode ( $ pass ) ; }
Generate Simple Random Password .
46,817
public static function simpleEncode ( $ string , $ passkey = null ) { $ key = $ passkey ; if ( ! isset ( $ passkey ) || empty ( $ passkey ) ) { $ key = self :: generateServerSpecificHash ( ) ; } $ result = '' ; for ( $ i = 0 ; $ i < strlen ( $ string ) ; $ i ++ ) { $ char = substr ( $ string , $ i , 1 ) ; $ keychar = substr ( $ key , ( $ i % strlen ( $ key ) ) - 1 , 1 ) ; $ char = chr ( ord ( $ char ) + ord ( $ keychar ) ) ; $ result .= $ char ; } return base64_encode ( $ result ) ; }
Simple Encode string .
46,818
public static function generateServerSpecificHash ( ) { return ( isset ( $ _SERVER [ 'SERVER_NAME' ] ) && ! empty ( $ _SERVER [ 'SERVER_NAME' ] ) ) ? md5 ( $ _SERVER [ 'SERVER_NAME' ] ) : md5 ( pathinfo ( __FILE__ , PATHINFO_FILENAME ) ) ; }
Generate Server Specific hash .
46,819
public static function getClientLocation ( ) { $ result = false ; $ ip_data = @ json_decode ( self :: curl ( 'http://www.geoplugin.net/json.gp?ip=' . self :: getClientIP ( ) ) ) ; if ( isset ( $ ip_data ) && $ ip_data -> geoplugin_countryName != null ) { $ result = $ ip_data -> geoplugin_city . ', ' . $ ip_data -> geoplugin_countryCode ; } return $ result ; }
Get client location .
46,820
public static function secondsToText ( $ seconds , $ returnAsWords = false ) { $ periods = [ 'year' => 3.156e+7 , 'month' => 2.63e+6 , 'week' => 604800 , 'day' => 86400 , 'hour' => 3600 , 'minute' => 60 , 'second' => 1 , ] ; $ parts = [ ] ; foreach ( $ periods as $ name => $ dur ) { $ div = floor ( $ seconds / $ dur ) ; if ( $ div == 0 ) { continue ; } if ( $ div == 1 ) { $ parts [ ] = ( $ returnAsWords ? self :: numberToWord ( $ div ) : $ div ) . ' ' . $ name ; } else { $ parts [ ] = ( $ returnAsWords ? self :: numberToWord ( $ div ) : $ div ) . ' ' . $ name . 's' ; } $ seconds %= $ dur ; } $ last = array_pop ( $ parts ) ; if ( empty ( $ parts ) ) { return $ last ; } return implode ( ', ' , $ parts ) . ' and ' . $ last ; }
Convert seconds to real time .
46,821
public static function curl ( $ url , $ method = 'GET' , $ data = false , $ headers = false , $ returnInfo = false , $ auth = false ) { $ ch = curl_init ( ) ; $ info = null ; if ( strtoupper ( $ method ) == 'POST' ) { curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_POST , true ) ; if ( $ data !== false ) { curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ data ) ; } } else { if ( $ data !== false ) { if ( is_array ( $ data ) ) { $ dataTokens = [ ] ; foreach ( $ data as $ key => $ value ) { array_push ( $ dataTokens , urlencode ( $ key ) . '=' . urlencode ( $ value ) ) ; } $ data = implode ( '&' , $ dataTokens ) ; } curl_setopt ( $ ch , CURLOPT_URL , $ url . '?' . $ data ) ; } else { curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; } } curl_setopt ( $ ch , CURLOPT_HEADER , false ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_FOLLOWLOCATION , true ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , 10 ) ; if ( $ headers !== false ) { curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ headers ) ; } if ( $ auth !== false && strlen ( $ auth [ 'username' ] ) > 0 && strlen ( $ auth [ 'password' ] ) > 0 ) { curl_setopt ( $ ch , CURLOPT_USERPWD , $ auth [ 'username' ] . ':' . $ auth [ 'password' ] ) ; } $ contents = curl_exec ( $ ch ) ; if ( $ returnInfo ) { $ info = curl_getinfo ( $ ch ) ; } curl_close ( $ ch ) ; if ( $ returnInfo ) { return [ 'contents' => $ contents , 'info' => $ info ] ; } return $ contents ; }
Make a Curl call .
46,822
public static function expandShortUrl ( $ shortURL ) { if ( empty ( $ shortURL ) ) { return false ; } $ headers = get_headers ( $ shortURL , 1 ) ; if ( isset ( $ headers [ 'Location' ] ) ) { return $ headers [ 'Location' ] ; } $ data = self :: curl ( $ shortURL ) ; preg_match_all ( '/<[\s]*meta[\s]*http-equiv="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si' , $ data , $ match ) ; if ( isset ( $ match ) && is_array ( $ match ) && count ( $ match ) == 3 ) { $ originals = $ match [ 0 ] ; $ names = $ match [ 1 ] ; $ values = $ match [ 2 ] ; if ( ( isset ( $ originals ) && isset ( $ names ) && isset ( $ values ) ) && count ( $ originals ) == count ( $ names ) && count ( $ names ) == count ( $ values ) ) { $ metaTags = [ ] ; for ( $ i = 0 , $ limit = count ( $ names ) ; $ i < $ limit ; $ i ++ ) { $ metaTags [ $ names [ $ i ] ] = [ 'html' => htmlentities ( $ originals [ $ i ] ) , 'value' => $ values [ $ i ] ] ; } } } if ( isset ( $ metaTags [ 'refresh' ] [ 'value' ] ) && ! empty ( $ metaTags [ 'refresh' ] [ 'value' ] ) ) { $ returnData = explode ( '=' , $ metaTags [ 'refresh' ] [ 'value' ] ) ; if ( isset ( $ returnData [ 1 ] ) && ! empty ( $ returnData [ 1 ] ) ) { return $ returnData [ 1 ] ; } } return false ; }
Get information on a short URL . Find out where it forwards .
46,823
public static function getAlexaRank ( $ domain ) { $ domain = preg_replace ( '~^https?://~' , '' , $ domain ) ; $ alexa = 'http://data.alexa.com/data?cli=10&dat=s&url=%s' ; $ request_url = sprintf ( $ alexa , urlencode ( $ domain ) ) ; $ xml = simplexml_load_file ( $ request_url ) ; if ( ! isset ( $ xml -> SD [ 1 ] ) ) { return false ; } $ nodeAttributes = $ xml -> SD [ 1 ] -> POPULARITY -> attributes ( ) ; $ text = ( int ) $ nodeAttributes [ 'TEXT' ] ; return $ text ; }
Get Alexa ranking for a domain name .
46,824
public static function getKeywordSuggestionsFromGoogle ( $ keyword ) { $ data = self :: curl ( 'http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl=en-US&q=' . urlencode ( $ keyword ) ) ; if ( ( $ data = json_decode ( $ data , true ) ) !== null && ! empty ( $ data [ 1 ] ) ) { return $ data [ 1 ] ; } return false ; }
Get keyword suggestion from Google .
46,825
public static function wikiSearch ( $ keyword ) { $ apiurl = 'http://wikipedia.org/w/api.php?action=opensearch&search=' . urlencode ( $ keyword ) . '&format=xml&limit=1' ; $ data = self :: curl ( $ apiurl ) ; $ xml = simplexml_load_string ( $ data ) ; if ( ( string ) $ xml -> Section -> Item -> Description ) { $ array = [ ] ; $ array [ 'title' ] = ( string ) $ xml -> Section -> Item -> Text ; $ array [ 'description' ] = ( string ) $ xml -> Section -> Item -> Description ; $ array [ 'url' ] = ( string ) $ xml -> Section -> Item -> Url ; if ( isset ( $ xml -> Section -> Item -> Image ) ) { $ img = ( string ) $ xml -> Section -> Item -> Image -> attributes ( ) -> source ; $ array [ 'image' ] = str_replace ( '/50px-' , '/200px-' , $ img ) ; } return $ array ; } return false ; }
Search wikipedia .
46,826
public static function numberOfDaysInMonth ( $ month = 0 , $ year = 0 ) { if ( $ month < 1 or $ month > 12 ) { return 0 ; } if ( ! is_numeric ( $ year ) or strlen ( $ year ) != 4 ) { $ year = date ( 'Y' ) ; } if ( $ month == 2 ) { if ( $ year % 400 == 0 or ( $ year % 4 == 0 and $ year % 100 != 0 ) ) { return 29 ; } } $ days_in_month = [ 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] ; return $ days_in_month [ $ month - 1 ] ; }
Returns the number of days for the given month and year .
46,827
public static function bytesToHumanReadableSize ( $ size , $ precision = 2 ) { for ( $ i = 0 ; ( $ size / 1024 ) > 0.9 ; $ i ++ , $ size /= 1024 ) { } return round ( $ size , $ precision ) . ' ' . [ 'B' , 'KB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ] [ $ i ] ; }
Converts bytes to human readable size .
46,828
public function exists ( $ path ) { $ path = Util :: normalizePath ( $ path ) ; return ( bool ) $ this -> adapter -> exists ( $ path ) ; }
Determine if a file exists .
46,829
public function name ( $ path ) { $ path = Util :: normalizePath ( $ path ) ; return $ this -> adapter -> name ( $ path ) ; }
Extract the file name from a file path .
46,830
public function extension ( $ path ) { $ path = Util :: normalizePath ( $ path ) ; return $ this -> adapter -> extension ( $ path ) ; }
Extract the file extension from a file path .
46,831
public function type ( $ path ) { $ path = Util :: normalizePath ( $ path ) ; return $ this -> adapter -> type ( $ path ) ; }
Get the file type of a given file .
46,832
public function size ( $ path ) { $ path = Util :: normalizePath ( $ path ) ; return $ this -> adapter -> size ( $ path ) ; }
Get the file size of a given file .
46,833
public function lastModified ( $ path ) { $ path = Util :: normalizePath ( $ path ) ; return ( int ) $ this -> adapter -> lastModified ( $ path ) ; }
Get the file s last modification time .
46,834
public function isDirectory ( $ directory ) { $ directory = Util :: normalizePath ( $ directory ) ; return ( bool ) $ this -> adapter -> isDirectory ( $ directory ) ; }
Determine if the given path is a directory .
46,835
public function isWritable ( $ path ) { $ path = Util :: normalizePath ( $ path ) ; return ( bool ) $ this -> adapter -> isWritable ( $ path ) ; }
Determine if the given path is writable .
46,836
public function isFile ( $ file ) { $ file = Util :: normalizePath ( $ file ) ; return ( bool ) $ this -> adapter -> isFile ( $ file ) ; }
Determine if the given path is a file .
46,837
public function isSafe ( $ file ) { $ file = Util :: normalizePath ( $ file ) ; return ( bool ) $ this -> adapter -> isSafe ( $ file ) ; }
Run a virus scan against a file
46,838
public function listContents ( $ path , $ filter = '.' , $ recursive = false , $ full = false , $ exclude = array ( '.svn' , '.git' , 'CVS' , '.DS_Store' , '__MACOSX' ) ) { $ path = Util :: normalizePath ( $ path ) ; return ( array ) $ this -> adapter -> listContents ( $ path , $ filter , $ recursive , $ full , $ exclude ) ; }
Get all contents within a given directory .
46,839
public function addMacro ( MacroInterface $ macro ) { if ( ! method_exists ( $ macro , 'handle' ) ) { throw new \ LogicException ( sprintf ( '%s does not have a handle method.' , get_class ( $ macro ) ) ) ; } $ this -> macros [ $ macro -> getMethod ( ) ] = $ macro ; return $ this ; }
Register a macro .
46,840
public static function checkHoneypot ( $ name = null , $ delay = 3 ) { $ name = $ name ? : \ Hubzero \ Spam \ Honeypot :: getName ( ) ; if ( $ honey = self :: getVar ( $ name , array ( ) , 'post' ) ) { if ( ! \ Hubzero \ Spam \ Honeypot :: isValid ( $ honey [ 'p' ] , $ honey [ 't' ] , $ delay ) ) { if ( \ App :: has ( 'log' ) ) { $ fallback = 'option=' . self :: getCmd ( 'option' ) . '&controller=' . self :: getCmd ( 'controller' ) . '&task=' . self :: getCmd ( 'task' ) ; $ from = self :: getVar ( 'REQUEST_URI' , $ fallback , 'server' ) ; $ from = $ from ? : $ fallback ; \ App :: get ( 'log' ) -> logger ( 'spam' ) -> info ( 'spam honeypot ' . self :: ip ( ) . ' ' . \ User :: get ( 'id' ) . ' ' . \ User :: get ( 'username' ) . ' ' . $ from ) ; } return false ; } } return true ; }
Checks for a honeypot in the request
46,841
public function setXML ( & $ xml ) { if ( is_object ( $ xml ) ) { if ( $ group = $ xml [ 'group' ] ) { $ this -> _xml [ ( string ) $ group ] = $ xml ; } else { $ this -> _xml [ '_default' ] = $ xml ; } if ( $ dir = $ xml [ 'addpath' ] ) { $ this -> addElementPath ( PATH_ROOT . str_replace ( '/' , DS , ( string ) $ dir ) ) ; } } }
Sets the XML object from custom XML files .
46,842
public function render ( $ name = 'params' , $ group = '_default' ) { if ( ! isset ( $ this -> _xml [ $ group ] ) ) { return false ; } $ params = $ this -> getParams ( $ name , $ group ) ; $ html = array ( ) ; if ( $ description = $ this -> _xml [ $ group ] [ 'description' ] ) { $ html [ ] = '<p class="paramrow_desc">' . \ App :: get ( 'language' ) -> txt ( ( string ) $ description ) . '</p>' ; } foreach ( $ params as $ param ) { if ( $ param [ 0 ] ) { $ html [ ] = '<div class="input-wrap">' ; $ html [ ] = $ param [ 0 ] ; $ html [ ] = $ param [ 1 ] ; $ html [ ] = '</div>' ; } else { $ html [ ] = $ param [ 1 ] ; } } if ( count ( $ params ) < 1 ) { $ html [ ] = '<p class="noparams">' . \ App :: get ( 'language' ) -> txt ( 'JLIB_HTML_NO_PARAMETERS_FOR_THIS_ITEM' ) . '</p>' ; } return implode ( PHP_EOL , $ html ) ; }
Render the form control .
46,843
public function renderToArray ( $ name = 'params' , $ group = '_default' ) { if ( ! isset ( $ this -> _xml [ $ group ] ) ) { return false ; } $ results = array ( ) ; foreach ( $ this -> _xml [ $ group ] -> children ( ) as $ param ) { $ result = $ this -> getParam ( $ param , $ name , $ group ) ; $ results [ $ result [ 5 ] ] = $ result ; } return $ results ; }
Render all parameters to an array .
46,844
public function getNumParams ( $ group = '_default' ) { if ( ! isset ( $ this -> _xml [ $ group ] ) || ! count ( $ this -> _xml [ $ group ] -> children ( ) ) ) { return false ; } return count ( $ this -> _xml [ $ group ] -> children ( ) ) ; }
Return the number of parameters in a group .
46,845
public function getGroups ( ) { if ( ! is_array ( $ this -> _xml ) ) { return false ; } $ results = array ( ) ; foreach ( $ this -> _xml as $ name => $ group ) { $ results [ $ name ] = $ this -> getNumParams ( $ name ) ; } return $ results ; }
Get the number of params in each group .
46,846
public function getParams ( $ name = 'params' , $ group = '_default' ) { if ( ! isset ( $ this -> _xml [ $ group ] ) ) { return false ; } $ results = array ( ) ; foreach ( $ this -> _xml [ $ group ] -> children ( ) as $ param ) { $ results [ ] = $ this -> getParam ( $ param , $ name , $ group ) ; } return $ results ; }
Render all parameters .
46,847
public function getParam ( & $ node , $ control_name = 'params' , $ group = '_default' ) { $ type = ( string ) $ node [ 'type' ] ; $ element = $ this -> loadElement ( $ type ) ; if ( $ element === false ) { $ result = array ( ) ; $ result [ 0 ] = ( string ) $ node [ 'name' ] ; $ result [ 1 ] = \ App :: get ( 'language' ) -> txt ( 'Element not defined for type' ) . ' = ' . $ type ; $ result [ 5 ] = $ result [ 0 ] ; return $ result ; } $ value = $ this -> get ( ( string ) $ node [ 'name' ] , ( string ) $ node [ 'default' ] , $ group ) ; return $ element -> render ( $ node , $ value , $ control_name ) ; }
Render a parameter type .
46,848
public function loadSetupFile ( $ path ) { $ result = false ; if ( $ path ) { if ( ! file_exists ( $ path ) ) { return $ result ; } $ xml = simplexml_load_file ( $ path ) ; if ( $ params = $ xml -> params ) { foreach ( $ params as $ param ) { $ this -> setXML ( $ param ) ; $ result = true ; } } } else { $ result = true ; } return $ result ; }
Loads an XML setup file and parses it .
46,849
public function loadElement ( $ type , $ new = false ) { if ( $ type == 'list' ) { $ type = 'select' ; } $ signature = md5 ( $ type ) ; if ( ( isset ( $ this -> _elements [ $ signature ] ) && ! ( $ this -> _elements [ $ signature ] instanceof __PHP_Incomplete_Class ) ) && $ new === false ) { return $ this -> _elements [ $ signature ] ; } $ elementClass = __NAMESPACE__ . '\\Parameter\\Element\\' . ucfirst ( $ type ) ; if ( ! class_exists ( $ elementClass ) ) { if ( isset ( $ this -> _elementPath ) ) { $ dirs = $ this -> _elementPath ; } else { $ dirs = array ( ) ; } preg_match ( '/^[A-Za-z0-9_-]+[A-Za-z0-9_\.-]*([\\\\\/][A-Za-z0-9_-]+[A-Za-z0-9_\.-]*)*$/' , str_replace ( '_' , DS , $ type ) . '.php' , $ matches ) ; $ file = @ ( string ) $ matches [ 0 ] ; if ( $ elementFile = \ App :: get ( 'filesystem' ) -> find ( $ dirs , $ file ) ) { include_once $ elementFile ; } else { $ false = false ; return $ false ; } } if ( ! class_exists ( $ elementClass ) ) { $ false = false ; return $ false ; } $ this -> _elements [ $ signature ] = new $ elementClass ( $ this ) ; return $ this -> _elements [ $ signature ] ; }
Loads an element type .
46,850
public function addElementPath ( $ path ) { settype ( $ path , 'array' ) ; foreach ( $ path as $ dir ) { $ dir = trim ( $ dir ) ; if ( substr ( $ dir , - 1 ) != DIRECTORY_SEPARATOR ) { $ dir .= DIRECTORY_SEPARATOR ; } array_unshift ( $ this -> _elementPath , $ dir ) ; } return $ this ; }
Add a directory where Parameter should search for element types .
46,851
protected function dir ( & $ name , $ default = '' ) { if ( substr ( $ name , 0 , 2 ) == './' ) { $ name = substr ( $ name , 2 ) ; return '' ; } if ( substr ( $ name , 0 , 1 ) == '/' ) { $ name = substr ( $ name , 1 ) ; return '/' ; } return $ default ; }
Determine the asset directory
46,852
public function setPath ( $ type , $ path ) { if ( ! array_key_exists ( $ type , $ this -> paths ) ) { throw new \ Exception ( \ App :: get ( 'language' ) -> txt ( 'Unknown asset path type of %s given.' , $ type ) ) ; } $ path = trim ( ( string ) $ path ) ; $ path = DS . trim ( $ path , DS ) ; $ this -> paths [ $ type ] = $ path ; return $ this ; }
Adds to the list of paths
46,853
public function overridePath ( ) { if ( ! isset ( $ this -> paths [ 'override' ] ) ) { $ this -> paths [ 'override' ] = \ App :: get ( 'template' ) -> path . DS . 'html' ; $ this -> paths [ 'override' ] .= DS . $ this -> extensionName ( ) . DS . ( $ this -> extensionType ( ) == 'system' ? $ this -> type ( ) . DS : '' ) . $ this -> file ( ) ; } return $ this -> paths [ 'override' ] ; }
Get the override path
46,854
public function targetPath ( ) { if ( ! isset ( $ this -> paths [ 'target' ] ) ) { if ( $ this -> declaration ) { $ this -> paths [ 'target' ] = '' ; } else { $ this -> paths [ 'target' ] = $ this -> sourcePath ( ) ; if ( $ this -> overridePath ( ) && file_exists ( $ this -> overridePath ( ) ) ) { $ this -> paths [ 'target' ] = $ this -> overridePath ( ) ; } } } return $ this -> paths [ 'target' ] ; }
Get the target path
46,855
public function lastModified ( ) { $ source = $ this -> targetPath ( ) ; if ( $ this -> declaration || ! is_file ( $ source ) ) { return 0 ; } return filemtime ( $ source ) ; }
Get the last modified time for a file
46,856
public function exists ( ) { if ( $ this -> isExternal ( ) ) { return true ; } if ( $ this -> declaration && $ this -> name ) { return true ; } if ( $ this -> targetPath ( ) && file_exists ( $ this -> targetPath ( ) ) ) { return true ; } return false ; }
Does asset exist?
46,857
public function link ( $ timestamp = true ) { $ output = $ this -> targetPath ( ) ; if ( ! $ output ) { return $ output ; } if ( $ this -> isExternal ( ) ) { return $ output ; } if ( $ this -> extensionType ( ) == 'system' ) { $ relative = rtrim ( str_replace ( '/administrator' , '' , \ Request :: base ( true ) ) , '/' ) . substr ( $ output , strlen ( PATH_ROOT ) ) ; } else { if ( strpos ( $ output , PATH_ROOT ) === 0 ) { $ relative = rtrim ( \ Request :: root ( true ) , '/' ) . rtrim ( substr ( $ output , strlen ( PATH_ROOT ) ) , '/' ) ; } else if ( strpos ( $ output , PATH_CORE ) === 0 ) { $ relative = rtrim ( \ Request :: root ( true ) , '/' ) . "/core/" . rtrim ( substr ( $ output , strlen ( PATH_CORE ) ) , '/' ) ; } } return $ relative . ( $ timestamp ? '?v=' . $ this -> lastModified ( ) : '' ) ; }
Get public asset path
46,858
public function contents ( ) { if ( $ this -> declaration ) { return $ this -> name ; } return file_exists ( $ this -> targetPath ( ) ) ? file_get_contents ( $ this -> targetPath ( ) ) : '' ; }
Get target asset s content
46,859
private function _relToAbs ( $ text ) { $ base = \ App :: get ( 'request' ) -> base ( ) ; $ text = preg_replace ( "/(href|src)=\"(?!http|ftp|https)([^\"]*)\"/" , "$1=\"$base\$2\"" , $ text ) ; return $ text ; }
Convert links in a text from relative to absolute
46,860
public function callback ( $ callback , $ func , $ args = array ( ) ) { if ( ! isset ( $ this -> callbacks [ $ callback ] ) ) { return false ; } return call_user_func_array ( array ( $ this -> callbacks [ $ callback ] , $ func ) , $ args ) ; }
Helper function for calling a given callback
46,861
public function getMWDBO ( ) { static $ instance ; if ( ! is_object ( $ instance ) ) { $ config = $ this -> getParams ( 'com_tools' ) ; $ options [ 'driver' ] = 'pdo' ; $ options [ 'host' ] = $ config -> get ( 'mwDBHost' ) ; $ options [ 'port' ] = $ config -> get ( 'mwDBPort' ) ; $ options [ 'user' ] = $ config -> get ( 'mwDBUsername' ) ; $ options [ 'password' ] = $ config -> get ( 'mwDBPassword' ) ; $ options [ 'database' ] = $ config -> get ( 'mwDBDatabase' ) ; $ options [ 'prefix' ] = $ config -> get ( 'mwDBPrefix' ) ; if ( ( ! isset ( $ options [ 'password' ] ) || $ options [ 'password' ] == '' ) && ( ! isset ( $ options [ 'user' ] ) || $ options [ 'user' ] == '' ) && ( ! isset ( $ options [ 'database' ] ) || $ options [ 'database' ] == '' ) ) { $ instance = $ this -> db ; } else { try { $ instance = Driver :: getInstance ( $ options ) ; } catch ( \ PDOException $ e ) { $ instance = null ; return false ; } } if ( ! $ instance -> connected ( ) ) { $ instance = null ; return false ; } } return $ instance ; }
Return a middleware database object
46,862
public function runAsRoot ( ) { if ( $ this -> protectedMode ) { return false ; } if ( $ creds = $ this -> getRootCredentials ( ) ) { $ db = Driver :: getInstance ( array ( 'driver' => ( \ Config :: get ( 'dbtype' ) == 'mysql' ) ? 'pdo' : \ Config :: get ( 'dbtype' ) , 'host' => \ Config :: get ( 'host' ) , 'user' => $ creds [ 'user' ] , 'password' => $ creds [ 'password' ] , 'database' => \ Config :: get ( 'db' ) , 'prefix' => \ Config :: get ( 'dbprefix' ) ) ) ; if ( ! $ db -> connected ( ) ) { return false ; } else { $ this -> db = $ db ; return true ; } } return false ; }
Try to run commands as MySql root user
46,863
public function getParams ( $ element , $ returnRaw = false ) { $ params = null ; if ( $ this -> baseDb -> tableExists ( '#__components' ) ) { if ( substr ( $ element , 0 , 4 ) == 'plg_' ) { $ ext = explode ( '_' , $ element ) ; $ query = "SELECT `params` FROM `#__plugins` WHERE `folder` = " . $ this -> baseDb -> quote ( $ ext [ 1 ] ) . " AND `element` = " . $ this -> baseDb -> quote ( $ ext [ 2 ] ) ; } else { $ query = "SELECT `params` FROM `#__components` WHERE `option` = " . $ this -> baseDb -> quote ( $ element ) ; } $ this -> baseDb -> setQuery ( $ query ) ; $ params = $ this -> baseDb -> loadResult ( ) ; } elseif ( $ this -> baseDb -> tableExists ( '#__extensions' ) ) { if ( substr ( $ element , 0 , 4 ) == 'plg_' ) { $ ext = explode ( '_' , $ element ) ; $ query = "SELECT `params` FROM `#__extensions` WHERE `folder` = " . $ this -> baseDb -> quote ( $ ext [ 1 ] ) . " AND `element` = " . $ this -> baseDb -> quote ( $ ext [ 2 ] ) ; } else { $ query = "SELECT `params` FROM `#__extensions` WHERE `element` = " . $ this -> baseDb -> quote ( $ element ) ; } $ this -> baseDb -> setQuery ( $ query ) ; $ params = $ this -> baseDb -> loadResult ( ) ; } else { $ this -> log ( sprintf ( 'Required table not found for retrieving "%s" params' , $ element ) , 'warning' ) ; } if ( ! $ returnRaw ) { if ( $ params ) { $ params = new Registry ( $ params ) ; } else { $ params = new Registry ( ) ; } } return $ params ; }
Get element params
46,864
public function normalizePluginEntry ( $ folder , $ element ) { if ( $ this -> baseDb -> tableExists ( '#__plugins' ) ) { $ folder = strtolower ( $ folder ) ; $ element = strtolower ( $ element ) ; $ name = ucfirst ( $ folder ) . ' - ' . ucfirst ( $ element ) ; return $ this -> renamePluginEntry ( $ folder , $ element , $ name ) ; } else if ( $ this -> baseDb -> tableExists ( '#__extensions' ) ) { $ folder = strtolower ( $ folder ) ; $ element = strtolower ( $ element ) ; $ name = 'plg_' . $ folder . '_' . $ element ; return $ this -> renamePluginEntry ( $ folder , $ element , $ name ) ; } }
Standardize a plugin entry name
46,865
public function renamePluginEntry ( $ folder , $ element , $ name ) { if ( $ this -> baseDb -> tableExists ( '#__plugins' ) ) { $ table = '#__plugins' ; $ pk = 'id' ; } else if ( $ this -> baseDb -> tableExists ( '#__extensions' ) ) { $ table = '#__extensions' ; $ pk = 'extension_id' ; } else { $ this -> log ( sprintf ( 'Required table not found for renaming plugin plg_%s_%s' , $ folder , $ element ) , 'warning' ) ; return false ; } $ folder = strtolower ( $ folder ) ; $ element = strtolower ( $ element ) ; $ query = "SELECT `{$pk}` FROM `{$table}` WHERE `folder` = '{$folder}' AND `element` = '{$element}'" ; $ this -> baseDb -> setQuery ( $ query ) ; if ( $ id = $ this -> baseDb -> loadResult ( ) ) { $ query = "UPDATE `{$table}` SET `name` = " . $ this -> baseDb -> quote ( $ name ) . " WHERE `{$pk}` = " . $ this -> baseDb -> quote ( $ id ) ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Renamed plugin plg_%s_%s to "%s"' , $ folder , $ element , $ name ) ) ; } return true ; }
Rename a plugin entry in the appropriate table depending on the CMS version
46,866
public function addModuleEntry ( $ element , $ enabled = 1 , $ params = '' , $ client = 0 ) { if ( $ this -> baseDb -> tableExists ( '#__extensions' ) ) { $ name = $ element ; $ query = "SELECT `extension_id` FROM `#__extensions` WHERE `name` = " . $ this -> baseDb -> quote ( $ name ) ; $ this -> baseDb -> setQuery ( $ query ) ; if ( $ this -> baseDb -> loadResult ( ) ) { $ this -> log ( sprintf ( 'Extension entry already exists for module "%s"' , $ element ) ) ; return true ; } $ ordering = 0 ; if ( ! empty ( $ params ) && is_array ( $ params ) ) { $ params = json_encode ( $ params ) ; } $ query = "INSERT INTO `#__extensions` (`name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `ordering`, `state`)" ; $ query .= " VALUES ('{$name}', 'module', '{$element}', '', {$client}, {$enabled}, 1, 0, '', " . $ this -> baseDb -> quote ( $ params ) . ", '', '', 0, {$ordering}, 0)" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Added extension entry for module "%s"' , $ element ) ) ; return true ; } $ this -> log ( sprintf ( 'Required table not found for adding module "%s"' , $ element ) , 'warning' ) ; return false ; }
Add as needed the module entry to the appropriate table depending on the CMS version
46,867
public function installModule ( $ module , $ position , $ always = true , $ params = '' , $ client = 0 , $ menus = 0 ) { $ title = $ this -> baseDb -> quote ( ucfirst ( $ module ) ) ; $ position = $ this -> baseDb -> quote ( $ position ) ; $ module = $ this -> baseDb -> quote ( 'mod_' . strtolower ( $ module ) ) ; $ client = $ this -> baseDb -> quote ( ( int ) $ client ) ; $ access = ( $ this -> baseDb -> tableExists ( '#__extensions' ) ) ? 1 : 0 ; if ( is_array ( $ params ) && ! $ this -> baseDb -> tableExists ( '#__extensions' ) ) { $ p = '' ; foreach ( $ params as $ k => $ v ) { $ p .= "{$k}={$v}\n" ; } $ params = $ this -> baseDb -> quote ( $ p ) ; } else { $ params = $ this -> baseDb -> quote ( json_encode ( $ params ) ) ; } if ( ! $ always ) { $ query = "SELECT `id` FROM `#__modules` WHERE `module` = {$module}" ; $ this -> db -> setQuery ( $ query ) ; if ( $ this -> db -> loadResult ( ) ) { return true ; } } $ query = "SELECT MAX(ordering) FROM `#__modules` WHERE `position` = {$position}" ; $ this -> baseDb -> setQuery ( $ query ) ; $ ordering = ( int ) ( ( $ this -> baseDb -> loadResult ( ) ) ? $ this -> baseDb -> loadResult ( ) + 1 : 0 ) ; $ query = "INSERT INTO `#__modules` " ; $ query .= "(`title` , `content`, `ordering` , `position` , `published`, `module` , `access` , `showtitle`, `params` , `client_id`) VALUES " ; $ query .= "({$title}, '' , {$ordering}, {$position}, 1 , {$module}, {$access}, 0 , {$params}, {$client} )" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ id = $ this -> baseDb -> quote ( $ this -> baseDb -> insertid ( ) ) ; $ menus = ( array ) $ menus ; foreach ( $ menus as $ menu ) { $ menu = $ this -> baseDb -> quote ( $ menu ) ; $ query = "INSERT INTO `#__modules_menu` (`moduleid`, `menuid`) VALUES ({$id}, {$menu})" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Added module_menu entry for module "%s" to menu "%s"' , $ module , $ menu ) ) ; } }
Instead of just adding to the extensions table install module in modules table
46,868
public function addTemplateEntry ( $ element , $ name = null , $ client = 1 , $ enabled = 1 , $ home = 0 , $ styles = null , $ protected = 0 ) { if ( $ this -> baseDb -> tableExists ( '#__extensions' ) ) { if ( ! isset ( $ name ) ) { if ( substr ( $ element , 0 , 4 ) == 'tpl_' ) { $ name = substr ( $ element , 4 ) ; $ element = $ name ; } else { $ name = $ element ; } $ name = ucwords ( $ name ) ; } $ query = "SELECT `extension_id` FROM `#__extensions` WHERE `type` = 'template' AND (`element` = '{$element}' OR `element` LIKE '{$name}') AND `client_id` = '{$client}'" ; $ this -> baseDb -> setQuery ( $ query ) ; if ( ! $ this -> baseDb -> loadResult ( ) ) { $ query = "INSERT INTO `#__extensions` (`name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `ordering`, `state`)" ; $ query .= " VALUES ('{$name}', 'template', '{$element}', '', '{$client}', '{$enabled}', '1', '{$protected}', '{}', '{}', '', '', '0', '0', '0')" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Added extension entry for template "%s"' , $ element ) ) ; if ( $ this -> baseDb -> tableExists ( '#__template_styles' ) ) { if ( $ home ) { $ query = "UPDATE `#__template_styles` SET `home` = 0 WHERE `client_id` = '{$client}'" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Disabling "home" for all other templates (client "%s")' , $ client ) ) ; } $ query = "INSERT INTO `#__template_styles` (`template`, `client_id`, `home`, `title`, `params`)" ; $ query .= " VALUES ('{$element}', '{$client}', '{$home}', '{$name}', " . ( ( isset ( $ styles ) ) ? $ this -> baseDb -> quote ( json_encode ( $ styles ) ) : "'{}'" ) . ")" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Added style entry for template "%s"' , $ element ) ) ; } } else { $ this -> log ( sprintf ( 'Extension entry already exists for template "%s"' , $ element ) ) ; } return true ; } $ this -> log ( sprintf ( 'Required table not found for adding template "%s"' , $ element ) , 'warning' ) ; return false ; }
Add as needed templates to the CMS
46,869
public function installTemplate ( $ element , $ name = null , $ client = 1 , $ styles = null , $ protected = 0 ) { $ this -> addTemplateEntry ( $ element , $ name , $ client , 1 , 1 , $ styles , $ protected ) ; }
Install a template adding it if needed
46,870
public function setAssetRules ( $ element , $ rules ) { if ( $ this -> baseDb -> tableExists ( '#__assets' ) ) { $ asset = \ Hubzero \ Access \ Asset :: oneByName ( $ element ) ; if ( ! $ asset || ! $ asset -> get ( 'id' ) ) { return false ; } foreach ( $ rules as $ idx => $ rule ) { foreach ( $ rule as $ group => $ value ) { if ( ! is_numeric ( $ group ) ) { $ query = "SELECT `id` FROM `#__usergroups` WHERE `title` = " . $ this -> baseDb -> quote ( $ group ) ; $ this -> baseDb -> setQuery ( $ query ) ; if ( $ id = $ this -> baseDb -> loadResult ( ) ) { unset ( $ rules [ $ idx ] [ $ group ] ) ; $ rules [ $ idx ] [ $ id ] = $ value ; } } } } $ asset -> set ( 'rules' , json_encode ( $ rules ) ) ; $ asset -> save ( ) ; } }
Sets the asset rules
46,871
public function deleteComponentEntry ( $ name ) { if ( $ this -> baseDb -> tableExists ( '#__components' ) ) { $ query = "DELETE FROM `#__components` WHERE `name` = " . $ this -> baseDb -> quote ( $ name ) ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Removed component entry for "%s"' , $ element ) ) ; return true ; } elseif ( $ this -> baseDb -> tableExists ( '#__extensions' ) ) { $ name = 'com_' . strtolower ( $ name ) ; $ query = "DELETE FROM `#__extensions` WHERE `name` = " . $ this -> baseDb -> quote ( $ name ) ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ asset = \ Hubzero \ Access \ Asset :: oneByName ( $ name ) ; if ( $ asset && $ asset -> get ( 'id' ) ) { $ asset -> destroy ( ) ; } $ this -> log ( sprintf ( 'Removed extension entry for component "%s"' , $ element ) ) ; if ( $ this -> baseDb -> tableExists ( '#__menu' ) ) { $ query = "DELETE FROM `#__menu` WHERE `menutype` = 'main' AND `title` = " . $ this -> baseDb -> quote ( $ name ) ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> rebuildMenu ( ) ; $ this -> log ( sprintf ( 'Removed menu entry for component "%s"' , $ element ) ) ; } return true ; } return false ; }
Remove component entries from the appropriate table depending on the CMS version
46,872
public function deletePluginEntry ( $ folder , $ element = null ) { if ( $ this -> baseDb -> tableExists ( '#__plugins' ) ) { $ query = "DELETE FROM `#__plugins` WHERE `folder` = " . $ this -> baseDb -> quote ( $ folder ) . ( ( ! is_null ( $ element ) ) ? " AND `element` = '{$element}'" : "" ) ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Removed plugin entry for "%s"' , 'plg_' . $ folder . ( $ element ? '_' . $ element : '' ) ) ) ; return true ; } elseif ( $ this -> baseDb -> tableExists ( '#__extensions' ) ) { $ query = "DELETE FROM `#__extensions` WHERE `folder` = " . $ this -> baseDb -> quote ( $ folder ) . ( ( ! is_null ( $ element ) ) ? " AND `element` = '{$element}'" : "" ) ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Removed extension entry for plugin "%s"' , 'plg_' . $ folder . ( $ element ? '_' . $ element : '' ) ) ) ; return true ; } return false ; }
Remove plugin entries from the appropriate table depending on the CMS version
46,873
public function deleteModuleEntry ( $ element , $ client = null ) { if ( $ this -> baseDb -> tableExists ( '#__extensions' ) ) { $ query = "DELETE FROM `#__extensions` WHERE `element` = '{$element}'" . ( ( isset ( $ client ) ) ? " AND `client_id` = " . $ this -> baseDb -> quote ( $ client ) : '' ) ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Removed extension entry for module "%s"' , $ element ) ) ; $ query = "SELECT `id` FROM `#__modules` WHERE `module` = '{$element}'" . ( ( isset ( $ client ) ) ? " AND `client_id` = " . $ this -> baseDb -> quote ( $ client ) : '' ) ; $ this -> baseDb -> setQuery ( $ query ) ; $ ids = $ this -> baseDb -> loadColumn ( ) ; if ( $ ids && count ( $ ids ) > 0 ) { $ query = "DELETE FROM `#__modules` WHERE `id` IN (" . implode ( ',' , $ ids ) . ")" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ query = "DELETE FROM `#__modules_menu` WHERE `moduleid` IN (" . implode ( ',' , $ ids ) . ")" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Removed module/menu entries for module "%s"' , $ element ) ) ; } return true ; } else { $ query = "SELECT `id` FROM `#__modules` WHERE `module` = '{$element}'" . ( ( isset ( $ client ) ) ? " AND `client_id` = " . $ this -> baseDb -> quote ( $ client ) : '' ) ; $ this -> baseDb -> setQuery ( $ query ) ; $ ids = $ this -> baseDb -> loadColumn ( ) ; if ( $ ids && count ( $ ids ) > 0 ) { $ query = "DELETE FROM `#__modules` WHERE `id` IN (" . implode ( ',' , $ ids ) . ")" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ query = "DELETE FROM `#__modules_menu` WHERE `moduleid` IN (" . implode ( ',' , $ ids ) . ")" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Removed module/menu entries for module "%s"' , $ element ) ) ; } return true ; } return false ; }
Remove module entries from the appropriate table depending on the CMS version
46,874
public function deleteTemplateEntry ( $ element , $ client = 1 ) { if ( $ this -> baseDb -> tableExists ( '#__extensions' ) ) { $ query = "DELETE FROM `#__extensions` WHERE `type` = 'template' AND `element` = '{$element}' AND `client_id` = '{$client}'" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Removed extension entry for template "%s"' , $ element ) ) ; if ( $ this -> baseDb -> tableExists ( '#__template_styles' ) ) { $ query = "DELETE FROM `#__template_styles` WHERE `template` = '{$element}' AND `client_id` = '{$client}'" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Removed style entry for template "%s"' , $ element ) ) ; $ query = "SELECT `id` FROM `#__template_styles` WHERE `home` = 1 AND `client_id` = '{$client}'" ; $ this -> baseDb -> setQuery ( $ query ) ; if ( ! $ this -> baseDb -> loadResult ( ) ) { $ query = "SELECT `id` FROM `#__template_styles` WHERE `client_id` = '{$client}' ORDER BY `id` DESC LIMIT 1" ; $ this -> baseDb -> setQuery ( $ query ) ; if ( $ id = $ this -> baseDb -> loadResult ( ) ) { $ query = "UPDATE `#__template_styles` SET `home` = 1 WHERE `id` = '{$id}'" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Setting "home" for template style "%s"' , $ id ) ) ; } } } return true ; } return false ; }
Remove template entires from the appropriate tables
46,875
protected function _safeAddColumn ( $ table , $ columnData ) { $ columnName = $ columnData [ 'name' ] ; $ addColumnStatement = '' ; if ( ! $ this -> db -> tableHasField ( $ table , $ columnName ) ) { $ addColumnStatement = ( new QueryAddColumnStatement ( $ columnData ) ) -> toString ( ) ; } return $ addColumnStatement ; }
Generates ADD COLUMN SQL statement if column absent from given table
46,876
protected function _safeDropColumn ( $ table , $ columnData ) { $ columnName = $ columnData [ 'name' ] ; $ dropColumnStatement = '' ; if ( $ this -> db -> tableHasField ( $ table , $ columnName ) ) { $ dropColumnStatement = with ( new QueryDropColumnStatement ( $ columnData ) ) -> toString ( ) ; } return $ dropColumnStatement ; }
Generates DROP COLUMN SQL statement if column present on given table
46,877
protected function _generateSafeAlterTableColumnOperation ( $ table , $ columns , $ functionName ) { $ query = "ALTER TABLE $table " ; foreach ( $ columns as $ columnData ) { $ query .= $ this -> $ functionName ( $ table , $ columnData ) . ',' ; } $ query = rtrim ( $ query , ',' ) . ';' ; return $ query ; }
Generates SQL statements to alter table for each column
46,878
protected function _queryIfTableExists ( $ table , $ query ) { if ( $ this -> db -> tableExists ( $ tableName ) ) { $ this -> db -> setQuery ( $ query ) ; $ this -> db -> query ( ) ; } }
Executes given query if given table exists
46,879
public function build ( $ syntax ) { $ syntax -> bind ( is_string ( $ this -> content ) ? trim ( $ this -> content ) : $ this -> content ) ; return '?' ; }
Builds the given string representation of the value object
46,880
function getHeaderField ( $ header ) { $ header = strtoupper ( $ header ) ; if ( $ header == 'ACCEPT' ) { return $ this -> accepts ; } $ key = 'HTTP_' . strtoupper ( $ header ) ; if ( isset ( $ _SERVER [ $ key ] ) ) { return $ SERVER [ $ key ] ; } return null ; }
Short description for getHeaderField
46,881
public function setSelect ( $ column , $ as = null , $ count = false ) { if ( isset ( $ this -> select [ 0 ] ) && $ this -> select [ 0 ] [ 'column' ] == '*' ) { $ this -> resetSelect ( ) ; } $ this -> select [ ] = [ 'column' => $ column , 'as' => $ as , 'count' => $ count ] ; }
Sets a select element on the query
46,882
public function setInsert ( $ table , $ ignore = false ) { $ this -> insert = $ table ; $ this -> ignore = $ ignore ; }
Sets an insert element on the query
46,883
public function setWhere ( $ column , $ operator , $ value , $ logical = 'and' , $ depth = 0 ) { $ this -> where [ ] = [ 'column' => $ column , 'operator' => $ operator , 'value' => $ value , 'logical' => $ logical , 'depth' => $ depth ] ; }
Sets a where element on the query
46,884
public function setRawWhere ( $ raw , $ bindings = [ ] , $ logical = 'and' , $ depth = 0 ) { $ this -> where [ ] = [ 'raw' => $ raw , 'bindings' => $ bindings , 'logical' => $ logical , 'depth' => $ depth ] ; }
Sets a raw where element on the query
46,885
public function setOrder ( $ column , $ dir ) { if ( ! in_array ( strtolower ( $ dir ) , [ 'asc' , 'desc' ] ) ) { throw new InvalidArgumentException ( 'Order direction must be one of ASC or DESC.' ) ; } $ this -> order [ ] = [ 'column' => $ column , 'dir' => $ dir ] ; }
Sets an order element on the query
46,886
public function build ( $ type ) { if ( empty ( $ this -> { $ type } ) ) { return false ; } $ method = 'build' . ucfirst ( $ type ) ; return $ this -> { $ method } ( ) ; }
Builds the given query element
46,887
private function buildSelect ( ) { $ selects = [ ] ; foreach ( $ this -> select as $ select ) { $ string = ( $ select [ 'count' ] ) ? "COUNT({$select['column']})" : $ select [ 'column' ] ; if ( isset ( $ select [ 'as' ] ) ) { $ string .= " AS {$select['as']}" ; } $ selects [ ] = $ string ; } return 'SELECT ' . implode ( ',' , $ selects ) ; }
Builds a select statement from the set params
46,888
private function buildFrom ( ) { $ froms = [ ] ; foreach ( $ this -> from as $ from ) { $ string = $ this -> connection -> quoteName ( $ from [ 'table' ] ) ; if ( isset ( $ from [ 'as' ] ) ) { $ string .= ' AS ' . $ this -> connection -> quoteName ( $ from [ 'as' ] ) ; } $ froms [ ] = $ string ; } return 'FROM ' . implode ( ',' , $ froms ) ; }
Builds a from statement from the set params
46,889
public function buildJoin ( ) { $ joins = [ ] ; foreach ( $ this -> join as $ join ) { if ( isset ( $ join [ 'raw' ] ) ) { $ joins [ ] = strtoupper ( $ join [ 'type' ] ) . ' JOIN ' . $ join [ 'table' ] . ' ON ' . $ join [ 'raw' ] ; } else { $ joins [ ] = strtoupper ( $ join [ 'type' ] ) . ' JOIN ' . $ join [ 'table' ] . ' ON ' . $ join [ 'left' ] . ' = ' . $ join [ 'right' ] ; } } return implode ( "\n" , $ joins ) ; }
Builds a join statement from the set params
46,890
private function buildWhere ( ) { $ strings = [ ] ; $ first = true ; $ depth = 0 ; foreach ( $ this -> where as $ constraint ) { $ string = '' ; if ( array_key_exists ( 'resetdepth' , $ constraint ) ) { $ string .= str_repeat ( ')' , ( $ depth - $ constraint [ 'depth' ] ) ) ; } else { $ string .= ( $ constraint [ 'depth' ] < $ depth ) ? ') ' : '' ; $ string .= ( $ first ) ? 'WHERE ' : strtoupper ( $ constraint [ 'logical' ] ) . ' ' ; $ string .= ( $ constraint [ 'depth' ] > $ depth ) ? '(' : '' ; if ( array_key_exists ( 'raw' , $ constraint ) ) { $ string .= $ constraint [ 'raw' ] ; foreach ( $ constraint [ 'bindings' ] as $ binding ) { $ this -> bind ( $ binding ) ; } } else { $ string .= $ this -> connection -> quoteName ( $ constraint [ 'column' ] ) ; $ string .= ' ' . $ constraint [ 'operator' ] ; if ( is_array ( $ constraint [ 'value' ] ) ) { $ values = array ( ) ; foreach ( $ constraint [ 'value' ] as $ value ) { $ values [ ] = '?' ; $ this -> bind ( $ value ) ; } $ string .= ' (' . ( ( ! empty ( $ values ) ) ? implode ( ',' , $ values ) : "''" ) . ')' ; } else { $ string .= ' ?' ; $ this -> bind ( $ constraint [ 'value' ] ) ; } } } $ strings [ ] = $ string ; $ first = false ; $ depth = $ constraint [ 'depth' ] ; } if ( $ depth > 0 ) { $ strings [ ] = str_repeat ( ')' , $ depth ) ; } return implode ( "\n" , $ strings ) ; }
Builds a where statement from the set params
46,891
public function buildSet ( ) { $ updates = [ ] ; foreach ( $ this -> set as $ field => $ value ) { if ( is_object ( $ value ) ) { $ updates [ ] = $ this -> connection -> quoteName ( $ field ) . ' = ' . $ value -> build ( $ this ) ; } else { $ updates [ ] = $ this -> connection -> quoteName ( $ field ) . ' = ?' ; $ this -> bind ( is_string ( $ value ) ? trim ( $ value ) : $ value ) ; } } return 'SET ' . implode ( ',' , $ updates ) ; }
Builds a set statement from the set params
46,892
public function buildValues ( ) { $ fields = [ ] ; $ values = [ ] ; foreach ( $ this -> values as $ field => $ value ) { $ fields [ ] = $ this -> connection -> quoteName ( $ field ) ; $ values [ ] = '?' ; $ this -> bind ( is_string ( $ value ) ? trim ( $ value ) : $ value ) ; } return '(' . implode ( ',' , $ fields ) . ') VALUES (' . implode ( ',' , $ values ) . ')' ; }
Builds a values statement from the set params
46,893
public function buildHaving ( ) { $ havings = [ ] ; foreach ( $ this -> having as $ having ) { $ havings [ ] = $ having [ 'column' ] . ' ' . $ having [ 'operator' ] . ' ?' ; $ this -> bind ( is_string ( $ having [ 'value' ] ) ? trim ( $ having [ 'value' ] ) : $ having [ 'value' ] ) ; } return 'HAVING ' . implode ( " AND " , $ havings ) ; }
Builds a having statement from the set params
46,894
public function buildLimit ( ) { $ string = 'LIMIT ' ; $ string .= ( ( ! empty ( $ this -> start ) ) ? ( int ) $ this -> start . ',' : '' ) ; $ string .= ( ( ! empty ( $ this -> limit ) ) ? ( int ) $ this -> limit : '18446744073709551615' ) ; return $ string ; }
Builds a limit statement from the set params
46,895
public function buildOrder ( ) { $ orders = [ ] ; foreach ( $ this -> order as $ order ) { if ( is_object ( $ order [ 'column' ] ) ) { $ string = $ order [ 'column' ] -> build ( $ this ) ; } else { $ string = $ this -> connection -> quoteName ( $ order [ 'column' ] ) ; } $ string .= ' ' . strtoupper ( $ order [ 'dir' ] ) ; $ orders [ ] = $ string ; } return 'ORDER BY ' . implode ( ',' , $ orders ) ; }
Builds an order statement from the set params
46,896
public static function getPopularGroups ( $ limit = 0 ) { $ database = \ App :: get ( 'db' ) ; $ sql = "SELECT g.gidNumber, g.cn, g.description, g.public_desc, (SELECT COUNT(*) FROM `#__xgroups_members` AS gm WHERE gm.gidNumber=g.gidNumber) AS members FROM `#__xgroups` AS g WHERE g.type IN (1, 3) AND g.published=1 AND g.approved=1 AND g.discoverability=0 ORDER BY members DESC" ; if ( $ limit > 0 ) { $ sql .= " LIMIT {$limit}" ; } $ database -> setQuery ( $ sql ) ; if ( ! $ database -> getError ( ) ) { return $ database -> loadObjectList ( ) ; } }
Get popular groups
46,897
public static function getFeaturedGroups ( $ groupList ) { $ database = \ App :: get ( 'db' ) ; $ groupList = array_map ( 'trim' , array_filter ( explode ( ',' , $ groupList ) , 'trim' ) ) ; if ( count ( $ groupList ) < 1 ) { return array ( ) ; } $ sql = "SELECT g.gidNumber, g.cn, g.description, g.public_desc FROM `#__xgroups` AS g WHERE (g.type=1 OR g.type=3) AND g.published=1 AND g.approved=1 AND g.discoverability=0 AND g.cn IN ('" . implode ( "','" , $ groupList ) . "')" ; $ database -> setQuery ( $ sql ) ; if ( ! $ database -> getError ( ) ) { return $ database -> loadObjectList ( ) ; } }
Gets featured groups
46,898
public static function getGroupsMatchingTagString ( $ usertags , $ usergroups ) { $ database = \ App :: get ( 'db' ) ; $ mytags = ( $ usertags != '' ) ? array_map ( 'trim' , explode ( ',' , $ usertags ) ) : array ( ) ; $ mygroups = array ( ) ; if ( is_array ( $ usergroups ) ) { foreach ( $ usergroups as $ ug ) { $ mygroups [ ] = $ ug -> gidNumber ; } } $ sql = "SELECT g.gidNumber, g.cn, g.description, g.public_desc FROM `#__xgroups` AS g WHERE g.type=1 AND g.published=1 AND g.discoverability=0" ; $ database -> setQuery ( $ sql ) ; $ groups = $ database -> loadObjectList ( ) ; foreach ( $ groups as $ k => $ group ) { $ gt = new \ Components \ Groups \ Models \ Tags ( $ group -> gidNumber ) ; $ group -> tags = $ gt -> render ( 'string' ) ; $ group -> tags = array_map ( 'trim' , explode ( ',' , $ group -> tags ) ) ; $ group -> matches = array_intersect ( $ mytags , $ group -> tags ) ; unset ( $ group -> tags ) ; if ( count ( $ group -> matches ) < 1 || in_array ( $ group -> gidNumber , $ mygroups ) ) { unset ( $ groups [ $ k ] ) ; } } return $ groups ; }
Gets groups matching tag string
46,899
public function convertInviteEmails ( $ email , $ user_id ) { if ( empty ( $ email ) || empty ( $ user_id ) ) { return false ; } $ db = \ App :: get ( 'db' ) ; $ sql = 'SELECT gidNumber FROM `#__xgroups_inviteemails` WHERE email=' . $ db -> quote ( $ email ) . ';' ; $ db -> setQuery ( $ sql ) ; $ result = $ db -> loadColumn ( ) ; if ( $ result === false ) { return false ; } if ( empty ( $ result ) ) { return true ; } foreach ( $ result as $ r ) { $ values .= "($r,$user_id)," ; $ gids .= "$r," ; } $ values = rtrim ( $ values , ',' ) ; $ gids = rtrim ( $ gids , ',' ) ; $ sql = 'INSERT INTO `#__xgroups_invitees` (gidNumber,uidNumber) VALUES ' . $ values . ';' ; $ db -> setQuery ( $ sql ) ; $ result = $ db -> query ( ) ; if ( ! $ result ) { return false ; } $ sql = 'DELETE FROM `#__xgroups_inviteemails` WHERE email=' . $ db -> quote ( $ email ) . ' AND gidNumber IN (' . $ gids . ');' ; $ db -> setQuery ( $ sql ) ; $ result = $ db -> query ( ) ; if ( ! $ result ) { return false ; } return true ; }
Converts invite emails to true group