Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass only remote filename #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FeedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class FeedCache {
private $is_local;
private $data = false;

public function __construct($local, $remote, $valid_for=3600) {
$this->local = ROOT.'cache/'.$local;
public function __construct($remote, $valid_for=3600) {
$this->local = ROOT . 'cache/' . hash('md4', $remote);
$this->remote = $remote;
$this->valid_for = $valid_for;
$this->is_local = $this->check_local();
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ Include FeedCache.php in your script
Then simply pass in the local file-name (that you want to save it as) and the remote feed:

```php
$feed_cache = new FeedCache('local_file.xml', 'http://example.com/feed.xml');
$feed_cache = new FeedCache('http://example.com/feed.xml');
$data = simplexml_load_string($feed_cache->get_data());
```

You will also need to make sure you have a writable folder called "cache" in the root of your site.

The local filename is hashed string, which represents remote URI, you can specify used algorithm from __construct() method inside FeedCache class.

```php
/* http://php.net/manual/en/function.hash.php */
$this->local = ROOT . 'cache/' . hash('md4', $remote);
```

Changelog
---------

* v1.1 (2013-04-26)
** UPDATE: Pass onle name of remote feed, the script will store hash of it's name as filename of local cache file.
* v1 (2012-04-26)
** ADD: Initial commit

Expand Down