Frodox/phileCustomPostPreview — pull request #1 by Stijn-Flipper (2014-06-25 23:32:50+00:00)
Title: fixed incorrect scoping

This plugin ran fine on development server (localhost), which uses PHP 5.5.X . However, when I pushed the content to the production server, which uses PHP 5.3.X, the twig filter function `custom_post_preview` crashed with the error message:

```
PHP Fatal error: Using $this when not in object context in <...>/plugins/phileCustomPostPreview/plugin.php on line 28
```

The crash is caused by incorrect scoping. For example:

```php
$foo = 'bar'
$custom_post_preview = new Twig_SimpleFilter('custom_post_preview', function ($string)
{
...
});
```

Here, the second argument is actually a lambda function `function ($string)`, which is a 'closed' scope, meaning you cannot access variables from the outer scopes (such as `$foo` in this example), it's also not possible to access the `$this` object. So I've solved this by providing a separate function `apply`, which applies the twig filter, but can access the settings as defined in `config.php`, and just pass the class member function as an argument to the `Twig_SimpleFilter` constructor. From now on, this should work smoothly on PHP versions >= 5.3.X :+1: