idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
23,200 | public function multiPersist ( $ entities ) { if ( ! $ this -> isRepositoryWritable ( ) ) { throw $ this -> createNotWritableException ( ) ; } return $ this -> trigger ( __FUNCTION__ , [ 'entities' => $ entities , ] ) ; } | Persist the given object and flushes it to the storage device . |
23,201 | protected function trigger ( $ name , array $ params ) { $ event = clone $ this -> getEvent ( ) ; $ event -> setName ( $ name ) ; $ event -> setParams ( $ params ) ; $ responseCollection = $ this -> getEventManager ( ) -> triggerEvent ( $ event ) ; if ( $ responseCollection -> stopped ( ) && $ event -> isError ( ) ) { throw new RuntimeException ( $ event -> getError ( ) , $ event -> getErrorNr ( ) ) ; } return $ event -> getResult ( ) ; } | will prepare the event object and trigger the event using the internal EventManager |
23,202 | public function commitTransaction ( ) { if ( $ this -> isTransactionEnabled ( ) === false ) { throw new ServiceException ( sprintf ( 'The repository for %s doesn\'t support Transactions' , $ this -> getEntityServiceName ( ) ) ) ; } $ this -> getRepository ( ) -> commitTransaction ( ) ; } | Commits a started transaction . |
23,203 | public function rollbackTransaction ( ) { if ( $ this -> isTransactionEnabled ( ) === false ) { throw new ServiceException ( sprintf ( 'The repository for %s doesn\'t support Transactions' , $ this -> getEntityServiceName ( ) ) ) ; } $ this -> getRepository ( ) -> rollbackTransaction ( ) ; } | Rolls back a started transaction . |
23,204 | public function call ( $ name , $ data = null , $ nest = null ) { if ( ! is_null ( $ data ) ) { $ this -> data = array_merge ( $ this -> data , $ data ) ; } if ( ! $ this -> exists ( $ name , $ nest ) ) { throw new ViewNotFoundException ( $ name ) ; } else { $ data = $ this -> exists ( $ name , $ nest ) ; $ this -> path = $ data [ 'path' ] ; $ this -> engine = $ data [ 'engine' ] ; $ this -> nest = $ nest ; } $ nameSegments = dot ( $ name ) ; $ this -> name = $ this -> setName ( $ nameSegments ) ; return $ this ; } | Call a view . |
23,205 | public function exists ( $ name , $ nest = null ) { $ file = str_replace ( '.' , '/' , $ name ) ; $ extensions = [ '.php' , '.atom.php' , '.atom' , '.tpl.php' , ] ; if ( ! is_null ( $ nest ) ) { $ nest = $ nest . 'resources/views/' ; } elseif ( ! is_null ( $ this -> nest ) ) { $ nest = $ this -> nest ; } else { $ nest = root ( ) . 'resources/views/' ; } $ i = 0 ; foreach ( $ extensions as $ extension ) { $ path = $ nest . $ file . $ extension ; if ( file_exists ( $ path ) ) { if ( $ i == 0 ) { $ view = [ 'path' => $ path , 'engine' => 'none' ] ; } elseif ( $ i == 1 || $ i == 2 ) { $ view = [ 'path' => $ path , 'engine' => 'atomium' ] ; } elseif ( $ i == 3 ) { $ view = [ 'path' => $ path , 'engine' => 'smarty' ] ; } return $ view ; } $ i ++ ; } return false ; } | Check if view exists . |
23,206 | public function with ( $ data , $ value = null ) { if ( is_string ( $ data ) ) { $ this -> data = array_merge ( $ this -> data , [ $ data => $ value ] ) ; } elseif ( is_array ( $ data ) ) { $ this -> data = array_merge ( $ this -> data , $ data ) ; } return $ this ; } | Add variables to the view . |
23,207 | public function show ( self $ _vinala_view = null ) { if ( is_null ( $ _vinala_view ) ) { $ _vinala_view = $ this ; } if ( $ _vinala_view -> engine == 'atomium' ) { self :: atomium ( $ _vinala_view -> path , $ _vinala_view -> data , $ _vinala_view -> nest ) ; } elseif ( $ _vinala_view -> engine == 'smarty' ) { Template :: show ( $ _vinala_view -> path , $ _vinala_view -> data ) ; } else { if ( ! is_null ( $ _vinala_view -> data ) ) { foreach ( $ _vinala_view -> data as $ _vinala_view_keys => $ _vinala_view_values ) { $ $ _vinala_view_keys = $ _vinala_view_values ; } } include $ _vinala_view -> path ; } } | Show the view . |
23,208 | protected function atomium ( $ file , $ data , $ nest = null ) { $ atomium = new Atomium ( $ nest ) ; return $ atomium -> show ( $ file , $ data ) ; } | Show atomium view . |
23,209 | public static function Tf2a ( $ s , $ ihour , $ imin , $ sec , & $ rad ) { $ rad = ( $ s == '-' ? - 1.0 : 1.0 ) * ( 60.0 * ( 60.0 * ( ( double ) abs ( $ ihour ) ) + ( ( double ) abs ( $ imin ) ) ) + abs ( $ sec ) ) * DS2R ; if ( $ ihour < 0 || $ ihour > 23 ) return 1 ; if ( $ imin < 0 || $ imin > 59 ) return 2 ; if ( $ sec < 0.0 || $ sec >= 60.0 ) return 3 ; return 0 ; } | - - - - - - - - i a u T f 2 a - - - - - - - - |
23,210 | public static function on ( ) { foreach ( self :: $ classes as $ k => $ class ) { if ( ! class_exists ( $ class ) ) { if ( class_exists ( 'Prototypemvc\Core\\' . $ class ) ) { class_alias ( 'Prototypemvc\Core\\' . $ class , $ class ) ; } else if ( class_exists ( 'Prototypemvc\Helpers\\' . $ class ) ) { class_alias ( 'Prototypemvc\Helpers\\' . $ class , $ class ) ; } } } } | Bypass namespaces . WARNING! Not recommended for use in a production environment because of poor performance . But fine in development for rapid prototyping . |
23,211 | public static function endsWith ( $ string , $ look ) { return strrpos ( $ string , $ look ) === strlen ( $ string ) - strlen ( $ look ) ; } | Check to see if string starts with a string |
23,212 | public function addResolver ( EmailPartResolver $ resolver , $ part ) : self { $ this -> resolvers [ $ part ] = $ resolver ; return $ this ; } | Add Resolver . |
23,213 | public function getResolverForPart ( EmailPart $ part ) : EmailPartResolver { $ identifier = get_class ( $ part ) ; if ( ! array_key_exists ( $ identifier , $ this -> resolvers ) ) { throw new InvalidArgumentException ( sprintf ( 'Resolver for the part "%s" does not exists. Please choose one of the following: %s' , $ identifier , implode ( ', ' , array_keys ( $ this -> resolvers ) ) ) ) ; } return $ this -> resolvers [ $ identifier ] ; } | Get resolver for given email part . |
23,214 | public function renderHelp ( ) { $ this -> renderHeader ( ) ; echo Line :: begin ( 'Usage:' , Line :: YELLOW ) -> nl ( ) ; echo Line :: begin ( ) -> indent ( 2 ) -> text ( $ this -> getUsage ( ) ) -> nl ( 2 ) ; echo Line :: begin ( 'Options:' , Line :: YELLOW ) -> nl ( ) ; echo Line :: begin ( ) -> indent ( 2 ) -> text ( '--help' , Line :: MAGENTA ) -> to ( 21 ) -> text ( '-h' , Line :: MAGENTA ) -> text ( 'Display this help message.' ) -> nl ( 1 ) ; $ attributes = $ this -> attributeNames ( ) ; $ help = $ this -> attributeHelp ( ) ; sort ( $ attributes ) ; foreach ( $ attributes as $ name ) { echo Line :: begin ( ) -> indent ( 2 ) -> text ( "--$name" , Line :: MAGENTA ) -> to ( 24 ) -> text ( isset ( $ help [ $ name ] ) ? $ help [ $ name ] : '' ) -> nl ( ) ; } exit ( 0 ) ; } | Displays the help for this generator . |
23,215 | public static function create ( $ name , array $ config = array ( ) ) { if ( ! isset ( self :: $ config -> generators [ $ name ] ) ) { throw new Exception ( "Unknown generator '$name'." ) ; } $ generator = \ Yii :: createComponent ( \ CMap :: mergeArray ( self :: $ config -> generators [ $ name ] , $ config ) ) ; $ generator -> init ( ) ; foreach ( self :: $ config -> attributes as $ attribute => $ value ) { if ( property_exists ( $ generator , $ attribute ) ) { $ generator -> $ attribute = $ value ; } } return $ generator ; } | Creates a new generator . |
23,216 | public static function run ( $ name , array $ config = array ( ) ) { $ generator = self :: create ( $ name , $ config ) ; if ( ! $ generator -> validate ( ) ) { $ generator -> renderErrors ( ) ; } return $ generator -> generate ( ) ; } | Creates and runs a specific generator . |
23,217 | private function getPluginController ( $ class ) { if ( $ this -> pluginControllers === null ) { $ this -> pluginControllers = file_exists ( $ this -> pluginManifestOfControllers ) ? include $ this -> pluginManifestOfControllers : [ ] ; } return isset ( $ this -> pluginControllers [ $ class ] ) && count ( $ this -> pluginControllers [ $ class ] ) == 1 ? $ this -> pluginControllers [ $ class ] [ 0 ] : null ; } | Get the full qualified class name of the plugin s controller . |
23,218 | private function find ( Contracts \ Request $ request ) { $ method = $ request -> method ( ) ; $ path = $ request -> path ( ) ; foreach ( $ this -> routes as $ route ) { if ( $ route -> method == $ method ) { $ pattern = $ this -> pattern ( $ route ) ; if ( preg_match ( $ pattern , $ path ) ) { return $ route ; } } } return null ; } | Find the route matching the given request . |
23,219 | private function getParameters ( Contracts \ Request $ request , $ route ) { $ path = $ request -> path ( ) ; $ pattern = $ this -> pattern ( $ route ) ; if ( preg_match_all ( $ pattern , $ path , $ matches , PREG_SET_ORDER ) === false ) { return [ ] ; } unset ( $ matches [ 0 ] [ 0 ] ) ; $ matches = array_values ( $ matches [ 0 ] ) ; return $ matches ; } | Get parameters of the request . |
23,220 | public function toQueryString ( $ separator = '&' , $ encoding = PHP_QUERY_RFC3986 ) { return http_build_query ( $ this -> toArray ( ) , null , $ separator , $ encoding ) ; } | Returns a HTTP query string of the values |
23,221 | public function isActive ( ) : bool { if ( $ this -> isNested ( ) ) { return str_contains ( url ( ) -> current ( ) , $ this -> url ) ; } return url ( $ this -> url ) == url ( ) -> current ( ) ; } | Check if the current item is active . |
23,222 | public function activeAttr ( string $ className = '' ) : string { if ( ! $ className ) { $ className = config ( 'menus.active_class_name' ) ; } return $ this -> isActive ( ) ? 'class="' . $ className . '"' : '' ; } | Output active class attribute . |
23,223 | public function activeClass ( string $ className = '' ) : string { if ( ! $ className ) { $ className = config ( 'menus.active_class_name' ) ; } return $ this -> isActive ( ) ? $ className : '' ; } | Return active class name . |
23,224 | public function execute ( ) { if ( ! isset ( $ this -> options [ CURLOPT_TIMEOUT ] ) ) { $ this -> options [ CURLOPT_TIMEOUT ] = 30 ; } if ( ! isset ( $ this -> options [ CURLOPT_RETURNTRANSFER ] ) ) { $ this -> options [ CURLOPT_RETURNTRANSFER ] = TRUE ; } if ( ! isset ( $ this -> options [ CURLOPT_FAILONERROR ] ) ) { $ this -> options [ CURLOPT_FAILONERROR ] = TRUE ; } if ( ! ini_get ( 'safe_mode' ) && ! ini_get ( 'open_basedir' ) ) { if ( ! isset ( $ this -> options [ CURLOPT_FOLLOWLOCATION ] ) ) { $ this -> options [ CURLOPT_FOLLOWLOCATION ] = TRUE ; } } if ( ! empty ( $ this -> headers ) ) { $ this -> option ( CURLOPT_HTTPHEADER , $ this -> headers ) ; } $ this -> options ( ) ; curl_setopt ( $ this -> session , CURLINFO_HEADER_OUT , true ) ; curl_setopt ( $ this -> session , CURLOPT_HEADER , 1 ) ; $ this -> response = curl_exec ( $ this -> session ) ; if ( $ this -> response !== false ) { $ this -> info = curl_getinfo ( $ this -> session ) ; list ( $ this -> response_header , $ this -> response ) = explode ( "\r\n\r\n" , $ this -> response ) ; if ( defined ( 'CURL_DEBUG' ) && $ this -> log !== null ) { $ this -> log -> addInfo ( $ this -> url , [ "Request" => $ this -> info , "Response" => $ this -> response ] ) ; } } else { if ( defined ( 'CURL_DEBUG' ) && $ this -> log !== null ) { $ this -> log -> addError ( "Server not responding!" , [ "URL" => $ this -> url ] , [ "message" => "test" ] ) ; } } if ( $ this -> response === FALSE ) { $ errno = curl_errno ( $ this -> session ) ; $ error = curl_error ( $ this -> session ) ; curl_close ( $ this -> session ) ; $ this -> set_defaults ( ) ; $ this -> error_code = $ errno ; $ this -> error_string = $ error ; return FALSE ; } else { curl_close ( $ this -> session ) ; $ this -> last_response = $ this -> response ; $ this -> last_response_header = $ this -> response_header ; $ this -> last_info = $ this -> info ; $ this -> set_defaults ( ) ; return $ this -> last_response ; } } | End a session and return the results |
23,225 | public function check ( ) { $ this -> _errors = [ ] ; foreach ( $ this -> _elements as $ element ) { $ element -> check ( ) ; if ( $ element -> valid ( ) == false ) { $ this -> _errors = array_merge ( $ this -> _errors , $ element -> errors ( ) ) ; } } } | check a form request |
23,226 | public function checkbox ( $ field , $ label ) { $ checkbox = new Checkbox ( $ this -> _entity , $ field , $ label ) ; array_push ( $ this -> _elements , $ checkbox ) ; return $ checkbox ; } | add checkbox element |
23,227 | public function select ( $ field , $ label ) { $ select = new Select ( $ this -> _entity , $ field , $ label ) ; array_push ( $ this -> _elements , $ select ) ; return $ select ; } | add select element |
23,228 | public function file ( $ field , $ label ) { $ file = new File ( $ this -> _entity , $ field , $ label ) ; array_push ( $ this -> _elements , $ file ) ; return $ file ; } | add file element |
23,229 | protected function doSearch ( array $ rows , $ title , $ language = null ) { if ( $ language === null ) { $ language = $ this -> defaultLanguage ; } $ results = [ ] ; foreach ( $ rows as $ row ) { $ node = $ this -> treeManager -> getByNodeId ( $ row [ 'id' ] ) -> get ( $ row [ 'id' ] ) ; if ( ! $ this -> authorizationChecker -> isGranted ( 'ROLE_SUPER_ADMIN' ) && ! $ this -> authorizationChecker -> isGranted ( 'VIEW' , $ node ) ) { continue ; } $ element = $ this -> elementService -> findElement ( $ node -> getTypeId ( ) ) ; $ elementVersion = $ this -> elementService -> findLatestElementVersion ( $ element ) ; $ siteroot = $ this -> siterootManager -> find ( $ node -> getTree ( ) -> getSiterootId ( ) ) ; $ handlerData = array ( 'handler' => 'element' , 'parameters' => array ( 'id' => $ node -> getId ( ) , 'siteroot_id' => $ node -> getTree ( ) -> getSiterootId ( ) , 'title' => $ siteroot -> getTitle ( $ language ) , 'start_tid_path' => '/' . implode ( '/' , $ node -> getTree ( ) -> getIdPath ( $ node ) ) , ) , ) ; $ createUserName = 'Unknown User' ; try { $ createUser = $ this -> userManager -> find ( $ elementVersion -> getCreateUserId ( ) ) ; if ( $ createUser ) { $ createUserName = $ createUser -> getDisplayName ( ) ; } } catch ( \ Exception $ e ) { } $ icon = $ this -> iconResolver -> resolveTreeNode ( $ node , $ language ) ; $ results [ ] = new SearchResult ( $ node -> getId ( ) , $ siteroot -> getTitle ( $ language ) . ' :: ' . $ elementVersion -> getBackendTitle ( $ language ) . ' (' . $ language . ', ' . $ node -> getId ( ) . ')' , $ createUserName , $ elementVersion -> getCreatedAt ( ) , $ icon , $ title , $ handlerData ) ; } return $ results ; } | Perform search . |
23,230 | public function newAction ( Request $ request ) { $ actorClass = $ this -> container -> get ( 'core_manager' ) -> getActorClass ( ) ; $ actor = new $ actorClass ( ) ; $ form = $ this -> createForm ( $ this -> get ( 'core_manager' ) -> getActorBundleName ( ) . '\Form\ActorType' , $ actor ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ factory = $ this -> get ( 'security.encoder_factory' ) ; $ encoder = $ factory -> getEncoder ( new BaseActor ( ) ) ; $ encodePassword = $ encoder -> encodePassword ( $ actor -> getPassword ( ) , $ actor -> getSalt ( ) ) ; $ actor -> setPassword ( $ encodePassword ) ; $ role = $ em -> getRepository ( 'CoreBundle:Role' ) -> findOneByRole ( Role :: USER ) ; $ actor -> addRole ( $ role ) ; $ em -> persist ( $ actor ) ; $ em -> flush ( ) ; $ filesData = $ request -> files -> get ( 'actor' ) ; if ( isset ( $ filesData [ 'image' ] [ 'file' ] ) && $ filesData [ 'image' ] [ 'file' ] instanceof UploadedFile ) { $ this -> get ( 'core_manager' ) -> uploadProfileImage ( $ actor ) ; } $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'actor.created' ) ; return $ this -> redirectToRoute ( 'core_actor_show' , array ( 'id' => $ actor -> getId ( ) ) ) ; } return array ( 'entity' => $ actor , 'form' => $ form -> createView ( ) , ) ; } | Creates a new Actor entity . |
23,231 | public function editAction ( Request $ request , Actor $ actor ) { $ oldPassword = $ actor -> getPassword ( ) ; $ deleteForm = $ this -> createDeleteForm ( $ actor ) ; $ editForm = $ this -> createForm ( 'CoreBundle\Form\ActorEditType' , $ actor ) ; $ editForm -> handleRequest ( $ request ) ; if ( $ editForm -> isSubmitted ( ) && $ editForm -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; if ( $ actor -> getRemoveImage ( ) ) { $ actor -> setImage ( null ) ; } $ password = $ editForm -> getNormData ( ) -> getPassword ( ) ; if ( $ password != '' ) { $ factory = $ this -> get ( 'security.encoder_factory' ) ; $ encoder = $ factory -> getEncoder ( new BaseActor ( ) ) ; $ encodePassword = $ encoder -> encodePassword ( $ password , $ actor -> getSalt ( ) ) ; $ actor -> setPassword ( $ encodePassword ) ; } else { $ actor -> setPassword ( $ oldPassword ) ; } $ em -> persist ( $ actor ) ; $ em -> flush ( ) ; $ filesData = $ request -> files -> get ( 'actor_edit' ) ; if ( isset ( $ filesData [ 'image' ] [ 'file' ] ) && $ filesData [ 'image' ] [ 'file' ] instanceof UploadedFile ) { $ this -> get ( 'core_manager' ) -> uploadProfileImage ( $ actor ) ; } $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'actor.edited' ) ; return $ this -> redirectToRoute ( 'core_actor_show' , array ( 'id' => $ actor -> getId ( ) ) ) ; } return array ( 'entity' => $ actor , 'edit_form' => $ editForm -> createView ( ) , 'delete_form' => $ deleteForm -> createView ( ) , ) ; } | Displays a form to edit an existing Actor entity . |
23,232 | public function getServedUrls ( $ path ) { $ isServedAs = [ ] ; foreach ( $ this -> paths as $ exposedPath => $ exposedDirectory ) { $ relative = $ this -> getRelative ( $ path , $ exposedDirectory ) ; if ( ! is_null ( $ relative ) ) { $ isServedAs [ ] = $ this -> getHost ( ) . preg_replace ( ',/$,' , '' , $ exposedPath ) . $ relative ; } } return $ isServedAs ; } | Gets the served urls . |
23,233 | public function getExposedPath ( $ url ) { $ isExposedAs = '' ; list ( $ host , $ path ) = $ this -> getUriHostAndPath ( $ url ) ; if ( $ host == $ this -> host ) { foreach ( $ this -> paths as $ exposedPath => $ exposedDirectory ) { $ relative = $ this -> getRelative ( $ path , $ exposedPath ) ; if ( ! is_null ( $ relative ) ) { $ isExposedAs = $ exposedDirectory . $ relative ; break ; } } } return $ isExposedAs ; } | Gets the exposed path . |
23,234 | private function getRelative ( $ path , $ against ) { $ relative = null ; if ( preg_replace ( ',/$,' , '' , $ path ) == $ against || Path :: isBasePath ( $ against , Path :: getDirectory ( $ path ) ) ) { $ relative = Path :: makeRelative ( $ path , $ against ) ; $ relative = $ relative ? '/' . $ relative : '' ; } return $ relative ; } | Gets the relative path if it matches against another path . |
23,235 | private function getUriHostAndPath ( $ url ) { try { $ uri = HttpUri :: createFromString ( $ url ) ; } catch ( InvalidArgumentException $ e ) { return [ '' , '' ] ; } $ host = $ uri -> getHost ( ) ; $ port = $ uri -> getPort ( ) ; if ( ! $ port && $ uri -> getScheme ( ) == 'https' ) { $ port = 443 ; } if ( $ port ) { $ host .= ':' . strval ( $ port ) ; } $ path = $ uri -> getPath ( ) ; if ( ! $ path ) { $ path = '/' ; } return [ $ host , $ path ] ; } | Gets the uri host and path . |
23,236 | public function connect ( ) { if ( ! $ this -> connected ) { if ( $ this -> config [ 'host' ] { 0 } == '/' ) { $ connector = $ this -> config [ 'driver' ] . ':unix_socket=' . $ this -> config [ 'host' ] . ';dbname=' . $ this -> config [ 'db' ] ; } else { $ connector = $ this -> config [ 'driver' ] . ':host=' . $ this -> config [ 'host' ] . ';dbname=' . $ this -> config [ 'db' ] ; } if ( $ this -> config [ 'driver' ] == 'sqlite' ) { $ connector = $ this -> config [ 'driver' ] . ':' . $ this -> config [ 'file' ] . '' ; } parent :: __construct ( $ connector , $ this -> config [ 'user' ] , $ this -> config [ 'pass' ] ) ; $ this -> setAttribute ( \ PDO :: ATTR_CASE , \ PDO :: CASE_NATURAL ) ; $ this -> setAttribute ( \ PDO :: ATTR_ERRMODE , \ PDO :: ERRMODE_EXCEPTION ) ; if ( isset ( $ this -> config [ 'encoding' ] ) && $ this -> config [ 'driver' ] != 'sqlite' ) { parent :: exec ( 'SET NAMES ' . $ this -> config [ 'encoding' ] ) ; } $ this -> connected = true ; } } | Connects to the Database . |
23,237 | public function get ( $ query , $ token = null ) { if ( is_scalar ( $ token ) ) $ token = [ $ token ] ; $ accesskey = null ; $ found = preg_match ( '=SELECT.+>([a-z_]+).+FROM=is' , $ query , $ match ) ; if ( $ found === 1 ) { $ accesskey = $ match [ 1 ] ; $ query = str_replace ( '>' . $ accesskey , $ accesskey , $ query ) ; } $ this -> connect ( ) ; $ sth = $ this -> prepare ( $ query ) ; $ returner [ 'SUCCESS' ] = $ sth -> execute ( $ token ) ; $ returner [ 'RESULT' ] = $ sth -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; $ returner [ 'NUM_ROWS' ] = count ( $ returner [ 'RESULT' ] ) ; if ( ! is_null ( $ accesskey ) ) { $ newreturner = [ ] ; foreach ( $ returner [ 'RESULT' ] as $ row ) { $ newreturner [ $ row [ $ accesskey ] ] = $ row ; } $ returner [ 'RESULT' ] = $ newreturner ; } return $ returner ; } | This method sends a query to the database and returns the result . |
23,238 | public function delete ( $ table , $ where , $ where_tokens = [ ] , $ affected_rows = false ) { $ values = [ ] ; if ( is_scalar ( $ where_tokens ) ) $ where_tokens = [ $ where_tokens ] ; foreach ( $ where_tokens as $ value ) { $ values [ ] = $ value ; } $ query = "DELETE FROM `$table` $where" ; $ this -> connect ( ) ; $ sth = $ this -> prepare ( $ query ) ; $ returner [ 'SUCCESS' ] = $ sth -> execute ( $ values ) ; if ( $ affected_rows ) $ returner [ 'AFFECTED_ROWS' ] = $ sth -> rowCount ( ) ; return $ returner ; } | Deletes a database row . |
23,239 | protected function _createUpdateValues ( $ array ) { $ values = [ ] ; $ tokens = [ ] ; foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { $ tokens [ ] = '`' . $ key . '`=' . $ value [ 'FUNC' ] ; } else { $ tokens [ ] = '`' . $ key . '`=?' ; $ values [ ] = $ value ; } } $ tokens = implode ( ', ' , $ tokens ) ; $ returner = compact ( 'tokens' , 'values' ) ; return $ returner ; } | Creates an update string of an associative array for use in a SQL query |
23,240 | protected function _createInsertAndReplaceValues ( $ array ) { $ keys = [ ] ; $ values = [ ] ; $ binds = [ ] ; foreach ( $ array as $ value ) { if ( is_array ( $ value ) ) { $ values [ ] = $ value [ 'FUNC' ] ; } else { $ values [ ] = '?' ; $ binds [ ] = $ value ; } } $ keys = implode ( ',' , array_keys ( $ array ) ) ; $ values = implode ( ',' , $ values ) ; $ returner = compact ( 'keys' , 'values' , 'binds' ) ; return $ returner ; } | Creates an insert and replace string of an associative array for use in a SQL query |
23,241 | protected function _safe ( $ table , $ array ) { if ( ! isset ( $ this -> cache [ $ table ] ) ) { $ this -> connect ( ) ; $ query = "SHOW COLUMNS FROM `$table`" ; if ( $ this -> config [ 'driver' ] == 'sqlite' ) { $ query = 'PRAGMA table_info(`' . $ table . '`);' ; } $ sth = $ this -> prepare ( $ query ) ; $ sth -> execute ( ) ; $ result = $ sth -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; foreach ( $ result as $ row ) { if ( $ this -> config [ 'driver' ] == 'sqlite' ) { $ columns [ ] = $ row [ 'name' ] ; } else { $ columns [ ] = $ row [ 'Field' ] ; } } $ this -> cache [ $ table ] = $ columns ; } foreach ( array_keys ( $ array ) as $ key ) { if ( ! in_array ( $ key , $ this -> cache [ $ table ] ) ) unset ( $ array [ $ key ] ) ; } return $ array ; } | Removes all keys from an array which are not available in the given table |
23,242 | public function actionIndex ( $ parent = null , $ page = 1 ) { $ searchModel = $ this -> module -> model ( 'ContentSearch' ) ; $ params = Yii :: $ app -> request -> queryParams ; if ( $ parent === '-' ) { $ params [ 'parent' ] = $ parent ; unset ( $ params [ $ searchModel -> formName ( ) ] [ 'parent_id' ] ) ; } else { $ params [ $ searchModel -> formName ( ) ] [ 'parent_id' ] = $ params [ 'parent' ] = intval ( $ parent ) ; } if ( ! Yii :: $ app -> user -> can ( 'roleContentModerator' ) && Yii :: $ app -> user -> can ( 'roleContentAuthor' ) ) { $ params [ $ searchModel -> formName ( ) ] [ 'owner_id' ] = Yii :: $ app -> user -> id ; } $ dataProvider = $ searchModel -> search ( $ params ) ; $ pager = $ dataProvider -> getPagination ( ) ; $ pager -> pageSize = $ this -> pageSizeAdmin ; $ pager -> totalCount = $ dataProvider -> getTotalCount ( ) ; $ maxPage = ceil ( $ pager -> totalCount / $ pager -> pageSize ) ; if ( $ page > $ maxPage ) { $ pager -> page = $ maxPage - 1 ; } else { $ pager -> page = $ page - 1 ; } return $ this -> render ( 'index' , compact ( 'dataProvider' , 'searchModel' , 'params' ) ) ; } | Lists all Content models . |
23,243 | public function actionView ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ modelsI18n = $ model -> prepareI18nModels ( ) ; if ( $ model -> pageSize > 0 ) { $ model -> orderBy = $ model :: $ defaultOrderBy ; $ model -> page = $ model -> calcPage ( ) ; } $ lh = $ this -> module -> langHelper ; $ editAllLanguages = empty ( $ this -> module -> params [ 'editAllLanguages' ] ) ? false : $ this -> module -> params [ 'editAllLanguages' ] ; $ languages = $ lh :: activeLanguages ( $ editAllLanguages ) ; if ( Yii :: $ app instanceof UniApplication && Yii :: $ app -> type == UniApplication :: APP_TYPE_BACKEND ) { $ containerModule = $ this -> module -> module ; if ( $ containerModule instanceof UniModule && array_key_exists ( static :: $ sysAppModel , $ containerModule -> models ) ) { $ appModel = $ containerModule :: model ( static :: $ sysAppModel ) ; $ appFront = $ appModel :: initFrontendApplication ( ) ; } } $ moduleUid = $ this -> module -> uniqueId ; $ frontendLinks = [ ] ; foreach ( $ languages as $ langCode => $ lang ) { $ frontendLinks [ $ langCode ] = '' ; if ( $ model -> hasInvisibleParent ( ) ) { if ( empty ( $ model -> route ) ) { $ frontendLinks [ $ langCode ] = Url :: toRoute ( [ "/{$moduleUid}/main/show" , 'id' => $ model -> id , 'slug' => $ model -> slug ] ) ; } else { $ frontendLinks [ $ langCode ] = ContentMenuBuilder :: routeToLink ( $ model -> route ) ; } } else { $ frontendLinks [ $ langCode ] = Url :: toRoute ( [ "/{$moduleUid}/main/view" , 'id' => $ model -> id , 'lang' => $ langCode ] , true ) ; } } if ( ! empty ( $ appModel ) ) $ appModel :: restoreApplication ( ) ; return $ this -> render ( 'view' , compact ( 'model' , 'modelsI18n' , 'frontendLinks' ) ) ; } | Displays a single Content model . |
23,244 | public function actionCreate ( $ parent = 0 ) { $ model = $ this -> module -> model ( 'Content' ) ; if ( ! isset ( $ model -> parent_id ) ) { $ model -> parent_id = $ parent ; } $ post = Yii :: $ app -> request -> post ( ) ; $ loaded = $ model -> load ( $ post ) ; if ( $ loaded && $ model -> save ( ) ) { if ( $ model -> aftersave != $ model :: AFTERSAVE_LIST ) { return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } else { $ model -> orderBy = $ model :: $ defaultOrderBy ; $ model -> page = $ model -> calcPage ( $ model :: find ( ) -> where ( [ 'parent_id' => $ model -> parent_id ] ) ) ; return $ this -> redirect ( [ 'index' , 'parent' => $ model -> parent_id , 'page' => $ model -> page , 'id' => $ model -> id , 'sort' => $ model -> orderByToSort ( ) , ] ) ; } } else { return $ this -> render ( 'create' , compact ( 'model' ) ) ; } } | Creates a new Content model . If creation is successful the browser will be redirected to the view page . |
23,245 | public function actionUpdate ( $ id ) { $ model = $ this -> findModel ( $ id ) ; if ( ! Yii :: $ app -> user -> can ( 'roleContentModerator' ) && Yii :: $ app -> user -> can ( 'roleContentAuthor' ) && ! Yii :: $ app -> user -> can ( 'updateOwnContent' , [ 'content' => $ model , 'canEditVisible' => $ this -> canAuthorEditOwnVisibleArticle , ] ) ) { if ( $ this -> canAuthorEditOwnVisibleArticle ) { throw new ForbiddenHttpException ( Yii :: t ( $ this -> tcModule , 'You can update only your own article' ) ) ; } else { throw new ForbiddenHttpException ( Yii :: t ( $ this -> tcModule , 'You can update only your own article still unvisible' ) ) ; } } $ post = Yii :: $ app -> request -> post ( ) ; $ loaded = $ model -> load ( $ post ) ; $ attributes = $ model -> attributes ; if ( ! $ this -> canAuthorEditOwnVisibleArticle ) unset ( $ attributes [ 'is_visible' ] ) ; $ attributeNames = array_keys ( $ attributes ) ; if ( $ loaded && $ model -> save ( true , $ attributeNames ) ) { if ( $ model -> aftersave != $ model :: AFTERSAVE_LIST ) { return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } else { $ model -> orderBy = $ model :: $ defaultOrderBy ; $ model -> page = $ model -> calcPage ( $ model :: find ( ) -> where ( [ 'parent_id' => $ model -> parent_id ] ) ) ; return $ this -> redirect ( [ 'index' , 'parent' => $ model -> parent_id , 'page' => $ model -> page , 'id' => $ model -> id , 'sort' => $ model -> orderByToSort ( ) , ] ) ; } } else { return $ this -> render ( 'update' , compact ( 'model' ) ) ; } } | Updates an existing Content model . If update is successful the browser will be redirected to the view page . |
23,246 | public function actionDelete ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ model -> orderBy = $ model :: $ defaultOrderBy ; $ model -> page = $ model -> calcPage ( $ model :: find ( ) -> where ( [ 'parent_id' => $ model -> parent_id ] ) ) ; $ returnTo = [ 'index' , 'parent_id' => $ model -> parent_id , 'page' => $ model -> page , 'id' => $ id , 'sort' => $ model -> orderByToSort ( ) , ] ; $ model -> delete ( ) ; return $ this -> redirect ( $ returnTo ) ; } | Deletes an existing Content model . If deletion is successful the browser will be redirected to the index page . |
23,247 | protected function findModel ( $ id ) { $ model = $ this -> module -> model ( 'Content' ) -> findOne ( $ id ) ; if ( $ model !== null ) { return $ model ; } else { throw new NotFoundHttpException ( 'The requested page does not exist.' ) ; } } | Finds the Content model based on its primary key value . If the model is not found a 404 HTTP exception will be thrown . |
23,248 | public function execute ( $ params = null ) { if ( $ params === null ) { $ params = [ ] ; } try { $ this -> stmt -> execute ( $ params ) ; return new QueryResult ( $ this -> stmt , $ this -> pdo ) ; } catch ( PDOException $ e ) { throw $ this -> exAdapter -> adapt ( $ e , $ this -> stmt , $ params ) ; } } | Execute the prepared statment with the given parameter values . |
23,249 | public function getValue ( ) { $ value = sprintf ( "%04d-%02d-%02d" , $ this -> year , $ this -> month , $ this -> day ) ; return $ value ; } | Get the value of this Date as an ISO string |
23,250 | public function getLocale ( ) { $ value = sprintf ( "%02d-%02d-%04d" , $ this -> day , $ this -> month , $ this -> year ) ; return $ value ; } | Get the value of this Date as a locale string |
23,251 | public function setDate ( $ year , $ month , $ day ) { self :: validateDate ( $ year , $ month , $ day ) ; $ this -> year = ( int ) $ year ; $ this -> month = ( int ) $ month ; $ this -> day = ( int ) $ day ; } | Set the date represented by this Date |
23,252 | static public function validate ( $ date ) { if ( is_string ( $ date ) && strlen ( trim ( $ date ) ) > 0 ) return false ; if ( ! preg_match ( '/^' . self :: PATTERN . '$/' , $ date , $ matches ) ) return false ; list ( $ original , $ year , $ month , $ day ) = $ matches ; if ( ! self :: validateDate ( $ year , $ month , $ day ) ) return false ; return true ; } | Validate if a string is a date |
23,253 | public function run ( string $ startup_event , $ startup_data = null ) { $ event = new Event ( $ startup_event , $ startup_data ) ; $ ctx = new EventContext ( $ event , $ this -> event_queue ) ; $ loop_exit = $ this -> loop_exit ?? function ( int $ counter ) { return $ counter > $ this -> max_loop_count ; } ; $ loop_counter = 0 ; while ( $ event && ! ( $ loop_exit ) ( $ loop_counter , $ this -> event_queue ) ) { foreach ( $ this -> workers as $ worker ) { if ( $ worker instanceof WorkerInterface ) { if ( self :: isProcessEventGenerator ( $ worker ) ) { foreach ( $ worker -> processEvent ( $ ctx ) as $ event ) { $ ctx -> setEvent ( $ event ) ; $ this -> dispatchImmediateEvent ( $ ctx ) ; } } else { $ worker -> processEvent ( $ ctx ) ; } } else if ( is_callable ( $ worker ) ) { if ( self :: isFunctionGenerator ( $ worker ) ) { foreach ( ( $ worker ) ( $ ctx ) as $ event ) { $ ctx -> setEvent ( $ event ) ; $ this -> dispatchImmediateEvent ( $ ctx ) ; } } else { ( $ worker ) ( $ ctx ) ; } } if ( $ event -> isConsumed ( ) && ! $ event -> isMulticast ( ) ) { break ; } } if ( $ event -> isConsumed ( ) ) { $ this -> event_queue -> dequeue ( $ event ) ; $ ctx -> setEvent ( $ event ) ; } $ loop_counter ++ ; } } | Process event loop |
23,254 | public static function register ( interfaces \ handlers \ Exception $ handler = null ) : Exception { set_exception_handler ( [ $ handler ? : $ handler = new static , 'handle' ] ) ; return $ handler ; } | Registers the given or this Exception Handler with PHP . |
23,255 | public function add ( $ delegate , string $ name = null , int $ priority = 0 ) : self { $ name = $ name ? : ( $ delegate instanceof interfaces \ Delegate ? get_class ( $ delegate ) : 'c\\' . mt_rand ( ) ) ; if ( isset ( $ this -> delegates [ $ name ] ) ) { throw new \ OverflowException ( "A Delegate with the given name [$name] is already set." ) ; } return $ this -> set ( $ name , $ delegate , $ priority ) ; } | Adds the given Delegate with the given optional priority to the stack . |
23,256 | public function remove ( $ delegate , bool $ all = true ) : self { $ name = is_string ( $ delegate ) ? $ delegate : null ; foreach ( $ this -> delegates as $ k => $ v ) { if ( ( $ name and $ k === $ name ) or ( ! $ name and $ v [ 'delegate' ] === $ delegate ) ) { unset ( $ this -> delegates [ $ k ] ) ; $ this -> applicable = null ; if ( $ name or false === $ all ) { break ; } } } return $ this ; } | Removes a specific Delegate or callable from the stack . |
23,257 | protected function sort ( array & $ delegates ) : self { uasort ( $ delegates , function ( $ a , $ b ) { return $ b [ 'priority' ] - $ a [ 'priority' ] ; } ) ; return $ this ; } | Sorts the given Delegates by their priority highest first . |
23,258 | protected function pushToList ( array & $ list , $ name ) : self { if ( is_array ( $ name ) ) { foreach ( $ name as $ single ) { $ this -> pushToList ( $ list , $ single ) ; } return $ this ; } $ list [ ] = $ name ; $ this -> applicable = null ; return $ this ; } | Pushes the given values to either the black - or - white - list . |
23,259 | protected function compileList ( array & $ list , array $ delegates ) { $ return = [ ] ; foreach ( $ list as $ name ) { $ return [ ] = preg_grep ( '/' . $ name . '/' , $ delegates ) ; } return call_user_func_array ( 'array_merge' , $ return ) ; } | Compiles the given black - or - white - list based on the given Delegate names ie . run regex matches against the Delegate names . |
23,260 | public function getTitle ( ) { $ title = $ this -> title ; if ( isset ( $ this -> title_suffix ) ) { $ title = $ title . $ this -> title_suffix ; } if ( isset ( $ this -> title_prefix ) ) { $ title = $ this -> title_prefix . $ title ; } return $ title ; } | Get title . |
23,261 | protected static function normalize ( array $ files ) { $ normalized = [ ] ; foreach ( $ files as $ key => $ value ) { if ( $ value instanceof UploadedFileInterface ) { $ normalized [ $ key ] = $ value ; continue ; } if ( ! is_array ( $ value ) ) { throw new InvalidArgumentException ( 'Invalid value in files specification.' ) ; } if ( isset ( $ value [ 'tmp_name' ] ) ) { $ normalized [ $ key ] = static :: build ( $ value ) ; continue ; } $ normalized [ $ key ] = static :: normalize ( $ value ) ; } return $ normalized ; } | Normalizes the array . |
23,262 | protected static function build ( array $ file ) { if ( is_array ( $ file [ 'tmp_name' ] ) ) { return static :: normalizeNested ( $ file ) ; } return new UploadedFile ( $ file [ 'name' ] , $ file [ 'tmp_name' ] , $ file [ 'type' ] , $ file [ 'size' ] , $ file [ 'error' ] ) ; } | Builds the uploaded file from specification . |
23,263 | protected static function normalizeNested ( array $ files ) { $ normalized = [ ] ; foreach ( array_keys ( $ files [ 'tmp_name' ] ) as $ key ) { $ spec = [ 'name' => $ files [ 'name' ] [ $ key ] , 'tmp_name' => $ files [ 'tmp_name' ] [ $ key ] , 'type' => $ files [ 'type' ] [ $ key ] , 'size' => $ files [ 'size' ] [ $ key ] , 'error' => $ files [ 'error' ] [ $ key ] , ] ; $ normalized [ $ key ] = static :: build ( $ spec ) ; } return $ normalized ; } | Normalizes a nested array . |
23,264 | public function setDirPath ( $ dirPath ) { $ dirPath = trim ( $ dirPath ) ; if ( $ this -> filesystem -> isDirectory ( $ dirPath ) ) { $ this -> dirPath = $ this -> filesystem -> realPath ( $ dirPath ) ; } } | set the log dir path |
23,265 | protected function log ( $ type , $ msg ) { $ msg = trim ( $ msg ) ; if ( '' == $ msg ) { return false ; } $ filesystem = $ this -> filesystem ; if ( ! $ filesystem -> isDirectory ( $ this -> dirPath ) ) { return false ; } $ type = intval ( $ type ) ; $ subPath = sprintf ( "%s%s%s%s" , date ( 'Y' ) , DIRECTORY_SEPARATOR , date ( 'm' ) , DIRECTORY_SEPARATOR ) ; $ file = $ this -> dirPath . DIRECTORY_SEPARATOR . $ subPath ; switch ( $ type ) { case self :: TYPE_DEBUG : $ file .= "debug" ; $ str = "[debug]" ; break ; case self :: TYPE_INFO : $ file .= "info" ; $ str = "[info]" ; break ; case self :: TYPE_NOTICE : $ file .= "notice" ; $ str = "[notice]" ; break ; case self :: TYPE_WARNING : $ file .= "warning" ; $ str = "[warning]" ; break ; case self :: TYPE_ERROR : $ file .= "error" ; $ str = "[error]" ; break ; case self :: TYPE_API : $ file .= "api" ; $ str = "[api]" ; break ; case self :: TYPE_DB : $ file .= "db" ; $ str = "[db]" ; break ; default : return false ; } $ file .= '_' . date ( 'Y_m_d' ) ; $ target = $ file . '_' . date ( 'His' ) . '.log' ; $ file .= '.log' ; if ( $ filesystem -> isFile ( $ file ) && ( $ filesystem -> size ( $ file ) > self :: MAX_FILE_SIZE ) ) { $ filesystem -> move ( $ file , $ target ) ; } $ dirPath = $ filesystem -> dirName ( $ file ) ; if ( ! $ filesystem -> isDirectory ( $ dirPath ) ) { $ filesystem -> makeDirectory ( $ dirPath , 0755 , true , true ) ; } $ str .= date ( 'Y-m-d H:i:s' ) . '|' . $ msg . "\n" ; return $ filesystem -> append ( $ file , $ str ) > 0 ; } | write log to file |
23,266 | public static function getNonce ( $ length = 32 ) { do { $ entropy = openssl_random_pseudo_bytes ( $ length , $ strong ) ; } while ( $ strong === false ) ; $ nonce = sha1 ( $ entropy ) ; return $ nonce ; } | This method will generate a pseudo random SHA1 that can be used as nonce or other kind of token . To specifiy the length of the token use the length parameter . |
23,267 | public function buildString ( array $ variables = [ ] , bool $ useExisting = true ) : string { if ( $ useExisting === true ) { $ variables = \ array_merge ( $ this -> variables , $ variables ) ; } $ tmp = [ ] ; foreach ( $ variables as $ name => $ val ) { if ( $ val !== null ) { $ tmp [ ] = $ name . '=' . \ urlencode ( ( string ) $ val ) ; } } $ ret = '' ; if ( \ count ( $ tmp ) > 0 ) { $ ret .= '?' . \ implode ( '&' , $ tmp ) ; } return $ ret ; } | Builds GET variables string . |
23,268 | public function deleteWhere ( array $ wheres ) { $ query = $ this -> getSqlObject ( ) -> delete ( ) -> where ( $ wheres ) ; return $ this -> execute ( $ query ) ; } | Delete all records in this table that meet the provided conditions |
23,269 | public function offsetGet ( $ offset ) { if ( $ this -> offsetExists ( $ offset ) && $ this -> internalFilterHooks ( $ offset , $ this -> baseConcreteData [ $ offset ] , 'output' ) ) { return $ this -> internalSanitizeHooks ( $ offset , $ this -> baseConcreteData [ $ offset ] , 'output' ) ; } } | this is necessary for ArrayAccess Interface and return and element by offset |
23,270 | public function offsetSet ( $ offset , $ value ) { if ( ! is_scalar ( $ offset ) && ! is_null ( $ offset ) ) { return ; } $ isNew = $ this -> offsetIsNew ( $ offset ) ; $ oldData = $ isNew ? null : $ this -> offsetGet ( $ offset ) ; $ index = $ isNew ? $ this -> arrayAccessMapIndex ++ : array_search ( $ offset , $ this -> baseArrayMap ) ; $ hook = $ isNew ? 'insert' : 'update' ; if ( is_null ( $ offset ) ) { $ offset = $ this -> arrayAccessConcreteIndex ; } $ offset = is_numeric ( $ offset ) || is_bool ( $ offset ) ? intval ( $ offset ) : ( string ) $ offset ; if ( ! $ this -> internalFilterHooks ( $ offset , $ value , 'input' ) ) { return ; } if ( is_numeric ( $ offset ) && $ offset >= $ this -> arrayAccessConcreteIndex ) { $ this -> arrayAccessConcreteIndex = $ offset + 1 ; } $ value = $ this -> internalSanitizeHooks ( $ offset , $ value , 'input' ) ; $ this -> baseConcreteData [ $ offset ] = $ value ; $ this -> baseArrayMap [ $ index ] = $ offset ; $ this -> internalChangingHooks ( $ offset , $ value , $ oldData , $ hook ) ; } | this is necessary for ArrayAccess Interface and save and element to array by offset |
23,271 | public function offsetUnset ( $ offset ) { if ( $ this -> offsetExists ( $ offset ) && $ this -> internalFilterHooks ( $ offset , null , 'remove' ) ) { $ oldData = $ this -> offsetGet ( $ offset ) ; unset ( $ this -> baseConcreteData [ $ offset ] ) ; if ( ( $ index = array_search ( $ offset , $ this -> baseArrayMap , true ) ) !== false ) { unset ( $ this -> baseArrayMap [ $ index ] ) ; } $ this -> baseArrayMap = array_values ( $ this -> baseArrayMap ) ; $ this -> arrayAccessMapIndex = count ( $ this -> baseArrayMap ) ; $ this -> internalChangingHooks ( $ offset , null , $ oldData , 'remove' ) ; } } | this is necessary for ArrayAccess Interface and delete element by offset and rearrange the map |
23,272 | public function ApplyBan ( $ NewBan = NULL , $ OldBan = NULL ) { if ( ! $ NewBan && ! $ OldBan ) return ; $ OldUsers = array ( ) ; $ OldUserIDs = array ( ) ; $ NewUsers = array ( ) ; $ NewUserIDs = array ( ) ; $ AllBans = $ this -> AllBans ( ) ; if ( $ NewBan ) { if ( isset ( $ NewBan [ 'BanID' ] ) ) $ AllBans [ $ NewBan [ 'BanID' ] ] = $ NewBan ; $ NewUsers = $ this -> SQL -> Select ( 'u.UserID, u.Banned' ) -> From ( 'User u' ) -> Where ( $ this -> BanWhere ( $ NewBan ) ) -> Get ( ) -> ResultArray ( ) ; $ NewUserIDs = ConsolidateArrayValuesByKey ( $ NewUsers , 'UserID' ) ; } elseif ( isset ( $ OldBan [ 'BanID' ] ) ) { unset ( $ AllBans [ $ OldBan [ 'BanID' ] ] ) ; } if ( $ OldBan ) { $ OldUsers = $ this -> SQL -> Select ( 'u.UserID, u.LastIPAddress, u.Name, u.Email, u.Banned' ) -> From ( 'User u' ) -> Where ( $ this -> BanWhere ( $ OldBan ) ) -> Get ( ) -> ResultArray ( ) ; $ OldUserIDs = ConsolidateArrayValuesByKey ( $ OldUsers , 'UserID' ) ; } foreach ( $ OldUsers as $ User ) { if ( in_array ( $ User [ 'UserID' ] , $ NewUserIDs ) ) continue ; $ this -> SaveUser ( $ User , FALSE ) ; } foreach ( $ NewUsers as $ User ) { if ( $ User [ 'Banned' ] ) continue ; $ this -> SaveUser ( $ User , TRUE , $ NewBan ) ; } } | Convert bans to new type . |
23,273 | public function BanWhere ( $ Ban ) { $ Result = array ( 'u.Admin' => 0 , 'u.Deleted' => 0 ) ; $ Ban [ 'BanValue' ] = str_replace ( '*' , '%' , $ Ban [ 'BanValue' ] ) ; switch ( strtolower ( $ Ban [ 'BanType' ] ) ) { case 'email' : $ Result [ 'u.Email like' ] = $ Ban [ 'BanValue' ] ; break ; case 'ipaddress' : $ Result [ 'u.LastIPAddress like' ] = $ Ban [ 'BanValue' ] ; break ; case 'name' : $ Result [ 'u.Name like' ] = $ Ban [ 'BanValue' ] ; break ; } return $ Result ; } | Ban users that meet conditions given . |
23,274 | public static function CheckUser ( $ User , $ Validation = NULL , $ UpdateBlocks = FALSE , & $ BansFound = NULL ) { $ Bans = self :: AllBans ( ) ; $ Fields = array ( 'Name' => 'Name' , 'Email' => 'Email' , 'IPAddress' => 'LastIPAddress' ) ; $ Banned = array ( ) ; if ( ! $ BansFound ) $ BansFound = array ( ) ; foreach ( $ Bans as $ Ban ) { $ Parts = explode ( '*' , str_replace ( '%' , '*' , $ Ban [ 'BanValue' ] ) ) ; $ Parts = array_map ( 'preg_quote' , $ Parts ) ; $ Regex = '`^' . implode ( '.*' , $ Parts ) . '$`i' ; if ( preg_match ( $ Regex , GetValue ( $ Fields [ $ Ban [ 'BanType' ] ] , $ User ) ) ) { $ Banned [ $ Ban [ 'BanType' ] ] = TRUE ; $ BansFound [ ] = $ Ban ; if ( $ UpdateBlocks ) { Gdn :: SQL ( ) -> Update ( 'Ban' ) -> Set ( 'CountBlockedRegistrations' , 'CountBlockedRegistrations + 1' , FALSE , FALSE ) -> Where ( 'BanID' , $ Ban [ 'BanID' ] ) -> Put ( ) ; } } } if ( $ Validation ) { foreach ( $ Banned as $ BanType => $ Value ) { $ Validation -> AddValidationResult ( Gdn_Form :: LabelCode ( $ BanType ) , 'ValidateBanned' ) ; } } return count ( $ Banned ) == 0 ; } | Add ban data to all Get requests . |
23,275 | public function Delete ( $ Where = '' , $ Limit = FALSE , $ ResetData = FALSE ) { if ( isset ( $ Where [ 'BanID' ] ) ) { $ OldBan = $ this -> GetID ( $ Where [ 'BanID' ] , DATASET_TYPE_ARRAY ) ; } parent :: Delete ( $ Where , $ Limit , $ ResetData ) ; if ( isset ( $ OldBan ) ) $ this -> ApplyBan ( NULL , $ OldBan ) ; } | Remove a ban . |
23,276 | public function Save ( $ FormPostValues , $ Settings = FALSE ) { $ CurrentBanID = GetValue ( 'BanID' , $ FormPostValues ) ; if ( $ CurrentBanID ) $ CurrentBan = $ this -> GetID ( $ CurrentBanID , DATASET_TYPE_ARRAY ) ; else $ CurrentBan = NULL ; $ this -> SetCounts ( $ FormPostValues ) ; $ BanID = parent :: Save ( $ FormPostValues , $ Settings ) ; $ FormPostValues [ 'BanID' ] = $ BanID ; $ this -> ApplyBan ( $ FormPostValues , $ CurrentBan ) ; } | Save data about ban from form . |
23,277 | public function addApps ( ArrayCollection $ apps ) { foreach ( $ apps as $ app ) { $ app -> addPage ( $ this ) ; $ this -> apps -> add ( $ app ) ; } } | Add apps to the page . |
23,278 | public function removeApps ( ArrayCollection $ apps ) { foreach ( $ apps as $ app ) { $ app -> removePage ( $ this ) ; $ this -> apps -> removeElement ( $ app ) ; } } | Remove apps from the page . |
23,279 | protected function sanitizeOffset ( $ offset ) : int { if ( ! is_numeric ( $ offset ) ) { throw new \ InvalidArgumentException ( sprintf ( '`$index` must be an `int`, %s(%s) received' , gettype ( $ offset ) , var_export ( $ offset , true ) ) ) ; } return intval ( $ offset ) ; } | Validates the offset throw an exception if invalid |
23,280 | public function equals ( $ other ) : bool { if ( is_array ( $ other ) || $ other instanceof self ) { return count ( $ other ) === count ( $ this ) && $ this -> zip ( $ other ) -> every ( function ( $ tuple ) { list ( $ a , $ b ) = $ tuple ; if ( $ a instanceof Equalable ) { return $ a -> equals ( $ b ) ; } return $ a === $ b ; } ) ; } throw new \ InvalidArgumentException ( '`$other` must be `Seq` or `array`' ) ; } | Deep strict comparison preferable over == |
23,281 | public function mapWithIndex ( callable $ function ) { $ values = array_values ( $ this -> data ) ; return new Seq ( array_map ( $ function , array_keys ( $ values ) , $ values ) ) ; } | Map over each Seq item with index |
23,282 | public function filterWithIndex ( callable $ function ) : Seq { $ result = new Seq ( ) ; foreach ( $ this -> data as $ key => $ value ) { if ( ! ! $ function ( $ key , $ value ) ) { $ result = $ result -> append ( $ value ) ; } } return $ result ; } | Filter an Seq using a predicate which receives key and value return a new Seq with elements that doesn t match the predicate |
23,283 | public function reduceLeft ( callable $ function ) { if ( $ this -> isEmpty ( ) ) { return null ; } list ( $ head , $ tail ) = $ this -> headAndTail ( ) ; return array_reduce ( $ tail -> all ( ) , $ function , $ head ) ; } | Reduces Seq items to the left |
23,284 | public function reduceRight ( callable $ function ) { if ( $ this -> isEmpty ( ) ) { return null ; } list ( $ head , $ tail ) = $ this -> reverse ( ) -> headAndTail ( ) ; return array_reduce ( $ tail -> all ( ) , $ function , $ head ) ; } | Reduces Seq items to the right |
23,285 | public function zipLeft ( $ other ) { if ( count ( $ other ) !== count ( $ this ) ) { throw new \ InvalidArgumentException ( 'Both left and right must have same size.' ) ; } if ( is_array ( $ other ) ) { return new Seq ( array_map ( function ( $ a , $ b ) { return new Tuple ( [ $ a , $ b ] ) ; } , $ other , $ this -> data ) ) ; } if ( $ other instanceof Seq ) { return $ other -> zip ( $ this -> data ) ; } throw new \ InvalidArgumentException ( '`$other` must be `Seq` or `array`' ) ; } | Zip with another Seq values on the left |
23,286 | protected function getFilePath ( $ path , $ file ) { if ( ! is_string ( $ file ) ) { $ file = ".env" ; } return rtrim ( $ path , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $ file ; } | Returns the full path to the file . |
23,287 | public function resolve ( ) { $ instance = null ; $ args = [ ] ; if ( isset ( $ this -> concrete ) ) { $ reflected_class = new \ ReflectionClass ( $ this -> concrete ) ; } else { throw new ResolveException ; } $ reflected_method = $ reflected_class -> getConstructor ( ) ; if ( $ reflected_method ) { $ args = $ this -> resolveArgs ( $ reflected_method , $ this -> args ) ; } $ instance = $ reflected_class -> newInstanceArgs ( $ args ) ; foreach ( $ this -> afters as $ after ) { $ after ( $ instance ) ; } return $ instance ; } | Resolves the definition |
23,288 | protected static function prepareNumericCast ( $ value ) { if ( ! in_array ( gettype ( $ value ) , static :: $ numericCastable , true ) ) { return '' ; } if ( is_string ( $ value ) ) { return trim ( $ value ) ; } return $ value ; } | Return empty string in case the type is not castable to a numeric data type and trim the value . |
23,289 | public static function create ( ConstraintViolationListInterface $ violationList , $ code = 0 , \ Exception $ prev = null ) { $ violationMessages = [ ] ; foreach ( $ violationList as $ violation ) { $ violationMessages [ ] = sprintf ( '[%s]: %s;' , $ violation -> getPropertyPath ( ) , $ violation -> getMessage ( ) ) ; } $ message = 'Not valid. ' . implode ( ' ' , $ violationMessages ) ; return new static ( $ violationList , $ message , $ code , $ prev ) ; } | Create a new instance with violation list |
23,290 | public function listJobs ( $ crontab ) { $ process = new Process ( $ this -> crontabCommand ( $ crontab ) . ' -l' ) ; $ process -> run ( ) ; $ this -> error = $ process -> getErrorOutput ( ) ; return $ process -> getOutput ( ) ; } | list the current jobs |
23,291 | private function registerClassloader ( ) { require_once ( 'SplClassLoader.php' ) ; $ register = [ 'Core' => $ this -> basedir , 'Apps' => $ this -> basedir , 'AppsSec' => $ this -> basedir , 'Themes' => $ this -> basedir ] ; foreach ( $ register as $ key => $ path ) { $ loader = new \ SplClassLoader ( $ key , $ path ) ; $ loader -> register ( ) ; } } | Registers SPL classloader |
23,292 | private function initHttp ( ) { $ this -> di -> mapService ( 'core.http' , '\Core\Http\Http' , [ 'core.http.cookie' , 'core.http.header' ] ) ; $ this -> di -> mapService ( 'core.http.cookie' , '\Core\Http\Cookie\CookieHandler' ) ; $ this -> di -> mapService ( 'core.http.header' , '\Core\Http\Header\HeaderHandler' ) ; $ this -> http = $ this -> di -> get ( 'core.http' ) ; } | Inits the http library system for cookie and header handling |
23,293 | private function initAssetManager ( ) { $ this -> di -> mapService ( 'core.asset' , '\Core\Asset\AssetManager' ) ; $ this -> assetmanager = $ this -> di -> get ( 'core.asset' ) ; $ ah = $ this -> assetmanager -> createAssetHandler ( 'js' , 'js' ) ; $ ah -> setBasedir ( $ this -> basedir ) ; $ ah -> setBaseurl ( BASEURL ) ; $ this -> di -> mapValue ( 'core.asset.js' , $ ah ) ; if ( $ this -> config -> get ( 'Core' , 'asset.general.minify_js' ) ) { $ ah -> addProcessor ( new \ Core \ Asset \ Processor \ JSMinProcessor ( ) ) ; } $ ah = $ this -> assetmanager -> createAssetHandler ( 'css' , 'css' ) ; $ ah -> setBasedir ( $ this -> basedir ) ; $ ah -> setBaseurl ( BASEURL ) ; $ this -> di -> mapValue ( 'core.asset.css' , $ ah ) ; if ( $ this -> config -> get ( 'Core' , 'asset.general.minify_css' ) ) { $ ah -> addProcessor ( new \ Core \ Asset \ Processor \ CssMinProcessor ( ) ) ; $ ah -> addProcessor ( new \ Core \ Asset \ Processor \ ReplaceProcessor ( '../fonts/' , '../Themes/Core/fonts/' ) ) ; $ ah -> addProcessor ( new \ Core \ Asset \ Processor \ ReplaceProcessor ( '../img/' , '../Themes/Core/img/' ) ) ; } } | Initiates the AssetManager |
23,294 | private function initMessageHandler ( ) { $ this -> di -> mapFactory ( 'core.message.message_handler' , '\Core\Message\MessageHandler' ) ; $ this -> di -> mapFactory ( 'core.message.message_storage' , '\Core\Message\MessageStorage' ) ; $ this -> di -> mapFactory ( 'core.message.message' , '\Core\Notification\Notifcation' ) ; $ handler = $ this -> di -> get ( 'core.message.message_handler' ) ; if ( empty ( $ _SESSION [ 'Core' ] [ 'messages' ] ) ) { $ _SESSION [ 'Core' ] [ 'messages' ] = [ ] ; } $ storage = $ this -> di -> get ( 'core.message.message_storage' ) ; $ storage -> setStorage ( $ _SESSION [ 'Core' ] [ 'messages' ] ) ; $ handler -> setStorage ( $ storage ) ; $ this -> message = new MessageFacade ( $ handler ) ; $ this -> di -> mapValue ( 'core.message.default' , $ handler ) ; } | Inits message handler |
23,295 | private function callAppEvent ( AbstractApp $ app , string $ event ) { if ( method_exists ( $ app , $ event ) ) { return call_user_func ( [ $ app , $ event ] ) ; } } | Calls an existing event method of an app |
23,296 | private function processAssets ( ) { $ js = $ this -> assetmanager -> getAssetHandler ( 'js' ) ; $ afh = new \ Core \ Asset \ AssetFileHandler ( ) ; $ afh -> setFilename ( $ this -> config -> get ( 'Core' , 'dir.cache' ) . '/script.js' ) ; $ afh -> setTTL ( $ this -> config -> get ( 'Core' , 'cache.ttl.js' ) ) ; $ js -> setFileHandler ( $ afh ) ; $ css = $ this -> assetmanager -> getAssetHandler ( 'css' ) ; $ theme = $ this -> config -> get ( 'Core' , 'style.theme.name' ) ; $ css -> addProcessor ( new \ Core \ Asset \ Processor \ ReplaceProcessor ( '../fonts/' , '../Themes/' . $ theme . '/fonts/' ) ) ; $ css -> addProcessor ( new \ Core \ Asset \ Processor \ ReplaceProcessor ( '../img/' , '../Themes/' . $ theme . '/img/' ) ) ; $ afh = new \ Core \ Asset \ AssetFileHandler ( ) ; $ afh -> setFilename ( $ this -> config -> get ( 'Core' , 'dir.cache' ) . '/style.css' ) ; $ afh -> setTTL ( $ this -> config -> get ( 'Core' , 'cache.ttl.css' ) ) ; $ css -> setFileHandler ( $ afh ) ; foreach ( $ this -> apps as $ app ) { foreach ( $ app -> javascript as $ aio ) { $ js -> addObject ( $ aio ) ; } foreach ( $ app -> css as $ aio ) { $ css -> addObject ( $ aio ) ; } } $ this -> assetmanager -> process ( ) ; } | Processes asset handlers and their contents |
23,297 | private function initApps ( ) { foreach ( $ this -> apps as $ app ) { if ( method_exists ( $ app , 'Init' ) ) { $ app -> Init ( ) ; } switch ( $ app -> getName ( ) ) { case 'Core' : $ config = $ this -> config -> getStorage ( 'Core' ) ; $ type = $ this -> user -> isGuest ( ) ? 'guest' : 'user' ; $ route = $ config -> get ( 'home.' . $ type . '.route' ) ; $ params = parse_ini_string ( $ config -> get ( 'home.' . $ type . '.params' ) ) ; $ config -> set ( 'url.home' , $ app -> url ( $ route , $ params ) ) ; break ; } } } | Inits all loaded apps calls core specific actions and maps |
23,298 | protected static function filterEntity ( $ filter , $ entity ) { if ( $ filter !== null && $ filter ( $ entity ) === false ) { return false ; } else { return $ entity ; } } | Use given entityFilter to check if entity is allowed |
23,299 | public function getProtocolVersion ( ) { $ version = null ; if ( isset ( $ this -> server [ 'SERVER_PROTOCOL' ] ) ) { $ protocol = $ this -> server [ 'SERVER_PROTOCOL' ] ; list ( , $ version ) = explode ( "/" , $ protocol ) ; } return $ version ; } | Get protocol version |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.