In this exercise, you will create a simple RSS reader which displays the
last feed item from the Plesk feed on the administrator’s dashboard.
While writing the extension, you will learn how to do the following:
- Write installation and removal scripts.
- Use the key-value storage.
- Add scheduled tasks.
- Create promotional blocks on the administrator’s dashboard.
We assume that the extension ID is plesk-news, and that you start with
the code inside the ex2 directory. This code is partly written by us
to help you focus only on certain areas. Additionally, we have populated
the directory with media content necessary for the exercise. To see the
completed exercise, examine the ex2complete directory.
Step 1. Implement a helper to download the RSS feed
First of all, let us implement a class to download the RSS feed and
store the most recent item in the local storage. For this purpose, open
/plib/library/News.php
. Pay attention to the class name: it follows
the class naming convention, and will thus be loaded automatically. For
auto-loading we rely on the Zend approach. Read more about it
here.
Now, let us implement the load method:
public static function load()
{
$url = 'http://kb.plesk.com/rss/gen.xml?p=PLESK';
$content = @file_get_contents($url);
if (false === $content) {
return;
}
$xml = simplexml_load_string($content);
if (false === $xml || !$xml->channel) {
return;
}
<span class="…