Skip to content

Commit 4f0f984

Browse files
author
reef-actor
committed
Move replace_title into dedicated plugin
Title replacement is not related to proxification.
1 parent 46e9ea8 commit 4f0f984

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/Plugin/ProxifyPlugin.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Proxy\Plugin\AbstractPlugin;
66
use Proxy\Event\ProxyEvent;
7-
use Proxy\Config;
87

98
class ProxifyPlugin extends AbstractPlugin {
109

@@ -101,12 +100,6 @@ private function meta_refresh($matches){
101100
// <title>, <base>, <link>, <style>, <meta>, <script>, <noscript>
102101
private function proxify_head($str){
103102

104-
// let's replace page titles with something custom
105-
if(Config::get('replace_title')){
106-
$str = preg_replace('/<title[^>]*>(.*?)<\/title>/is', '<title>'.Config::get('replace_title').'</title>', $str);
107-
}
108-
109-
110103
// base - update base_url contained in href - remove <base> tag entirely
111104
//$str = preg_replace_callback('/<base[^>]*href=
112105

src/Plugin/ReplaceTitlePlugin.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
namespace Proxy\Plugin;
3+
4+
use Proxy\Plugin\AbstractPlugin;
5+
use Proxy\Event\ProxyEvent;
6+
use Proxy\Config;
7+
8+
class ReplaceTitlePlugin extends AbstractPlugin
9+
{
10+
public function onCompleted(ProxyEvent $event)
11+
{
12+
$response = $event['response'];
13+
$content_type = $response->headers->get('content-type');
14+
if (strpos($content_type, 'text/html') === false) {
15+
return;
16+
}
17+
18+
if (Config::get('replace_title')) {
19+
$content = $response->getContent();
20+
$content = preg_replace('/<title[^>]*>(.*?)<\/title>/is', '<title>'.Config::get('replace_title').'</title>', $content);
21+
$response->setContent($content);
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)