-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.php
More file actions
27 lines (25 loc) · 813 Bytes
/
base.php
File metadata and controls
27 lines (25 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
/**
* @package Gist
* @author Alan Hardman <alan@phproject.org>
* @version 0.1.0
*/
namespace Plugin\Gist;
class Base extends \Plugin
{
/**
* Initialize the plugin
*/
public function _load()
{
// Replace Gist links with embeds
// TODO: don't add embeds when rendering in an email
$this->_hook('text.parse.after', function ($str) {
// TODO: use file fragment to add ?file= parameter
$urlPatt = '(https?://gist.github.com/[0-9A-Za-z_-]+/[0-9a-f]+)(#file-[0-9A-Za-z_-]+)?';
$pattern = "@(<a href=\")?{$urlPatt}(\" ?(rel=\"nofollow\")? ?(target=\"_blank\")?>)?({$urlPatt})?(</a>)?@";
$replace = '<script src="$2.js"></script>';
return preg_replace($pattern, $replace, $str);
});
}
}