| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
class CJTWordpressEvents extends CJTEvents { |
| 10 |
|
| 11 |
/** |
| 12 |
* |
| 13 |
*/ |
| 14 |
const HOOK_ACTION = 'action'; |
| 15 |
|
| 16 |
/** |
| 17 |
* |
| 18 |
*/ |
| 19 |
const HOOK_CUSTOM = 'custom'; |
| 20 |
|
| 21 |
/** |
| 22 |
* |
| 23 |
*/ |
| 24 |
const HOOK_FILTER = 'filter'; |
| 25 |
|
| 26 |
/** |
| 27 |
* put your comment there... |
| 28 |
* |
| 29 |
* @param mixed $options |
| 30 |
*/ |
| 31 |
public static function __init($options = array()) { |
| 32 |
// Initialize CJTEvents! |
| 33 |
parent::__init($options); |
| 34 |
// Extend all Hookable objects with CJTEvents events! |
| 35 |
$events = new CJTWordpressEvents(__CLASS__, $options, true); |
| 36 |
// Inherits all CJTEvents and CJTWordpressEvents Events to all hookable objects! |
| 37 |
self::$definition->addBaseClass(__CLASS__, array('hookType' => self::HOOK_FILTER)); |
| 38 |
return $events; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* put your comment there... |
| 43 |
* |
| 44 |
* @param mixed $type |
| 45 |
*/ |
| 46 |
protected function prepareEventTypeOptions($event) { |
| 47 |
$type =& $event['type']; |
| 48 |
switch ($type['hookType']) { |
| 49 |
case self::HOOK_ACTION: |
| 50 |
$type['subjectClass'] = 'CJTEEWordpressHookAction'; |
| 51 |
$type['file'] = 'action.subject.php'; |
| 52 |
$type['observerClass'] = 'CJTWordpressActionHookObserver'; |
| 53 |
$type['observerFile'] = 'wordpress-hook-action.observer.php'; |
| 54 |
break; |
| 55 |
case self::HOOK_FILTER: |
| 56 |
$type['subjectClass'] = 'CJTEEWordpressHookFilter'; |
| 57 |
$type['file'] = 'filter.subject.php'; |
| 58 |
$type['observerClass'] = 'CJTWordpressFilterHookObserver'; |
| 59 |
$type['observerFile'] = 'wordpress-hook-filter.observer.php'; |
| 60 |
break; |
| 61 |
} |
| 62 |
return $event; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* put your comment there... |
| 67 |
* |
| 68 |
* @param mixed $type |
| 69 |
* @param mixed $params |
| 70 |
*/ |
| 71 |
public function trigger($typeName, $params = array(), $typePrefixed = true) { |
| 72 |
$result = false; |
| 73 |
// Get type object! |
| 74 |
$type = $this->parseEventType($typeName, $typePrefixed); |
| 75 |
// Get event type subject! |
| 76 |
$subject = $this->getSubject($type); |
| 77 |
// Notify observers! |
| 78 |
if ($subject) { |
| 79 |
$result = call_user_func(array(&$subject, 'callIndirect'), $params); |
| 80 |
} |
| 81 |
return $result; |
| 82 |
} |
| 83 |
|
| 84 |
} // End class. |