2012-11-30 13:52:09 +01:00
|
|
|
<?php
|
2013-01-04 15:49:52 +01:00
|
|
|
|
2012-11-30 13:52:09 +01:00
|
|
|
App::uses('AppController', 'Controller');
|
2013-01-04 15:49:52 +01:00
|
|
|
|
2012-11-30 13:52:09 +01:00
|
|
|
/**
|
2013-01-04 15:49:52 +01:00
|
|
|
* Regexps Controller
|
2012-11-30 13:52:09 +01:00
|
|
|
*
|
2013-01-04 15:49:52 +01:00
|
|
|
* @property Regexp $Regexp
|
2012-11-30 13:52:09 +01:00
|
|
|
*/
|
2012-12-20 19:47:38 +01:00
|
|
|
class RegexpController extends AppController {
|
2012-11-30 13:52:09 +01:00
|
|
|
|
2013-01-04 15:49:52 +01:00
|
|
|
public $components = array('Security', 'RequestHandler', 'AdminCrud');
|
2012-11-30 13:52:09 +01:00
|
|
|
|
2012-12-19 02:48:53 +01:00
|
|
|
public $paginate = array(
|
|
|
|
'limit' => 60,
|
|
|
|
'order' => array(
|
2012-12-20 19:47:38 +01:00
|
|
|
'Regexp.id' => 'ASC'
|
2012-12-19 02:48:53 +01:00
|
|
|
)
|
|
|
|
);
|
2012-12-19 11:30:10 +01:00
|
|
|
|
2012-12-19 02:48:53 +01:00
|
|
|
public function beforeFilter() {
|
|
|
|
parent::beforeFilter();
|
|
|
|
}
|
2012-11-30 13:52:09 +01:00
|
|
|
|
|
|
|
/**
|
2013-01-04 15:49:52 +01:00
|
|
|
* admin_add method
|
2012-11-30 13:52:09 +01:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2013-01-04 15:49:52 +01:00
|
|
|
public function admin_add() {
|
2013-04-26 15:46:39 +02:00
|
|
|
if($this->Auth->User('org') != 'ADMIN') $this->redirect(array('controller' => 'regexp', 'action' => 'index', 'admin' => false));
|
2013-01-04 15:49:52 +01:00
|
|
|
$this->AdminCrud->adminAdd();
|
2012-11-30 13:52:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-04 15:49:52 +01:00
|
|
|
* admin_index method
|
2012-11-30 13:52:09 +01:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2013-01-04 15:49:52 +01:00
|
|
|
public function admin_index() {
|
2013-01-30 11:49:55 +01:00
|
|
|
if($this->Auth->User('org') != 'ADMIN') $this->redirect(array('controller' => 'regexp', 'action' => 'index', 'admin' => false));
|
2013-01-04 15:49:52 +01:00
|
|
|
$this->AdminCrud->adminIndex();
|
2013-01-28 11:44:09 +01:00
|
|
|
//}
|
2012-11-30 13:52:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-04 15:49:52 +01:00
|
|
|
* admin_edit method
|
2012-11-30 13:52:09 +01:00
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
* @throws NotFoundException
|
|
|
|
*/
|
|
|
|
public function admin_edit($id = null) {
|
2013-01-30 11:49:55 +01:00
|
|
|
if($this->Auth->User('org') != 'ADMIN') $this->redirect(array('controller' => 'regexp', 'action' => 'index', 'admin' => false));
|
2013-01-04 15:49:52 +01:00
|
|
|
$this->AdminCrud->adminEdit($id);
|
2012-11-30 13:52:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-04 15:49:52 +01:00
|
|
|
* admin_delete method
|
2012-11-30 13:52:09 +01:00
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
* @throws MethodNotAllowedException
|
|
|
|
* @throws NotFoundException
|
|
|
|
*/
|
|
|
|
public function admin_delete($id = null) {
|
2013-01-30 11:49:55 +01:00
|
|
|
if($this->Auth->User('org') != 'ADMIN') $this->redirect(array('controller' => 'regexp', 'action' => 'index', 'admin' => false));
|
2013-01-04 15:49:52 +01:00
|
|
|
$this->AdminCrud->adminDelete($id);
|
2012-11-30 13:52:09 +01:00
|
|
|
}
|
2012-12-04 08:51:27 +01:00
|
|
|
|
2013-01-28 11:44:09 +01:00
|
|
|
/**
|
|
|
|
* index method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function index() {
|
|
|
|
$this->recursive = 0;
|
2013-04-24 15:33:22 +02:00
|
|
|
$this->set('list', $this->paginate());
|
2013-01-28 11:44:09 +01:00
|
|
|
}
|
|
|
|
|
2012-12-04 08:51:27 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function admin_clean() {
|
2013-01-30 11:49:55 +01:00
|
|
|
if($this->Auth->User('org') != 'ADMIN') $this->redirect(array('controller' => 'regexp', 'action' => 'index', 'admin' => false));
|
2013-01-04 15:49:52 +01:00
|
|
|
$this->regexpAll('Attribute', 'value');
|
|
|
|
$this->regexpAll('Event', 'info');
|
|
|
|
|
|
|
|
$this->redirect(array('action' => 'index'));
|
|
|
|
}
|
2012-12-04 08:51:27 +01:00
|
|
|
|
2013-01-04 15:49:52 +01:00
|
|
|
public function regexpAll($Model, $Field) {
|
2013-01-30 11:49:55 +01:00
|
|
|
if($this->Auth->User('org') != 'ADMIN') $this->redirect(array('controller' => 'regexp', 'action' => 'index', 'admin' => false));
|
2013-01-04 15:49:52 +01:00
|
|
|
$deletable = array();
|
|
|
|
$this->loadModel($Model);
|
|
|
|
$all = $this->{$Model}->find('all', array('recursive' => -1));
|
|
|
|
foreach ($all as $item) {
|
|
|
|
$result = $this->replaceSpecific($item[$Model][$Field]);
|
2012-12-04 08:51:27 +01:00
|
|
|
if (!$result) {
|
2013-01-04 15:49:52 +01:00
|
|
|
$deletable[] = $item[$Model]['id'];
|
2012-12-04 08:51:27 +01:00
|
|
|
} else {
|
2013-01-04 15:49:52 +01:00
|
|
|
$this->{$Model}->save($item);
|
2012-12-04 08:51:27 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-04 15:49:52 +01:00
|
|
|
if (count($deletable)) {
|
|
|
|
foreach ($deletable as $item) {
|
|
|
|
$this->{$Model}->delete($item);
|
2012-12-04 08:51:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function replaceSpecific($origString) {
|
2013-01-30 11:49:55 +01:00
|
|
|
if($this->Auth->User('org') != 'ADMIN') $this->redirect(array('controller' => 'regexp', 'action' => 'index', 'admin' => false));
|
2012-12-04 08:51:27 +01:00
|
|
|
$returnValue = true;
|
2013-01-04 15:49:52 +01:00
|
|
|
$allRegexp = $this->Regexp->find('all'); // TODO REGEXP INIT LOAD ARRAY
|
2012-12-20 19:47:38 +01:00
|
|
|
foreach ($allRegexp as $regexp) {
|
|
|
|
if (strlen($regexp['Regexp']['replacement']) && strlen($regexp['Regexp']['regexp'])) {
|
|
|
|
$origString = preg_replace($regexp['Regexp']['regexp'], $regexp['Regexp']['replacement'], $origString);
|
2012-12-04 08:51:27 +01:00
|
|
|
}
|
2012-12-20 19:47:38 +01:00
|
|
|
if (!strlen($regexp['Regexp']['replacement']) && preg_match($regexp['Regexp']['regexp'], $origString)) {
|
2012-12-04 08:51:27 +01:00
|
|
|
App::uses('SessionComponent', 'Controller/Component');
|
|
|
|
SessionComponent::setFlash('Blacklisted value!');
|
2012-12-19 02:48:53 +01:00
|
|
|
$returnValue = false;
|
2012-12-04 08:51:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $returnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|