112 Chapter 3 Application Design: A Real-Life Example
Interfacing the Network 113 To be useful in the application, phpChat offers a set of events to which each plug- in can attach itself. During plug-in initialization, each plug-in tells phpChat to send a set of desired events. Events might include the chat being idle, the user submitting a new message, the user clicking on a nickname in the nick list, an incoming message from the network, and so on. At runtime,the plug-ins can intercept these events and perform certain tasks.The clock plug-in, for example, registers itself to the idle event and checks the current system time frequently.After a predefined number of minutes,it announces the time to the user. For most events, phpChat also sends parameters (such as the message texts for incoming messages), which the plug-ins are allowed to change. For example, the list of plug-ins in Listing 3.3 includes plug-ins named htmlspecialchars and link_transform.These plug-ins change the output of messages; htmlspecialchars applies a call to htmlspecialchars() to all printed text (for security reasons, so that no one can insert malicious HTML code into the chat), and the link transformer detects all URLs and email addresses and prefixes them with or mailto:, respectively, so that users can click links right in the chat window (see Figure 3.10). Figure 3.10 The plug-ins at work.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services