Пример #1
0
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new MDispatcher();
     }
     return self::$instance;
 }
Пример #2
0
 protected static function _import(&$plugin, $autocreate = true, $dispatcher = null)
 {
     static $paths = array();
     $plugin->type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $plugin->type);
     $plugin->name = preg_replace('/[^A-Z0-9_\\.-]/i', '', $plugin->name);
     $path = MPATH_PLUGINS . '/plg_' . $plugin->type . '_' . $plugin->name . '/' . $plugin->name . '.php';
     if (!isset($paths[$path])) {
         if (file_exists($path)) {
             if (!isset($paths[$path])) {
                 require_once $path;
             }
             $paths[$path] = true;
             if ($autocreate) {
                 // Makes sure we have an event dispatcher
                 if (!is_object($dispatcher)) {
                     $dispatcher = MDispatcher::getInstance();
                 }
                 $className = 'plg' . $plugin->type . $plugin->name;
                 if (class_exists($className)) {
                     // Load the plugin from the database.
                     if (!isset($plugin->params)) {
                         // Seems like this could just go bye bye completely
                         $plugin = self::getPlugin($plugin->type, $plugin->name);
                     }
                     // Instantiate and register the plugin.
                     new $className($dispatcher, (array) $plugin);
                 }
             }
         } else {
             $paths[$path] = false;
         }
     }
 }
Пример #3
0
 public static function prepare($text, $params = null, $context = 'text')
 {
     if ($params === null) {
         $params = new MObject();
     }
     $article = new stdClass();
     $article->text = $text;
     MPluginHelper::importPlugin('content');
     $dispatcher = MDispatcher::getInstance();
     $dispatcher->trigger('onContentPrepare', array($context, &$article, &$params, 0));
     return $article->text;
 }
Пример #4
0
 public static function authorise($response, $options = array())
 {
     // Get plugins in case they haven't been loaded already
     MPluginHelper::getPlugin('user');
     MPluginHelper::getPlugin('authentication');
     $dispatcher = MDispatcher::getInstance();
     $results = $dispatcher->trigger('onUserAuthorisation', array($response, $options));
     return $results;
 }
Пример #5
0
 public function search($posts, $wp_query)
 {
     if (!is_search() or !isset($wp_query->query) or !isset($wp_query->query['s'])) {
         return $posts;
     }
     $this->wp_query = $wp_query;
     $text = get_search_query();
     mimport('framework.plugin.helper');
     mimport('framework.application.component.helper');
     MPluginHelper::importPlugin('search');
     $dispatcher = MDispatcher::getInstance();
     $plg_result = $dispatcher->trigger('onContentSearch', array($text, 'all', 'newest', null, $this->context));
     $miwo_result = array();
     foreach ($plg_result as $rows) {
         $miwo_result = array_merge($miwo_result, $rows);
     }
     $posts = array_merge($miwo_result, $posts);
     usort($posts, array('MWordpress', '_sortResult'));
     return $posts;
 }
Пример #6
0
 public function triggerEvent($event, $args = null)
 {
     $dispatcher = MDispatcher::getInstance();
     return $dispatcher->trigger($event, $args);
 }
Пример #7
0
 protected function cleanCache($group = null, $client_id = 0)
 {
     // Initialise variables;
     $conf = MFactory::getConfig();
     $dispatcher = MDispatcher::getInstance();
     $options = array('defaultgroup' => $group ? $group : (isset($this->option) ? $this->option : MRequest::getCmd('option')), 'cachebase' => MPATH_CACHE);
     $cache = MCache::getInstance('callback', $options);
     $cache->clean();
     // Trigger the onContentCleanCache event.
     $dispatcher->trigger($this->event_clean_cache, $options);
 }
Пример #8
0
 public function delete()
 {
     MPluginHelper::importPlugin('user');
     // Trigger the onUserBeforeDelete event
     $dispatcher = MDispatcher::getInstance();
     $dispatcher->trigger('onUserBeforeDelete', array($this->getProperties()));
     $result = false;
     if (!($result = wp_delete_user($this->id))) {
         $this->setError('Not deleted');
     }
     // Trigger the onUserAfterDelete event
     $dispatcher->trigger('onUserAfterDelete', array($this->getProperties(), $result, $this->getError()));
     return $result;
 }
Пример #9
0
 protected function preprocessForm(MForm $form, $data, $group = 'content')
 {
     // Import the appropriate plugin group.
     MPluginHelper::importPlugin($group);
     // Get the dispatcher.
     $dispatcher = MDispatcher::getInstance();
     // Trigger the form preparation event.
     $results = $dispatcher->trigger('onContentPrepareForm', array($form, $data));
     // Check for errors encountered while preparing the form.
     if (count($results) && in_array(false, $results, true)) {
         // Get the last error.
         $error = $dispatcher->getError();
         if (!$error instanceof Exception) {
             throw new Exception($error);
         }
     }
 }