| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
class midcom_helper_replicator_subscription_dba extends __midcom_helper_replicator_subscription_dba |
|---|
| 16 |
{ |
|---|
| 17 |
var $filters = false; |
|---|
| 18 |
var $autoserialize_filters = false; |
|---|
| 19 |
|
|---|
| 20 |
function __construct($id = null) |
|---|
| 21 |
{ |
|---|
| 22 |
return parent::__construct($id); |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
function _unserialize_filters() |
|---|
| 26 |
{ |
|---|
| 27 |
debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 28 |
debug_add("Called for #{$this->id} ({$this->title})"); |
|---|
| 29 |
debug_pop(); |
|---|
| 30 |
if (empty($this->filtersSerialized)) |
|---|
| 31 |
{ |
|---|
| 32 |
debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 33 |
debug_add("filtersSerialized is empty"); |
|---|
| 34 |
debug_pop(); |
|---|
| 35 |
|
|---|
| 36 |
$this->filters = array(); |
|---|
| 37 |
$this->autoserialize_filters = true; |
|---|
| 38 |
return true; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
$eval = "Array({$this->filtersSerialized});"; |
|---|
| 42 |
|
|---|
| 43 |
$tmpfile = tempnam('', 'midcom_helper_replicator_subscription_dba_unserialize_filters'); |
|---|
| 44 |
$fp = fopen($tmpfile, 'w'); |
|---|
| 45 |
fwrite($fp, "<?php {$eval} ?>"); |
|---|
| 46 |
fclose($fp); |
|---|
| 47 |
$parse_results = `php -l {$tmpfile}`; |
|---|
| 48 |
|
|---|
| 49 |
unlink($tmpfile); |
|---|
| 50 |
|
|---|
| 51 |
if (strstr($parse_results, 'Parse error')) |
|---|
| 52 |
{ |
|---|
| 53 |
debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 54 |
debug_add("'php -l {$tmpfile}' returned: \n===\n{$parse_results}\n===\n"); |
|---|
| 55 |
debug_add('Invalid filter definition', MIDCOM_LOG_ERROR); |
|---|
| 56 |
debug_pop(); |
|---|
| 57 |
return false; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
eval("\$this->filters = {$eval}"); |
|---|
| 61 |
$this->autoserialize_filters = true; |
|---|
| 62 |
return true; |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
function _serialize_filters() |
|---|
| 66 |
{ |
|---|
| 67 |
|
|---|
| 68 |
return; |
|---|
| 69 |
if (!$this->autoserialize_filters) |
|---|
| 70 |
{ |
|---|
| 71 |
|
|---|
| 72 |
return; |
|---|
| 73 |
} |
|---|
| 74 |
$this->filtersSerialized = trim(preg_replace('%^\s*array\((.*)\)\s*$%msi', '\\1', var_export($this->filters, true))); |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
function _on_loaded() |
|---|
| 78 |
{ |
|---|
| 79 |
$this->_unserialize_filters(); |
|---|
| 80 |
return true; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
function _on_creating() |
|---|
| 84 |
{ |
|---|
| 85 |
if (!is_array($this->filters)) |
|---|
| 86 |
{ |
|---|
| 87 |
$this->filters = array(); |
|---|
| 88 |
} |
|---|
| 89 |
$this->autoserialize_filters = true; |
|---|
| 90 |
$this->_serialize_filters(); |
|---|
| 91 |
return true; |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
function _on_updating() |
|---|
| 95 |
{ |
|---|
| 96 |
$this->_serialize_filters(); |
|---|
| 97 |
return true; |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
* As default only admins can read subscriptions that do not have specific privileges granted. |
|---|
| 102 |
*/ |
|---|
| 103 |
function get_class_magic_default_privileges() |
|---|
| 104 |
{ |
|---|
| 105 |
$privileges = parent::get_class_magic_default_privileges(); |
|---|
| 106 |
$privileges['EVERYONE']['midgard:read'] = MIDCOM_PRIVILEGE_DENY; |
|---|
| 107 |
return $privileges; |
|---|
| 108 |
} |
|---|
| 109 |
} |
|---|
| 110 |
?> |
|---|