idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
47,500
|
final public function display ( $ name = NULL ) { $ this -> render ( ) ; if ( is_dir ( $ this -> modulePath . '/css' ) ) { $ files = Utilities :: getDirectoryFilenames ( $ this -> modulePath . '/css' ) ; foreach ( $ files as $ file ) { $ fullPath = $ this -> moduleUrl . '/css/' . $ file ; $ this -> app -> loadCss ( $ fullPath . '?' . filemtime ( $ fullPath ) ) ; } } if ( is_dir ( $ this -> modulePath . '/js' ) ) { $ files = Utilities :: getDirectoryFilenames ( $ this -> modulePath . '/js' ) ; foreach ( $ files as $ file ) { $ fullPath = $ this -> moduleUrl . '/js/' . $ file ; $ this -> app -> loadScript ( $ fullPath . '?' . filemtime ( $ fullPath ) , TRUE ) ; } } if ( ! $ name ) { $ name = $ this -> layout ; } $ file = $ this -> modulePath . '/' . $ this -> scriptPath . $ name . '.php' ; $ this -> app -> logEvent ( 'Applying ' . $ this -> layout . ' layout' ) ; try { if ( file_exists ( $ file ) ) { include $ file ; } else { throw new \ Exception ( 'Layout file ' . $ file . ' was not found' ) ; } } catch ( \ Exception $ e ) { $ this -> app -> enqueueError ( $ e -> getMessage ( ) ) ; } }
|
Formats page layout including variables and returns .
|
47,501
|
public function getAlphaFilter ( $ selected = NULL ) { $ router = Router :: getInstance ( ) ; foreach ( range ( 'A' , 'Z' ) as $ a ) { $ filter = new \ stdClass ( ) ; $ filter -> href = $ router -> module . '/' . $ router -> action . '/' . strtolower ( $ a ) . '/page-1' ; $ filter -> text = $ a ; $ filter -> active = ( $ a == $ selected ) ; yield $ filter ; } }
|
Return an A - Z list with link for build an alpha filter .
|
47,502
|
private function populate ( ) { $ res = Database :: load ( 'SELECT * FROM `options` ORDER BY `group`' ) ; $ this -> list = array ( ) ; foreach ( $ res as $ o ) { if ( 'list' == $ o -> type ) { $ listItems = explode ( '|' , $ o -> list_options ) ; foreach ( $ listItems as $ listEntry ) { list ( $ val , $ text ) = explode ( ',' , $ listEntry ) ; $ listItem = new \ stdClass ( ) ; $ listItem -> value = $ val ; $ listItem -> text = $ text ; $ o -> listItems [ ] = $ listItem ; } } $ o -> value = $ this -> castTo ( $ o -> value , $ o -> type ) ; $ this -> list [ $ o -> name ] = $ o ; } }
|
Load from DB and sets all options to this object .
|
47,503
|
private function castTo ( $ value , $ type ) { switch ( $ type ) { default : $ value = ( string ) $ value ; break ; case 'int' : $ value = ( int ) $ value ; break ; case 'bool' : $ value = ( bool ) $ value ; break ; case 'password' : if ( $ this -> isCryptAvailable ( ) ) { $ value = openssl_decrypt ( $ value , 'AES128' , OPTIONS_CRYPT_KEY ) ; } else { $ app = Application :: getInstance ( ) ; $ app -> logWarning ( 'OPTIONS_CRYPT_KEY constant should be defined into config.php file.' ) ; } break ; case 'list' : break ; } return $ value ; }
|
Private utility for casting to proper type .
|
47,504
|
public function addPath ( $ title , $ url = NULL ) { $ path = new \ stdClass ( ) ; $ path -> title = $ title ; $ path -> url = $ url ; $ path -> active = TRUE ; foreach ( $ this -> paths as $ p ) { $ p -> active = FALSE ; } $ this -> paths [ ] = $ path ; return $ this ; }
|
Adds a new sub - path to Breadcrumb . Chainable method .
|
47,505
|
public function getPaths ( ) { if ( $ this -> lastUrlDisabled ) { $ newPaths = $ this -> paths ; end ( $ newPaths ) -> url = NULL ; return $ newPaths ; } else { return $ this -> paths ; } }
|
Returns all paths as array .
|
47,506
|
public function setHome ( $ title , $ url = NULL ) { $ path = new \ stdClass ( ) ; $ path -> title = $ title ; $ path -> url = $ url ; $ path -> active = count ( $ this -> paths ) > 1 ? FALSE : TRUE ; $ this -> paths [ 0 ] = $ path ; }
|
Overwrite the standard Home path .
|
47,507
|
public function db ( $ dbName ) { if ( ! $ this -> isOpen ) return ; $ this -> db = $ dbName ; $ this -> conn1 -> select_db ( $ dbName ) ; }
|
It changes default database .
|
47,508
|
public function setCharset ( $ charset ) { if ( ! $ this -> isOpen ) return ; $ this -> charset = $ charset ; $ this -> conn1 -> set_charset ( $ this -> charset ) ; }
|
It sets the charset of the database .
|
47,509
|
public function close ( ) { $ this -> isOpen = false ; if ( $ this -> conn1 === null ) return ; @ $ this -> conn1 -> close ( ) ; @ $ this -> conn1 = null ; }
|
It closes the connection
|
47,510
|
public function runMultipleRawQuery ( $ listSql , $ continueOnError = false ) { if ( ! $ this -> isOpen ) { $ this -> throwError ( "RMRQ: It's not connected to the database" , "" ) ; return false ; } $ arr = explode ( ';' , $ listSql ) ; $ ok = true ; foreach ( $ arr as $ rawSql ) { if ( trim ( $ rawSql ) != '' ) { if ( $ this -> readonly ) { if ( stripos ( $ rawSql , 'insert ' ) === 0 || stripos ( $ rawSql , 'update ' ) === 0 || stripos ( $ rawSql , 'delete ' ) === 0 ) { $ ok = false ; if ( ! $ continueOnError ) { $ this -> throwError ( "Database is in READ ONLY MODE" , "" ) ; } } } if ( $ this -> logLevel >= 2 ) { $ this -> storeInfo ( $ rawSql ) ; } $ r = $ this -> conn1 -> query ( $ rawSql ) ; if ( $ r === false ) { $ ok = false ; if ( ! $ continueOnError ) { $ this -> throwError ( "Unable to run raw query" , $ this -> lastQuery ) ; } } } } return $ ok ; }
|
Run many unprepared query separated by ;
|
47,511
|
public function getSequence ( $ asFloat = false , $ unpredictable = false ) { $ sql = "select next_{$this->tableSequence}({$this->nodeId}) id" ; $ r = $ this -> runRawQuery ( $ sql , null , true ) ; if ( $ unpredictable ) { if ( PHP_INT_SIZE == 4 ) { return $ this -> encryption -> encryptSimple ( $ r [ 0 ] [ 'id' ] ) ; } else { return $ this -> encryption -> encryptInteger ( $ r [ 0 ] [ 'id' ] ) ; } } if ( $ asFloat ) return floatval ( $ r [ 0 ] [ 'id' ] ) ; else return $ r [ 0 ] [ 'id' ] ; }
|
It returns the next sequence . It gets a collision free number if we don t do more than one operation every 0 . 0001 seconds . But if we do 2 or more operations per seconds then it adds a sequence number from 0 to 4095 So the limit of this function is 4096 operations per 0 . 0001 second .
|
47,512
|
public function createTable ( $ tableName , $ definition , $ primaryKey = null , $ extra = '' ) { $ sql = "CREATE TABLE `{$tableName}` (" ; foreach ( $ definition as $ key => $ type ) { $ sql .= "`$key` $type," ; } if ( $ primaryKey ) { $ sql .= " PRIMARY KEY(`$primaryKey`) " ; } else { $ sql = substr ( $ sql , 0 , - 1 ) ; } $ sql .= "$extra ) ENGINE=MyISAM DEFAULT CHARSET=" . $ this -> charset ; return $ this -> runRawQuery ( $ sql , null , true ) ; }
|
Create a t
|
47,513
|
public function commit ( $ throw = true ) { if ( ! $ this -> transactionOpen && $ throw ) { $ this -> throwError ( "Transaction not open to commit()" , "" ) ; return false ; } if ( ! $ this -> isOpen ) { $ this -> throwError ( "It's not connected to the database" , "" ) ; return false ; } $ this -> transactionOpen = false ; return @ $ this -> conn1 -> commit ( ) ; }
|
Commit and close a transaction
|
47,514
|
public function rollback ( $ throw = true ) { if ( ! $ this -> transactionOpen && $ throw ) $ this -> throwError ( "Transaction not open to rollback()" , "" ) ; if ( ! $ this -> isOpen ) { $ this -> throwError ( "It's not connected to the database" , "" ) ; return false ; } $ this -> transactionOpen = false ; return @ $ this -> conn1 -> rollback ( ) ; }
|
Rollback and close a transaction
|
47,515
|
public static function unixtime2Sql ( $ dateNum ) { if ( $ dateNum == null ) { return DaoOne :: $ dateEpoch ; } try { $ date2 = new DateTime ( date ( "Y-m-d H:i:s.u" , $ dateNum ) ) ; } catch ( Exception $ e ) { return DaoOne :: $ dateEpoch ; } return $ date2 -> format ( 'Y-m-d H:i:s.u' ) ; }
|
Convert date from unix - > mysql
|
47,516
|
public static function dateTimeSql2PHP ( $ sqlField , & $ hasTime = false ) { if ( $ sqlField === "" || $ sqlField === null ) { if ( DaoOne :: $ dateEpoch === null ) return null ; return DateTime :: createFromFormat ( 'Y-m-d H:i:s.u' , DaoOne :: $ dateEpoch ) ; } if ( strpos ( $ sqlField , '.' ) ) { $ hasTime = true ; return DateTime :: createFromFormat ( 'Y-m-d H:i:s.u' , $ sqlField ) ; } else { if ( strpos ( $ sqlField , ':' ) ) { $ hasTime = true ; return DateTime :: createFromFormat ( 'Y-m-d H:i:s' , $ sqlField ) ; } else { $ hasTime = false ; return DateTime :: createFromFormat ( 'Y-m-d' , $ sqlField ) ; } } }
|
Convert date from mysql - > php
|
47,517
|
public function runGen ( $ returnArray = true ) { $ sql = $ this -> sqlGen ( ) ; $ stmt = $ this -> prepare ( $ sql ) ; if ( $ stmt === null ) { return false ; } $ parType = implode ( '' , $ this -> whereParamType ) ; $ values = array_values ( $ this -> whereParamValue ) ; if ( $ parType ) { $ reval = $ stmt -> bind_param ( $ parType , ... $ values ) ; if ( ! $ reval ) { $ this -> throwError ( "Error in bind" , "" , "type: " . json_encode ( $ parType ) . " values:" . json_encode ( $ values ) ) ; return false ; } } $ this -> runQuery ( $ stmt ) ; $ rows = $ stmt -> get_result ( ) ; if ( $ this -> genSqlFields ) { $ this -> lastSqlFields = $ this -> obtainSqlFields ( $ rows ) ; } $ stmt -> close ( ) ; $ this -> builderReset ( ) ; if ( $ returnArray ) { $ r = $ rows -> fetch_all ( MYSQLI_ASSOC ) ; $ rows -> free_result ( ) ; return $ r ; } else { return $ rows ; } }
|
Run builder query and returns a mysqli_result .
|
47,518
|
public function prepare ( $ query ) { if ( ! $ this -> isOpen ) { $ this -> throwError ( "It's not connected to the database" , "" ) ; return null ; } $ this -> lastParam = [ ] ; $ this -> lastQuery = $ query ; if ( $ this -> readonly ) { if ( stripos ( $ query , 'insert ' ) === 0 || stripos ( $ query , 'update ' ) === 0 || stripos ( $ query , 'delete ' ) === 0 ) { $ this -> throwError ( "Database is in READ ONLY MODE" , "" ) ; } } if ( $ this -> logLevel >= 2 ) { $ this -> storeInfo ( $ query ) ; } try { $ stmt = $ this -> conn1 -> prepare ( $ query ) ; } catch ( Exception $ ex ) { $ stmt = false ; $ this -> throwError ( "Failed to prepare" , $ ex -> getMessage ( ) , json_encode ( $ this -> lastParam ) ) ; } if ( $ stmt === false ) { $ this -> throwError ( "Unable to prepare query" , $ this -> lastQuery , json_encode ( $ this -> lastParam ) ) ; } return $ stmt ; }
|
Prepare a query . It returns a mysqli statement .
|
47,519
|
private function builderReset ( ) { $ this -> select = '' ; $ this -> from = '' ; $ this -> where = [ ] ; $ this -> whereParamType = array ( ) ; $ this -> whereCounter = 0 ; $ this -> whereParamValue = array ( ) ; $ this -> set = [ ] ; $ this -> group = '' ; $ this -> having = [ ] ; $ this -> limit = '' ; $ this -> distinct = '' ; $ this -> order = '' ; }
|
It reset the parameters used to Build Query .
|
47,520
|
public static function getByRepresentation ( $ representation ) { list ( $ languageCode , $ countryCode ) = explode ( '-' , $ representation ) ; $ query = 'SELECT lc.*' . ' FROM `locales` as lc' . ' INNER JOIN `languages` AS l ON lc.language_id = l.id' . ' INNER JOIN `countries` AS c ON lc.country_id = c.id' . ' WHERE c.code = ?' . ' AND l.code = ?' ; return static :: getObjectByQuery ( $ query , [ $ countryCode , $ languageCode ] ) ; }
|
Returns the Locale object by its representation .
|
47,521
|
public function readTranslation ( $ module ) { $ file = APPLICATION_PATH . ( is_a ( $ module , 'Pair\Module' ) ? '/modules/' . $ module -> name : '' ) . '/translations/' . $ this -> getRepresentation ( ) . '.ini' ; if ( file_exists ( $ file ) ) { $ strings = parse_ini_file ( $ file ) ; return ( is_array ( $ strings ) ? $ strings : array ( ) ) ; } else { return array ( ) ; } }
|
Read all translation strings from a file located into a module .
|
47,522
|
public function isFileWritable ( $ moduleName ) { $ folder = APPLICATION_PATH . ( 'common' != $ moduleName ? '/modules/' . $ moduleName : '' ) . '/translations' ; $ file = $ folder . '/' . $ this -> getRepresentation ( ) . '.ini' ; if ( ( file_exists ( $ file ) and is_writable ( $ file ) ) or ( ! file_exists ( $ file ) and is_dir ( $ folder ) and is_writable ( $ folder ) ) ) { return TRUE ; } else { return FALSE ; } }
|
Returns TRUE if translation file of passed module is writable .
|
47,523
|
public function writeTranslation ( $ strings , $ module ) { $ folder = APPLICATION_PATH . ( is_a ( $ module , 'Pair\Module' ) ? '/modules/' . $ module -> name : '' ) . '/translations/' ; $ file = $ folder . $ this -> getRepresentation ( ) . '.ini' ; if ( ! file_exists ( $ file ) ) { if ( is_dir ( $ folder ) and is_writable ( $ folder ) ) { try { touch ( $ file ) ; chmod ( $ file , 0777 ) ; $ head = "; \$Id\$\r\n" ; } catch ( \ Exception $ e ) { trigger_error ( $ e -> getMessage ( ) ) ; return FALSE ; } } else { trigger_error ( 'Translation file ' . $ file . ' cannot be read' ) ; return FALSE ; } } $ lines = array ( ) ; foreach ( $ strings as $ key => $ value ) { if ( $ value ) { $ lines [ ] = $ key . ' = "' . $ value . '"' ; } } $ content = implode ( "\n" , $ lines ) ; try { $ res = file_put_contents ( $ file , $ content ) ; } catch ( \ Exception $ e ) { $ app = Application :: getInstance ( ) ; $ app -> logError ( 'Translation file ' . $ file . ' cannot be written due its permission' ) ; $ res = FALSE ; } return $ res ; }
|
Write all translation strings into a file located into a module .
|
47,524
|
public function getNativeNames ( ) { $ language = $ this -> getLanguage ( ) ; $ country = $ this -> getCountry ( ) ; $ languageName = $ language -> nativeName ? $ language -> nativeName : $ language -> englishName ; $ countryName = $ country -> nativeName ? $ country -> nativeName : $ country -> englishName ; return $ languageName . ' (' . $ countryName . ')' ; }
|
Return the native language and country names if available english name otherwise .
|
47,525
|
public static function getExistentTranslations ( $ nativeNames = TRUE ) { $ columnName = $ nativeNames ? 'native_name' : 'english_name' ; $ query = 'SELECT lo.*, CONCAT(la.code, "-", co.code) AS representation,' . ' CONCAT(la.' . $ columnName . ', " (", co.' . $ columnName . ', ")") AS language_country' . ' FROM `locales` AS lo' . ' INNER JOIN `languages` AS la ON lo.language_id = la.id' . ' INNER JOIN `countries` AS co ON lo.country_id = co.id' . ' ORDER BY la.' . $ columnName ; $ locales = Locale :: getObjectsByQuery ( $ query ) ; $ files = Utilities :: getDirectoryFilenames ( 'translations' ) ; $ existents = array ( ) ; foreach ( $ files as $ file ) { $ fileRepresentation = substr ( $ file , 0 , strlen ( $ file ) - 4 ) ; foreach ( $ locales as $ locale ) { if ( $ locale -> representation == $ fileRepresentation ) { $ existents [ ] = $ locale ; continue ; } } } return $ existents ; }
|
List all locales that have the common translation file in this application .
|
47,526
|
public function addInput ( $ name , $ attributes = array ( ) ) { $ control = new FormControlInput ( $ name , $ attributes ) ; $ this -> addControl ( $ control ) ; return $ control ; }
|
Adds an FormControlInput object to this Form object . Default type is Text . Chainable method .
|
47,527
|
public function addSelect ( $ name , $ attributes = array ( ) ) { $ control = new FormControlSelect ( $ name , $ attributes ) ; $ this -> addControl ( $ control ) ; return $ control ; }
|
Adds an FormControlSelect object to this Form object . Chainable method .
|
47,528
|
public function addTextarea ( $ name , $ attributes = array ( ) ) { $ control = new FormControlTextarea ( $ name , $ attributes ) ; $ this -> addControl ( $ control ) ; return $ control ; }
|
Adds an FormControlTextarea object to this Form object . Chainable method .
|
47,529
|
public function addButton ( $ name , $ attributes = array ( ) ) { $ control = new FormControlButton ( $ name , $ attributes ) ; $ this -> addControl ( $ control ) ; return $ control ; }
|
Adds an FormControlButton object to this Form object . Chainable method .
|
47,530
|
public function removeControl ( $ name ) { if ( substr ( $ name , - 2 ) == '[]' ) { $ name = substr ( $ name , 0 , - 2 ) ; } if ( ! $ this -> controlExists ( $ name ) ) { return FALSE ; } unset ( $ this -> controls [ $ name ] ) ; return TRUE ; }
|
Remove a control form a Form object .
|
47,531
|
public function setValuesByObject ( $ object ) { if ( is_object ( $ object ) and is_subclass_of ( $ object , 'Pair\ActiveRecord' ) ) { $ properties = $ object -> getAllProperties ( ) ; foreach ( $ properties as $ name => $ value ) { if ( array_key_exists ( $ name , $ this -> controls ) ) { $ control = $ this -> getControl ( $ name ) ; $ control -> setValue ( $ value ) ; } } } }
|
Assigns all attributes of passed ActiveRecord children to controls with same name .
|
47,532
|
public function renderControl ( $ name ) { $ control = $ this -> getControl ( $ name ) ; if ( $ control ) { if ( count ( $ this -> controlClasses ) ) { $ control -> addClass ( implode ( ' ' , $ this -> controlClasses ) ) ; } print $ control -> render ( ) ; } }
|
Creates an HTML form control getting its object by its name .
|
47,533
|
public function isValid ( ) { $ valid = TRUE ; foreach ( $ this -> controls as $ control ) { if ( ! $ control -> validate ( ) ) { $ valid = FALSE ; } } return $ valid ; }
|
Validates all form field controls and returns a FormValidation result object .
|
47,534
|
public function getUnvalidControls ( ) { $ unvalids = array ( ) ; foreach ( $ this -> controls as $ control ) { if ( ! $ control -> validate ( ) ) { $ unvalids [ ] = $ control ; } } return $ unvalids ; }
|
Return a list of unvalid FormControl objects .
|
47,535
|
public static function buildSelectFromArray ( $ name , $ list , $ value = NULL , $ attributes = NULL , $ prependEmpty = NULL ) { $ control = new FormControlSelect ( $ name , $ attributes ) ; $ control -> setListByAssociativeArray ( $ list ) -> prependEmpty ( $ prependEmpty ) -> setValue ( $ value ) ; return $ control -> render ( ) ; }
|
Proxy for buildSelect that allow to start option list from a simple array .
|
47,536
|
public static function buildInput ( $ name , $ value = NULL , $ type = 'text' , $ attributes = array ( ) ) { $ control = new FormControlInput ( $ name , $ attributes ) ; $ control -> setType ( $ type ) -> setValue ( $ value ) ; return $ control -> render ( ) ; }
|
Creates an HTML input form control .
|
47,537
|
public static function buildTextarea ( $ name , $ rows , $ cols , $ value = NULL , $ attributes = array ( ) ) { $ control = new FormControlTextarea ( $ name , $ attributes ) ; $ control -> setRows ( $ rows ) -> setCols ( $ cols ) -> setValue ( $ value ) ; return $ control -> render ( ) ; }
|
Creates a TextArea input field .
|
47,538
|
public static function buildButton ( $ value , $ type = 'submit' , $ name = NULL , $ attributes = array ( ) , $ faIcon = NULL ) { $ control = new FormControlButton ( $ name , $ attributes ) ; $ control -> setValue ( $ value ) -> setType ( $ type ) -> setFaIcon ( $ faIcon ) ; return $ control -> render ( ) ; }
|
Creates an HTML button form control prepending an optional icon .
|
47,539
|
public function setValue ( $ value ) { if ( is_a ( $ value , 'DateTime' ) and is_a ( $ this , 'Pair\FormControlInput' ) ) { if ( defined ( 'UTC_DATE' ) and UTC_DATE ) { $ app = Application :: getInstance ( ) ; $ value -> setTimezone ( $ app -> currentUser -> getDateTimeZone ( ) ) ; } $ format = ( isset ( $ this -> type ) and 'date' == $ this -> type ) ? $ this -> dateFormat : $ this -> datetimeFormat ; $ this -> value = $ value -> format ( $ format ) ; } else { $ this -> value = $ value ; } return $ this ; }
|
Sets value for this control subclass .
|
47,540
|
public function addClass ( $ class ) { if ( is_array ( $ class ) ) { foreach ( $ class as $ c ) { if ( ! in_array ( $ c , $ this -> class ) ) { $ this -> class [ ] = $ c ; } } } else if ( ! in_array ( $ class , $ this -> class ) ) { $ this -> class [ ] = $ class ; } return $ this ; }
|
Adds CSS single class classes string or classes array to this control avoiding duplicates . This method is chainable .
|
47,541
|
protected function processProperties ( ) { $ ret = '' ; if ( $ this -> required and ( ! isset ( $ this -> type ) or ( isset ( $ this -> type ) and 'bool' != $ this -> type ) ) ) { $ ret .= ' required' ; } if ( $ this -> disabled ) { $ ret .= ' disabled' ; } if ( $ this -> readonly ) { $ ret .= ' readonly' ; } if ( $ this -> placeholder ) { $ ret .= ' placeholder="' . $ this -> placeholder . '"' ; } if ( count ( $ this -> class ) ) { $ ret .= ' class="' . implode ( ' ' , $ this -> class ) . '"' ; } foreach ( $ this -> attributes as $ attr => $ val ) { $ ret .= ' ' . $ attr . '="' . addslashes ( $ val ) . '"' ; } return $ ret ; }
|
Process and return the common control attributes .
|
47,542
|
public function render ( ) { $ ret = '<input ' . $ this -> getNameProperty ( ) ; switch ( $ this -> type ) { default : case 'text' : case 'email' : case 'tel' : case 'url' : case 'color' : case 'password' : $ ret .= ' type="' . htmlspecialchars ( $ this -> type ) . '" value="' . htmlspecialchars ( $ this -> value ) . '"' ; break ; case 'number' : $ curr = setlocale ( LC_NUMERIC , 0 ) ; setlocale ( LC_NUMERIC , 'en_US' ) ; $ ret .= ' type="number" value="' . htmlspecialchars ( $ this -> value ) . '"' ; setlocale ( LC_NUMERIC , $ curr ) ; break ; case 'bool' : $ ret .= ' type="checkbox" value="1"' ; if ( $ this -> value ) $ ret .= ' checked="checked"' ; break ; case 'date' : $ ret .= ' type="date" value="' . htmlspecialchars ( $ this -> value ) . '"' ; break ; case 'datetime' : $ type = Input :: usingCustomDatetimepicker ( ) ? 'datetime' : 'datetime-local' ; $ ret .= ' type="' . $ type . '" value="' . htmlspecialchars ( $ this -> value ) . '"' ; break ; case 'file' : $ ret .= ' type="file"' ; break ; case 'address' : $ ret .= ' type="text" value="' . htmlspecialchars ( $ this -> value ) . '" size="50" autocomplete="on" placeholder=""' ; $ this -> addClass ( 'googlePlacesAutocomplete' ) ; break ; case 'hidden' : $ ret .= ' type="hidden" value="' . htmlspecialchars ( $ this -> value ) . '"' ; break ; } if ( in_array ( $ this -> type , [ 'number' , 'date' ] ) ) { if ( $ this -> min ) { $ ret .= ' min="' . htmlspecialchars ( $ this -> min ) . '"' ; } if ( $ this -> max ) { $ ret .= ' max="' . htmlspecialchars ( $ this -> max ) . '"' ; } } if ( $ this -> minLength ) { $ ret .= ' minlength="' . htmlspecialchars ( $ this -> minLength ) . '"' ; } if ( $ this -> maxLength ) { $ ret .= ' maxlength="' . htmlspecialchars ( $ this -> maxLength ) . '"' ; } if ( $ this -> accept ) { $ ret .= ' accept="' . $ this -> accept . '"' ; } if ( $ this -> step ) { $ ret .= ' step="' . htmlspecialchars ( $ this -> step ) . '"' ; } $ ret .= $ this -> processProperties ( ) . ' />' ; return $ ret ; }
|
Renders and returns an HTML input form control .
|
47,543
|
public function setListByAssociativeArray ( $ list ) { foreach ( $ list as $ value => $ text ) { $ option = new \ stdClass ( ) ; $ option -> value = $ value ; $ option -> text = $ text ; $ option -> attributes = [ ] ; $ this -> list [ ] = $ option ; } return $ this ; }
|
Populates select control with an associative array . Chainable method .
|
47,544
|
public function prependEmpty ( $ text = NULL ) { $ t = Translator :: getInstance ( ) ; $ option = new \ stdClass ( ) ; $ option -> value = '' ; $ option -> text = is_null ( $ text ) ? $ t -> get ( 'SELECT_NULL_VALUE' ) : $ text ; $ this -> list = array_merge ( array ( $ option ) , $ this -> list ) ; return $ this ; }
|
Adds a null value as first item . Chainable method .
|
47,545
|
public function render ( ) { $ buildOption = function ( $ option ) { if ( ! isset ( $ option -> value ) or ! isset ( $ option -> text ) ) { return '' ; } if ( is_array ( $ this -> value ) ) { $ selected = in_array ( $ option -> value , $ this -> value ) ? ' selected="selected"' : '' ; } else { $ selected = $ this -> value == $ option -> value ? ' selected="selected"' : '' ; } $ attributes = '' ; if ( isset ( $ option -> attributes ) and count ( $ option -> attributes ) ) { foreach ( $ option -> attributes as $ a ) { $ attributes .= ' ' . $ a [ 'name' ] . '="' . $ a [ 'value' ] . '"' ; } } return '<option value="' . htmlspecialchars ( $ option -> value ) . '"' . $ selected . $ attributes . '>' . htmlspecialchars ( $ option -> text ) . "</option>\n" ; } ; $ ret = '<select ' . $ this -> getNameProperty ( ) ; if ( $ this -> multiple ) { $ ret .= ' multiple' ; } $ ret .= $ this -> processProperties ( ) . ">\n" ; try { foreach ( $ this -> list as $ item ) { if ( isset ( $ item -> list ) and is_array ( $ item -> list ) and count ( $ item -> list ) ) { $ ret .= '<optgroup label="' . htmlspecialchars ( isset ( $ item -> group ) ? $ item -> group : '' ) . "\">\n" ; foreach ( $ item -> list as $ option ) { $ ret .= $ buildOption ( $ option ) ; } $ ret .= "</optgroup>\n" ; } else { $ ret .= $ buildOption ( $ item ) ; } } } catch ( \ Exception $ e ) { print $ e -> getMessage ( ) ; } $ ret .= "</select>\n" ; return $ ret ; }
|
Renders a Select field tag as HTML code .
|
47,546
|
public function render ( ) { $ ret = '<textarea ' . $ this -> getNameProperty ( ) ; $ ret .= ' rows="' . $ this -> rows . '" cols="' . $ this -> cols . '"' ; $ ret .= $ this -> processProperties ( ) . '>' ; $ ret .= htmlspecialchars ( $ this -> value ) . '</textarea>' ; return $ ret ; }
|
Renders a TextArea field tag as HTML code .
|
47,547
|
public function render ( ) { $ ret = '<button type="' . $ this -> type . '"' ; if ( $ this -> id ) { $ ret .= 'id=' . $ this -> id ; } if ( $ this -> name ) { $ ret .= ' ' . $ this -> getNameProperty ( ) ; } $ ret .= $ this -> processProperties ( ) . '>' ; if ( $ this -> faIcon ) { $ ret .= '<i class="fa ' . $ this -> faIcon . '"></i> ' ; } $ ret .= trim ( htmlspecialchars ( $ this -> value ) ) . ' </button>' ; return $ ret ; }
|
Renders an HTML button form control prepending an optional FontAwesome icon .
|
47,548
|
protected function setCurrentUser ( $ user ) { if ( is_a ( $ user , 'Pair\User' ) ) { $ this -> currentUser = $ user ; $ tran = Translator :: getInstance ( ) ; $ tran -> setLocale ( $ user -> getLocale ( ) ) ; } }
|
Sets current user default template and translation locale .
|
47,549
|
final public function getState ( $ name ) { if ( array_key_exists ( $ name , $ this -> state ) ) { return $ this -> state [ $ name ] ; } else { return NULL ; } }
|
Returns the requested session state variable .
|
47,550
|
public function loadScript ( $ src , $ defer = FALSE , $ async = FALSE , $ attribs = [ ] ) { $ attribs = ( array ) $ attribs ; $ script = new \ stdClass ( ) ; $ script -> src = $ src ; if ( $ defer ) $ script -> defer = TRUE ; if ( $ async ) $ script -> async = TRUE ; $ validTypes = [ 'text/javascript' , 'text/ecmascript' , 'application/javascript' , 'application/ecmascript' ] ; if ( isset ( $ attribs [ 'type' ] ) and in_array ( $ attribs [ 'type' ] , $ validTypes ) ) { $ script -> type = $ attribs [ 'type' ] ; } if ( isset ( $ attribs [ 'integrity' ] ) and strlen ( trim ( $ attribs [ 'integrity' ] ) ) ) { $ script -> integrity = $ attribs [ 'integrity' ] ; } if ( isset ( $ attribs [ 'crossorigin' ] ) and strlen ( trim ( $ attribs [ 'crossorigin' ] ) ) ) { $ script -> crossorigin = $ attribs [ 'crossorigin' ] ; } if ( isset ( $ attribs [ 'charset' ] ) and strlen ( trim ( $ attribs [ 'charset' ] ) ) ) { $ script -> charset = $ attribs [ 'charset' ] ; } $ this -> scriptFiles [ ] = $ script ; }
|
Set esternal script file load with optional attributes .
|
47,551
|
public function enqueueMessage ( $ text , $ title = '' , $ type = NULL ) { $ message = new \ stdClass ( ) ; $ message -> text = $ text ; $ message -> title = ( $ title ? $ title : 'Info' ) ; $ message -> type = ( $ type ? $ type : 'info' ) ; $ this -> messages [ ] = $ message ; }
|
Appends a text message to queue .
|
47,552
|
public function redirect ( $ url , $ externalUrl = FALSE ) { $ this -> makeQueuedMessagesPersistent ( ) ; if ( ! $ url ) return ; if ( $ externalUrl ) { header ( 'Location: ' . $ url ) ; } else { $ router = Router :: getInstance ( ) ; $ page = $ router -> getPage ( ) ; if ( $ page > 1 ) { if ( '/' == $ url { 0 } ) { $ url = substr ( $ url , 1 ) ; } if ( FALSE == strpos ( $ url , '/' ) ) { $ url .= '/' ; } header ( 'Location: ' . BASE_HREF . $ url . '/page-' . $ page ) ; } else { header ( 'Location: ' . BASE_HREF . $ url ) ; } } exit ( ) ; }
|
Redirect HTTP on the URL param . Relative path as default . Queued messages get a persistent storage in a cookie in order to being retrieved later .
|
47,553
|
public function runApi ( $ name = 'api' ) { $ router = Router :: getInstance ( ) ; if ( ! trim ( $ name ) or $ name != $ router -> module or ! file_exists ( MODULE_PATH . 'controller.php' ) ) { return ; } Router :: setRaw ( ) ; $ logger = Logger :: getInstance ( ) ; $ logger -> disable ( ) ; require ( MODULE_PATH . 'controller.php' ) ; $ sid = Input :: get ( 'sid' ) ; $ tokenValue = Router :: get ( 'token' ) ; $ ctlName = $ name . 'Controller' ; $ apiCtl = new $ ctlName ( ) ; $ action = $ router -> action ? $ router -> action . 'Action' : 'defaultAction' ; if ( $ tokenValue ) { $ token = Token :: getByValue ( $ tokenValue ) ; if ( $ token ) { $ token -> updateLastUse ( ) ; $ apiCtl -> setToken ( $ token ) ; $ apiCtl -> $ action ( ) ; } else { $ apiCtl -> sendError ( 'Token is not valid' ) ; } } else if ( 'login' == $ router -> action or 'logout' == $ router -> action ) { session_start ( ) ; $ apiCtl -> $ action ( ) ; } else if ( $ sid ) { $ session = new Session ( $ sid ) ; if ( ! $ session -> isLoaded ( ) ) { $ apiCtl -> sendError ( 'Session is not valid' ) ; } $ session -> extendTimeout ( ) ; $ userClass = PAIR_USER_CLASS ; $ user = new $ userClass ( $ session -> idUser ) ; $ this -> setCurrentUser ( $ user ) ; $ apiCtl -> setSession ( $ session ) ; $ apiCtl -> $ action ( ) ; } else { $ apiCtl -> sendError ( 'Request is not valid' ) ; } exit ( ) ; }
|
Manage API login logout and custom requests .
|
47,554
|
public function setPersistentState ( $ name , $ value ) { $ name = static :: getCookiePrefix ( ) . ucfirst ( $ name ) ; $ this -> persistentState [ $ name ] = $ value ; setcookie ( $ name , json_encode ( $ value ) , NULL , '/' ) ; }
|
Store variables of any type in a cookie for next retrievement . Existent variables with same name will be overwritten .
|
47,555
|
public function getPersistentState ( $ name ) { $ name = static :: getCookiePrefix ( ) . ucfirst ( $ name ) ; if ( array_key_exists ( $ name , $ this -> persistentState ) ) { return $ this -> persistentState [ $ name ] ; } else if ( isset ( $ _COOKIE [ $ name ] ) ) { return json_decode ( $ _COOKIE [ $ name ] ) ; } else { return NULL ; } }
|
Retrieves variables of any type form a cookie named like in param .
|
47,556
|
public function unsetPersistentState ( $ name ) { $ name = static :: getCookiePrefix ( ) . ucfirst ( $ name ) ; unset ( $ this -> persistentState [ $ name ] ) ; if ( isset ( $ _COOKIE [ $ name ] ) ) { unset ( $ _COOKIE [ $ name ] ) ; setcookie ( $ name , '' , - 1 , '/' ) ; } }
|
Removes a state variable from cookie .
|
47,557
|
public function unsetAllPersistentStates ( ) { $ prefix = static :: getCookiePrefix ( ) ; foreach ( $ _COOKIE as $ name => $ content ) { if ( 0 == strpos ( $ name , $ prefix ) ) { $ this -> unsetPersistentState ( $ name ) ; } } }
|
Removes all state variables from cookies .
|
47,558
|
final private function getMessageScript ( ) { $ script = '' ; if ( count ( $ this -> messages ) ) { foreach ( $ this -> messages as $ m ) { $ types = array ( 'info' , 'warning' , 'error' ) ; if ( ! in_array ( $ m -> type , $ types ) ) $ m -> type = 'info' ; $ script .= '$.showMessage("' . addslashes ( $ m -> title ) . '","' . addcslashes ( $ m -> text , "\"\n\r" ) . '","' . addslashes ( $ m -> type ) . "\");\n" ; } } return $ script ; }
|
Returns javascript code for displaying a front - end user message .
|
47,559
|
protected function beforeDelete ( ) { $ this -> db -> exec ( 'DELETE FROM `sessions` WHERE id_user = ?' , $ this -> id ) ; $ this -> db -> exec ( 'DELETE FROM `error_logs` WHERE user_id = ?' , $ this -> id ) ; }
|
Deletes sessions of an user before its deletion .
|
47,560
|
public static function getHashedPasswordWithSalt ( $ password ) { $ salt = substr ( str_replace ( '+' , '.' , base64_encode ( sha1 ( microtime ( true ) , true ) ) ) , 0 , 22 ) ; $ hash = crypt ( $ password , '$2a$12$' . $ salt ) ; return $ hash ; }
|
Creates and returns an Hash for user password adding salt .
|
47,561
|
private function createSession ( string $ timezone ) : bool { if ( ! in_array ( $ timezone , \ DateTimeZone :: listIdentifiers ( ) ) ) { $ timezone = date_default_timezone_get ( ) ; } $ dt = new \ DateTime ( 'now' , new \ DateTimeZone ( $ timezone ) ) ; $ diff = $ dt -> format ( 'P' ) ; list ( $ hours , $ mins ) = explode ( ':' , $ diff ) ; $ offset = ( float ) $ hours + ( $ hours > 0 ? ( $ mins / 60 ) : - ( $ mins / 60 ) ) ; $ session = new Session ( ) ; $ session -> id = session_id ( ) ; $ session -> idUser = $ this -> id ; $ session -> startTime = new \ DateTime ( ) ; $ session -> timezoneOffset = $ offset ; $ session -> timezoneName = $ timezone ; $ res1 = $ session -> create ( ) ; $ this -> lastLogin = new \ DateTime ( ) ; $ this -> tzOffset = $ offset ; $ this -> tzName = $ timezone ; $ res2 = $ this -> update ( 'lastLogin' ) ; return ( $ res1 and $ res2 ) ; }
|
Starts a new session writes on db and updates users table for last login . Returns true if both db writing has been done succesfully .
|
47,562
|
public static function doLogout ( $ sid ) : bool { $ app = Application :: getInstance ( ) ; $ db = Database :: getInstance ( ) ; $ res = $ db -> exec ( 'DELETE FROM `sessions` WHERE id = ?' , $ sid ) ; $ app -> unsetAllPersistentStates ( ) ; $ app -> currentUser -> unsetRememberMe ( ) ; $ app -> currentUser = NULL ; return ( bool ) $ res ; }
|
Does the logout action and returns TRUE if session is found and deleted .
|
47,563
|
public function getDateTimeZone ( ) : \ DateTimeZone { $ this -> loadTimezone ( ) ; return new \ DateTimeZone ( $ this -> tzName ? $ this -> tzName : BASE_TIMEZONE ) ; }
|
It will returns DateTimeZone object for this User .
|
47,564
|
private function loadTimezone ( ) { if ( ! is_null ( $ this -> id ) and ( is_null ( $ this -> tzName ) or is_null ( $ this -> tzOffset ) ) ) { $ this -> db -> setQuery ( 'SELECT timezone_name, timezone_offset FROM `sessions` WHERE id_user = ?' ) ; $ obj = $ this -> db -> loadObject ( $ this -> id ) ; $ this -> tzOffset = $ obj -> timezone_offset ; $ this -> tzName = $ obj -> timezone_name ; } }
|
If time zone name or offset is null will loads from session table their values and populates this object cache properties .
|
47,565
|
public function canAccess ( $ module , $ action = NULL ) : bool { if ( is_null ( $ action ) and FALSE !== strpos ( $ module , '/' ) ) { list ( $ module , $ action ) = explode ( '/' , $ module ) ; } if ( $ this -> admin or 'user' == $ module ) { return TRUE ; } $ acl = $ this -> getAcl ( ) ; foreach ( $ acl as $ rule ) { if ( $ rule -> module_name == $ module and ( ! $ rule -> action or ( $ rule -> action and $ rule -> action == $ action ) ) ) { return TRUE ; } } return FALSE ; }
|
Check if this user has access permission to a module and optionally to a specific action . Admin can access everything . This method use cache variable to load once from db .
|
47,566
|
private function getAcl ( ) : ? array { if ( ! $ this -> issetCache ( 'acl' ) ) { $ query = 'SELECT r.*, m.name AS module_name' . ' FROM `rules` AS r' . ' INNER JOIN `acl` AS a ON a.rule_id = r.id' . ' INNER JOIN `modules` AS m ON r.module_id = m.id' . ' WHERE a.group_id = ?' ; $ this -> db -> setQuery ( $ query ) ; $ this -> setCache ( 'acl' , $ this -> db -> loadObjectList ( $ this -> groupId ) ) ; } return $ this -> getCache ( 'acl' ) ; }
|
Load the rule list for this user . Cached .
|
47,567
|
public function getLanding ( ) : ? \ stdClass { $ query = ' SELECT m.`name` AS module, r.action' . ' FROM `acl` AS a' . ' INNER JOIN `rules` AS r ON r.id = a.rule_id' . ' INNER JOIN `modules` AS m ON m.id = r.module_id' . ' WHERE a.is_default = 1' . ' AND a.group_id = ?' ; $ this -> db -> setQuery ( $ query ) ; $ obj = $ this -> db -> loadObject ( $ this -> groupId ) ; return $ obj ; }
|
Get landing module and action as object properties where the user goes after login .
|
47,568
|
public function getLanguageCode ( ) { if ( ! $ this -> issetCache ( 'lang' ) ) { $ query = 'SELECT l.code' . ' FROM `languages` AS l' . ' INNER JOIN `locales` AS lc ON l.id = lc.language_id' . ' INNER JOIN `users` AS u ON u.locale_id = lc.id' . ' WHERE u.id = ?' ; $ this -> db -> setQuery ( $ query ) ; $ this -> setCache ( 'lang' , $ this -> db -> loadResult ( $ this -> id ) ) ; } return $ this -> getCache ( 'lang' ) ; }
|
Return the language code of this user . Cached .
|
47,569
|
public function getGroup ( ) : Group { if ( ! $ this -> issetCache ( 'group' ) ) { $ this -> setCache ( 'group' , new Group ( $ this -> groupId ) ) ; } return $ this -> getCache ( 'group' ) ; }
|
Get Group object for this user . Cached .
|
47,570
|
public function isDeletable ( ) : bool { $ app = Application :: getInstance ( ) ; if ( $ this -> id == $ app -> currentUser -> id ) { return FALSE ; } return parent :: isDeletable ( ) ; }
|
Check whether record of this object is deletable based on inverse foreign - key list and the user is not the same connected .
|
47,571
|
public function setNewPassword ( string $ newPassword , string $ timezone ) : bool { $ this -> pwReset = NULL ; $ this -> hash = static :: getHashedPasswordWithSalt ( $ newPassword ) ; if ( ! $ this -> store ( ) ) { return FALSE ; } $ this -> createSession ( $ timezone ) ; $ this -> resetFaults ( ) ; return TRUE ; }
|
Apply a password reset for this User .
|
47,572
|
public function renewRememberMe ( ) { $ cookieName = static :: getRememberMeCookieName ( ) ; if ( ! isset ( $ _COOKIE [ $ cookieName ] ) ) { return FALSE ; } $ expire = time ( ) + 60 * 60 * 24 * 30 ; return setcookie ( $ cookieName , $ _COOKIE [ $ cookieName ] , $ expire , '/' ) ; }
|
Update the expire date of RememberMe cookie .
|
47,573
|
public function getActiveRecordObjects ( $ class , $ orderBy = NULL , $ descOrder = FALSE ) { if ( ! class_exists ( $ class ) or ! is_subclass_of ( $ class , 'Pair\ActiveRecord' ) ) { return array ( ) ; } $ this -> db -> setQuery ( 'SELECT COUNT(*) FROM `' . $ class :: TABLE_NAME . '`' ) ; $ this -> pagination -> count = $ this -> db -> loadCount ( ) ; $ orderDir = $ descOrder ? 'DESC' : 'ASC' ; $ query = 'SELECT *' . ' FROM `' . $ class :: TABLE_NAME . '`' . ( $ orderBy ? ' ORDER BY `' . $ orderBy . '` ' . $ orderDir : NULL ) . ' LIMIT ' . $ this -> pagination -> start . ', ' . $ this -> pagination -> limit ; $ this -> db -> setQuery ( $ query ) ; $ list = $ this -> db -> loadObjectList ( ) ; $ objects = array ( ) ; foreach ( $ list as $ item ) { $ objects [ ] = new $ class ( $ item ) ; } return $ objects ; }
|
Returns list of all object specified in param within pagination limit and sets pagination count .
|
47,574
|
protected function getOrderLimitSql ( ) { $ router = Router :: getInstance ( ) ; $ ret = '' ; if ( $ router -> order ) { $ orderOptions = $ this -> getOrderOptions ( ) ; if ( isset ( $ orderOptions [ $ router -> order ] ) ) { $ ret = ' ORDER BY ' . $ orderOptions [ $ router -> order ] ; } } $ ret .= ' LIMIT ' . $ this -> pagination -> start . ', ' . $ this -> pagination -> limit ; return $ ret ; }
|
Create SQL code about ORDER and LIMIT .
|
47,575
|
final public static function getInstance ( ) { if ( NULL == self :: $ instance ) { self :: $ instance = new self ( ) ; self :: $ instance -> startChrono ( ) ; } return self :: $ instance ; }
|
Singleton instance method .
|
47,576
|
final public function isEnabled ( ) { if ( $ this -> disabled ) { return FALSE ; } $ app = Application :: getInstance ( ) ; $ router = Router :: getInstance ( ) ; if ( 'cli' == php_sapi_name ( ) or 'api' == $ router -> module ) { return FALSE ; } else if ( $ app -> currentUser ) { return ( Options :: get ( 'show_log' ) and $ app -> currentUser -> admin ) ; } else if ( 'user' == $ router -> module and 'login' == $ router -> action ) { return FALSE ; } else { return TRUE ; } }
|
Checks that logger is enabled by options and group of connected user .
|
47,577
|
final private function startChrono ( ) { $ this -> timeStart = $ this -> lastChrono = $ this -> getMicrotime ( ) ; $ this -> addEvent ( 'Starting Pair framework with base timezone ' . BASE_TIMEZONE ) ; }
|
Starts the time chrono .
|
47,578
|
final private function getMicrotime ( ) { list ( $ msec , $ sec ) = explode ( ' ' , microtime ( ) ) ; $ time = ( ( float ) $ msec + ( float ) $ sec ) ; return $ time ; }
|
Returns current time as float value .
|
47,579
|
final public function addEvent ( $ description , $ type = 'notice' , $ subtext = NULL ) { if ( ! $ this -> isEnabled ( ) ) return ; $ now = $ this -> getMicrotime ( ) ; $ event = new \ stdClass ( ) ; $ event -> description = $ description ; $ event -> type = $ type ; $ event -> subtext = $ subtext ; $ event -> chrono = abs ( $ now - $ this -> lastChrono ) ; $ this -> events [ ] = $ event ; $ this -> lastChrono = $ now ; }
|
Adds an event storing its chrono time .
|
47,580
|
final public function getEventListForAjax ( ) { $ app = Application :: getInstance ( ) ; $ router = Router :: getInstance ( ) ; if ( ! $ this -> isEnabled ( ) or ! $ router -> sendLog ( ) ) { return NULL ; } $ log = '' ; if ( Options :: get ( 'show_log' ) and $ app -> currentUser -> admin ) { $ showQueries = isset ( $ _COOKIE [ 'LogShowQueries' ] ) ? $ _COOKIE [ 'LogShowQueries' ] : 0 ; foreach ( $ this -> events as $ e ) { $ class = $ e -> type . ( ( 'query' == $ e -> type and ! $ showQueries ) ? ' hidden' : '' ) ; $ log .= '<div class="' . $ class . '"><span class="time">' . $ this -> formatChrono ( $ e -> chrono ) . '</span> ' . htmlspecialchars ( $ e -> description ) . ( $ e -> subtext ? ' <span>| ' . htmlspecialchars ( $ e -> subtext ) . '</span>' : '' ) . '</div>' ; } } return $ log ; }
|
Returns a formatted event list with no header useful for AJAX purpose .
|
47,581
|
public function isExpired ( $ sessionTime ) { if ( is_null ( $ this -> startTime ) ) { return TRUE ; } $ expiring = new \ DateTime ( NULL , new \ DateTimeZone ( BASE_TIMEZONE ) ) ; $ expiring -> sub ( new \ DateInterval ( 'PT' . ( int ) $ sessionTime . 'M' ) ) ; return ( $ this -> startTime < $ expiring ) ; }
|
Checks if a Session object is expired after sessionTime passed as parameter .
|
47,582
|
public function addItem ( $ url , $ title , $ badge = NULL , $ class = NULL , $ target = NULL ) { $ this -> items [ ] = self :: getItemObject ( $ url , $ title , $ badge , $ class , $ target ) ; }
|
Adds a single - item menu entry . The optional badge can be a subtitle .
|
47,583
|
public function addMulti ( $ title , $ list , $ class = NULL ) { $ multi = new \ stdClass ( ) ; $ multi -> type = 'multi' ; $ multi -> title = $ title ; $ multi -> class = $ class ; $ multi -> list = array ( ) ; foreach ( $ list as $ i ) { $ multi -> list [ ] = $ i ; } $ this -> items [ ] = $ multi ; }
|
Adds a multi - entry menu item . The list is array of single - item objects .
|
47,584
|
public function addSeparator ( $ title = NULL ) { $ item = new \ stdClass ( ) ; $ item -> type = 'separator' ; $ item -> title = $ title ; $ this -> items [ ] = $ item ; }
|
Adds a separator to menu .
|
47,585
|
public static function getItemObject ( $ url , $ title , $ badge = NULL , $ class = NULL , $ target = NULL ) { $ item = new \ stdClass ( ) ; $ item -> type = 'single' ; $ item -> url = $ url ; $ item -> title = $ title ; $ item -> badge = $ badge ; $ item -> class = $ class ; $ item -> target = $ target ; return $ item ; }
|
Static method utility to create single - item object .
|
47,586
|
public function render ( ) { $ app = Application :: getInstance ( ) ; $ ret = '' ; foreach ( $ this -> items as $ item ) { if ( isset ( $ item -> url ) and ! ( is_a ( $ app -> currentUser , 'Pair\User' ) and ! $ app -> currentUser -> canAccess ( $ item -> url ) ) ) { continue ; } switch ( $ item -> type ) { case 'single' : $ class = ( $ item -> url == $ app -> activeMenuItem ? ' active' : '' ) ; if ( $ item -> class ) { $ class .= ' ' . $ item -> class ; } $ ret .= $ item -> url ? '<a href="' . $ item -> url . '"' : '<div' ; $ ret .= ' class="item' . $ class . '"' . ( $ item -> target ? ' target="' . $ item -> target . '"' : '' ) . ( ! is_null ( $ item -> badge ) ? ' data-badge="' . ( int ) $ item -> badge . '" ' : '' ) . '>' . ( ! is_null ( $ item -> badge ) ? '<span class="badge">' . $ item -> badge . '</span>' : '' ) . '<span class="title">' . $ item -> title . '</span>' ; $ ret .= $ item -> url ? '</a>' : '</div>' ; break ; case 'multi' : $ links = '' ; $ menuClass = '' ; foreach ( $ item -> list as $ i ) { if ( isset ( $ i -> url ) and ! ( is_a ( $ app -> currentUser , 'Pair\User' ) and ! $ app -> currentUser -> canAccess ( $ i -> url ) ) ) { continue ; } if ( $ i -> url == $ app -> activeMenuItem ) { $ class = ' active' ; $ menuClass = ' open' ; } else { $ class = '' ; } if ( $ i -> class ) { $ class .= ' ' . $ i -> class ; } $ links .= '<a class="item' . $ class . '" href="' . $ i -> url . '">' . ( ! is_null ( $ i -> badge ) ? '<span class="badge">' . $ i -> badge . '</span>' : '' ) . '<span class="title">' . $ i -> title . '</span>' . '</a>' ; } if ( '' == $ links ) { break ; } $ ret .= '<div class="dropDownMenu' . $ menuClass . '">' . '<div class="title">' . $ item -> title . '</div>' . '<div class="itemGroup">' . $ links . '</div></div>' ; break ; case 'separator' : if ( ! $ item -> title ) $ item -> title = ' ' ; $ ret .= '<div class="separator">' . $ item -> title . '</div>' ; break ; } } return $ ret ; }
|
Builds HTML of this menu .
|
47,587
|
public static function get ( $ name , $ type = 'string' , $ default = NULL ) { $ val = "" ; switch ( $ _SERVER [ 'REQUEST_METHOD' ] ) { case 'GET' : $ request = & $ _GET ; break ; case 'POST' : $ request = & $ _POST ; break ; default : $ request = & $ _REQUEST ; break ; } if ( substr ( $ name , - 2 ) == '[]' ) { $ name = substr ( $ name , 0 , - 2 ) ; } if ( array_key_exists ( $ name , $ request ) ) { if ( is_array ( $ request [ $ name ] ) ) { $ values = array ( ) ; foreach ( $ request [ $ name ] as $ val ) { $ values [ ] = self :: castTo ( $ val , $ type ) ; } return $ values ; } else { return self :: castTo ( $ request [ $ name ] , $ type ) ; } } else { return self :: castTo ( $ default , $ type ) ; } }
|
Get data by POST or GET array returning the specified type or default value . In case of not found return default value . Manage array inputs .
|
47,588
|
public static function isSent ( $ name ) { if ( substr ( $ name , - 2 ) == '[]' ) { $ name = substr ( $ name , 0 , - 2 ) ; } return ( array_key_exists ( $ name , $ _REQUEST ) ) ; }
|
Check wheter a field was submitted in the REQUEST array .
|
47,589
|
public static function getInputsByRegex ( $ pattern , $ type = 'string' , $ default = NULL ) { $ list = array ( ) ; foreach ( $ _POST as $ name => $ value ) { if ( preg_match ( $ pattern , $ name ) or $ default ) { $ val = $ _POST [ $ name ] ? $ _POST [ $ name ] : $ default ; $ val = self :: castTo ( $ val , $ type ) ; $ list [ $ name ] = $ val ; } } return $ list ; }
|
Gets all submitted field name that matches regular expressions .
|
47,590
|
private static function castTo ( $ val , $ type ) { $ app = Application :: getInstance ( ) ; switch ( $ type ) { case 'string' : case 'text' : $ val = ( string ) $ val ; break ; case 'int' : case 'integer' : $ val = ( int ) $ val ; break ; case 'bool' : case 'boolean' : $ val = ( bool ) $ val ; break ; case 'date' : if ( $ val ) { if ( ( defined ( 'PAIR_FORM_DATE_FORMAT' ) and self :: usingCustomDatepicker ( ) ) ) { $ format = PAIR_FORM_DATE_FORMAT ; } else { $ format = 'Y-m-d' ; } $ val = \ DateTime :: createFromFormat ( '!' . $ format , $ val , $ app -> currentUser -> getDateTimeZone ( ) ) ; if ( FALSE === $ val ) $ val = NULL ; } else { $ val = NULL ; } break ; case 'datetime' : if ( $ val ) { if ( ( defined ( 'PAIR_FORM_DATETIME_FORMAT' ) and self :: usingCustomDatetimepicker ( ) ) ) { $ format = PAIR_FORM_DATETIME_FORMAT ; } else { $ format = 'Y-m-d H:i:s' ; } $ val = \ DateTime :: createFromFormat ( '!' . $ format , $ val , $ app -> currentUser -> getDateTimeZone ( ) ) ; if ( FALSE === $ val ) $ val = NULL ; } else { $ val = NULL ; } break ; } return $ val ; }
|
Casts a value to a type string integer or boolean .
|
47,591
|
public static function createPluginByManifest ( \ SimpleXMLElement $ manifest ) { $ app = Application :: getInstance ( ) ; $ mPlugin = $ manifest -> plugin ; $ mAttributes = $ mPlugin -> attributes ( ) ; $ class = ucfirst ( $ mAttributes -> type ) ; if ( in_array ( $ class , array ( 'Module' , 'Template' ) ) ) { $ class = 'Pair\\' . $ class ; } if ( $ class :: pluginExists ( $ mPlugin -> name ) ) { $ app -> enqueueError ( 'PLUGIN_IS_ALREADY_INSTALLED' ) ; return NULL ; } $ plugin = new $ class ( ) ; $ plugin -> name = ( string ) $ mPlugin -> name ; $ plugin -> version = ( string ) $ mPlugin -> version ; $ plugin -> dateReleased = date ( 'Y-m-d H:i:s' , strtotime ( ( string ) $ mPlugin -> dateReleased ) ) ; $ plugin -> appVersion = ( string ) $ mPlugin -> appVersion ; $ plugin -> installedBy = $ app -> currentUser -> id ; $ plugin -> dateInstalled = new \ DateTime ( ) ; $ plugin -> storeByPlugin ( $ mPlugin -> options ) ; return $ plugin ; }
|
Insert a new db record for the plugin in manifest . Return an object of the plugin type .
|
47,592
|
private static function folderToZip ( $ folder , & $ zipFile , $ parentPath ) { $ handle = opendir ( $ folder ) ; while ( false !== $ f = readdir ( $ handle ) ) { $ excluded = array ( '.' , '..' , '.DS_Store' , 'thumbs.db' ) ; if ( ! in_array ( $ f , $ excluded ) ) { $ filePath = $ folder . '/' . $ f ; if ( 0 === strpos ( $ filePath , $ parentPath ) ) { $ localPath = substr ( $ filePath , strlen ( $ parentPath . '/' ) ) ; } if ( is_file ( $ filePath ) ) { $ zipFile -> addFile ( $ filePath , $ localPath ) ; } elseif ( is_dir ( $ filePath ) ) { $ zipFile -> addEmptyDir ( $ localPath ) ; self :: folderToZip ( $ filePath , $ zipFile , $ parentPath ) ; } } } closedir ( $ handle ) ; }
|
Recursively adds all files and all sub - directories to a ZIP file .
|
47,593
|
public static function checkTemporaryFolder ( ) { if ( ! file_exists ( static :: TEMP_FOLDER ) or ! is_dir ( static :: TEMP_FOLDER ) ) { @ unlink ( static :: TEMP_FOLDER ) ; $ old = umask ( 0 ) ; if ( ! mkdir ( static :: TEMP_FOLDER , 0777 , TRUE ) ) { trigger_error ( 'Directory creation on ' . static :: TEMP_FOLDER . ' failed' ) ; $ ret = FALSE ; } umask ( $ old ) ; if ( ! chmod ( static :: TEMP_FOLDER , 0777 ) ) { trigger_error ( 'Set permissions on directory ' . static :: TEMP_FOLDER . ' failed' ) ; $ ret = FALSE ; } } }
|
Check temporary folder or create it .
|
47,594
|
public static function removeOldFiles ( ) { if ( ! is_dir ( static :: TEMP_FOLDER ) ) { return ; } $ app = Application :: getInstance ( ) ; $ counter = 0 ; $ files = Utilities :: getDirectoryFilenames ( static :: TEMP_FOLDER ) ; foreach ( $ files as $ file ) { $ pathFile = APPLICATION_PATH . '/' . static :: TEMP_FOLDER . '/' . $ file ; $ fileLife = time ( ) - filemtime ( $ pathFile ) ; $ maxLife = static :: FILE_EXPIRE * 60 ; if ( $ fileLife > $ maxLife ) { $ counter ++ ; unlink ( $ pathFile ) ; } } if ( $ counter ) { $ app -> logEvent ( $ counter . ' files has been deleted from ' . static :: TEMP_FOLDER ) ; } else { $ app -> logEvent ( 'No old files deleted from ' . static :: TEMP_FOLDER ) ; } }
|
Deletes file with created date older than EXPIRE_TIME const .
|
47,595
|
public function createManifestFile ( ) { $ app = Application :: getInstance ( ) ; $ addChildArray = function ( $ element , $ list ) use ( $ app , & $ addChildArray ) { foreach ( $ list as $ name => $ value ) { if ( is_array ( $ value ) ) { $ listChild = $ element -> addChild ( $ name ) ; $ addChildArray ( $ listChild , $ value ) ; } else if ( is_int ( $ value ) or is_string ( $ value ) ) { $ element -> addChild ( $ name , ( string ) $ value ) ; } else { $ app -> logError ( 'Option item ' . $ name . ' is not valid' ) ; } } } ; if ( ! is_dir ( $ this -> baseFolder ) ) { $ app -> logError ( 'Folder ' . $ this -> baseFolder . ' of ' . $ this -> name . ' ' . $ this -> type . ' plugin cannot be accessed' ) ; return FALSE ; } $ manifest = new \ SimpleXMLElement ( '<!DOCTYPE xml><manifest></manifest>' ) ; $ plugin = $ manifest -> addChild ( 'plugin' ) ; $ plugin -> addAttribute ( 'type' , $ this -> type ) ; $ plugin -> addChild ( 'name' , $ this -> name ) ; $ plugin -> addChild ( 'folder' , basename ( $ this -> baseFolder ) ) ; $ plugin -> addChild ( 'version' , $ this -> version ) ; $ plugin -> addChild ( 'dateReleased' , $ this -> dateReleased ) ; $ plugin -> addChild ( 'appVersion' , $ this -> appVersion ) ; $ optionsChild = $ plugin -> addChild ( 'options' ) ; $ addChildArray ( $ optionsChild , $ this -> options ) ; $ filesChild = $ plugin -> addChild ( 'files' ) ; $ files = Utilities :: getDirectoryFilenames ( $ this -> baseFolder ) ; foreach ( $ files as $ file ) { $ filesChild -> addChild ( 'file' , $ file ) ; } $ filename = $ this -> baseFolder . '/manifest.xml' ; try { $ res = $ manifest -> asXML ( $ filename ) ; $ app -> logEvent ( 'Created manifest file ' . $ filename . ' for ' . $ this -> type . ' plugin' ) ; } catch ( \ Exception $ e ) { $ res = FALSE ; $ app -> logError ( 'Manifest file ' . $ filename . ' creation failed for ' . $ this -> type . ' plugin: ' . $ e -> getMessage ( ) ) ; } return $ res ; }
|
Creates or updates manifest . xml file for declare package content .
|
47,596
|
protected function beforeDelete ( ) { $ acls = Acl :: getAllObjects ( array ( 'ruleId' => $ this -> id ) ) ; foreach ( $ acls as $ acl ) { $ acl -> delete ( ) ; } }
|
Deletes all Acl of this Rule .
|
47,597
|
public function getModule ( ) { $ class = 'Module' ; $ id = $ this -> moduleId ; if ( ! $ this -> issetCache ( $ class ) ) { $ this -> setCache ( $ class , new Module ( $ id ) ) ; } return $ this -> getCache ( $ class ) ; }
|
Return related Module object . Cached .
|
47,598
|
public static function getRuleModuleName ( $ module_id , $ action , $ adminOnly ) { $ db = Database :: getInstance ( ) ; $ query = ' SELECT m.name AS moduleName,r.action AS ruleAction, r.admin_only ' . ' FROM `rules` AS r ' . ' INNER JOIN `modules` AS m ON m.id = r.module_id ' . ' WHERE m.id = ? AND r.action = ? AND r.admin_only = ?' ; $ db -> setQuery ( $ query ) ; $ module = $ db -> loadObject ( array ( $ module_id , $ action , $ adminOnly ) ) ; return $ module ; }
|
Returns the db - record of the current Rule object NULL otherwise .
|
47,599
|
private function openConnection ( $ persistent = FALSE ) { if ( is_a ( $ this -> handler , 'PDO' ) ) { return ; } switch ( DBMS ) { default : case 'mysql' : $ dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME ; $ options = array ( \ PDO :: ATTR_PERSISTENT => ( bool ) $ persistent , \ PDO :: MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" , \ PDO :: MYSQL_ATTR_FOUND_ROWS => TRUE ) ; break ; case 'mssql' : $ dsn = 'dblib:host=' . DB_HOST . ';dbname=' . DB_NAME ; $ options = [ ] ; break ; } try { $ this -> handler = new \ PDO ( $ dsn , DB_USER , DB_PASS , $ options ) ; if ( is_a ( $ this -> handler , 'PDO' ) ) { $ this -> handler -> setAttribute ( \ PDO :: ATTR_ERRMODE , \ PDO :: ERRMODE_EXCEPTION ) ; } else { throw new \ PDOException ( 'Db handler is not valid, connection failed' ) ; } } catch ( \ Exception $ e ) { exit ( $ e -> getMessage ( ) ) ; } }
|
Connects to DBMS with params only if PDO handler property is null so not connected .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.