Skip to content

Commit

Permalink
cleanup!
Browse files Browse the repository at this point in the history
updates after some great feedback from kevincupp
  • Loading branch information
jaseclamp committed Feb 16, 2015
1 parent 2abffb3 commit 30c1206
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 257 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -38,7 +38,7 @@ If you click into modules > Purge you can now set URL patterns to purge when ent

## Changelog

* **1.0.5 - February 13, 2015**
* **1.1 - February 13, 2015**
* Changed addon to only purge via url patterns when entries are saved. All cache can still be purged using the accessory.
* **1.0.4 - March 17, 2014**
* Fixing issue #11 where there were bugs with purging multiple Varnish servers and purging by IP address.
Expand Down
27 changes: 17 additions & 10 deletions third_party/purge/ext.purge.php
Expand Up @@ -90,8 +90,6 @@ public function activate_extension()
public function send_purge_request($id,$meta,$data)
{

//var_dump($id,$meta,$data); die;

$this->EE->load->helper('varnish');

$urls = $this->site_url;
Expand All @@ -101,26 +99,35 @@ public function send_purge_request($id,$meta,$data)
$urls = array($urls);
}

foreach ($urls as $url)
//get patterns for this channel
$this->EE->db->select('*');
$this->EE->db->where('channel_id',(int) $meta['channel_id']);
$channelPatterns = $this->EE->db->get_where('purge_rules')->result_array();

//if no patterns this may mean patterns aren't configured therefore revert to old behaviour of clearing everything
if(count($channelPatterns)==0)
{
//now loop through urls for this channel
//are there any patterns at all?
$this->EE->db->select('*');
$this->EE->db->where('channel_id',(int) $meta['channel_id']);
$channelPatterns = $this->EE->db->get_where('purge_rules')->result_array();

if(count($channelPatterns)==0) $channelPatterns = array( array('pattern','/.*$') );
else return false; //patterns are configured but not for this channel.
}

//now loop through varnish urls
foreach ($urls as $url)
{
//and loop through patterns for each
foreach($channelPatterns as $pattern)
{
$_pattern = str_replace('{url_title}',$meta['url_title'],$pattern['pattern']);
$_pattern = str_replace('{url_title}',$meta['url_title'],$pattern['pattern']); //only str replacing url title at this point
$_url = preg_replace('/\/$/','',$url).'/'.preg_replace('/^\//','',$_pattern); //handle trailing and beginning slashes
//echo $_url . "<br>";
send_purge_request($_url, $this->port);
unset($_pattern);
}
}
}

// ----------------------------------------------------------------------

/**
* Disable Extension
*
Expand Down
13 changes: 3 additions & 10 deletions third_party/purge/helpers/varnish_helper.php
Expand Up @@ -20,29 +20,22 @@ function send_purge_request($site_url = NULL, $site_port = NULL)
{
$purge_url = $site_url;
$port = $site_port;
/*$parsed_url = parse_url($site_url);
$url_path = isset($parsed_url['path']) ? $parsed_url['path'] : '/';
$url_scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : $protocol;
$purge_url = $url_scheme . $parsed_url['host'] . $url_path;
$port = ( ! isset($parsed_url['port']) || empty($parsed_url['port'])) ? 80 : $parsed_url['port'];*/
}

if (empty($port))
{
$port = 80;
}

echo $purge_url;


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $purge_url);
curl_setopt($ch, CURLOPT_PORT , (int)$port);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Host: '.$_SERVER['SERVER_NAME'] ) );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'PURGE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,2);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
if(curl_exec($ch) === false)
die( curl_error ( $ch ) );
curl_close ($ch);
Expand Down
52 changes: 11 additions & 41 deletions third_party/purge/mcp.purge.php
Expand Up @@ -6,10 +6,8 @@ class Purge_mcp {

public $return_data;
public $return_array = array();

private $_base_url;
private $_data = array();
private $_module = 'purge';



/**
Expand All @@ -22,7 +20,7 @@ public function __construct()
$this->_base_url = BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=purge';

$this->EE->cp->set_right_nav(array(
'module_home' => $this->_cp_url()
'module_home' => $this->_base_url
));

$this->EE->view->cp_page_title = "Purge: Channel URL Patterns for Varnish";
Expand All @@ -34,19 +32,20 @@ public function __construct()
public function index()
{

$this->EE->load->library('table');
//$this->EE->load->library('table');

$this->_data['action_url'] = $this->_base_url . '&method=save';
//$this->_data['images'] = $this->get_alttags();
$_data = array();

$_data['action_url'] = $this->_base_url . '&method=save';

$this->EE->load->model('channel_model');
$channels_query = $this->EE->channel_model->get_channels()->result();
foreach ($channels_query as $channel)
$this->_data['channels'][] = array('channel_title' => $channel->channel_title, 'channel_name' => $channel->channel_name, 'channel_id' => $channel->channel_id );
$_data['channels'][] = array('channel_title' => $channel->channel_title, 'channel_name' => $channel->channel_name, 'channel_id' => $channel->channel_id );

$this->_data['rules'] = $this->get();
$_data['rules'] = $this->get();

return $this->EE->load->view('rules', $this->_data, TRUE);
return $this->EE->load->view('rules', $_data, TRUE);

}

Expand All @@ -69,40 +68,11 @@ public function save()
{
$this->EE->db->insert( 'purge_rules', array('channel_id' => $channel, 'pattern' => $patterns[$key]) );
}

// Redirect back to Detour Pro landing page

$this->EE->functions->redirect($this->_base_url);
}

function strposa($haystack, $needle, $offset=0) {
if(!is_array($needle)) $needle = array($needle);
foreach($needle as $query) {
if(strpos($haystack, $query, $offset) !== false) return true; // stop on first true result
}
return false;
}



private function _cp_url ($method = 'index', $variables = array()) {
$url = BASE . AMP . 'C=addons_modules' . AMP . 'M=show_module_cp' . AMP . 'module=' . $this->_module . AMP . 'method=' . $method;

foreach ($variables as $variable => $value) {
$url .= AMP . $variable . '=' . $value;
}

return $url;
}

private function _form_url ($method = 'index', $variables = array()) {
$url = 'C=addons_modules' . AMP . 'M=show_module_cp' . AMP . 'module=' . $this->_module . AMP . 'method=' . $method;

foreach ($variables as $variable => $value) {
$url .= AMP . $variable . '=' . $value;
}

return $url;
}




Expand Down
188 changes: 0 additions & 188 deletions third_party/purge/upd.detour_pro.php

This file was deleted.

0 comments on commit 30c1206

Please sign in to comment.