示例#1
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;
 }
示例#2
0
文件: helper.php 项目: vanie3/appland
 protected static function _load()
 {
     if (self::$plugins !== null) {
         return self::$plugins;
     }
     mimport('framework.filesystem.folder');
     if (!MFolder::exists(MPATH_PLUGINS)) {
         self::$plugins = array();
         return self::$plugins;
     }
     $folders = MFolder::folders(MPATH_PLUGINS);
     if (empty($folders)) {
         self::$plugins = array();
         return self::$plugins;
     }
     self::$plugins = array();
     foreach ($folders as $folder) {
         $folder = str_replace('plg_', '', $folder);
         list($type, $name) = explode('_', $folder);
         $plg = new stdClass();
         $plg->type = $type;
         $plg->name = $name;
         $plg->params = null;
         $xml_file = MPATH_MIWI . '/plugins/plg_' . $type . '_' . $name . '/' . $name . '.xml';
         if (file_exists($xml_file)) {
             $form = MForm::getInstance($folder . '_form', $xml_file, array(), false, 'config');
             $field_sets = $form->getFieldsets();
             if (!empty($field_sets)) {
                 $params = array();
                 foreach ($field_sets as $name => $field_set) {
                     foreach ($form->getFieldset($name) as $field) {
                         $field_name = $field->get('fieldname');
                         $field_value = $field->get('value');
                         $params[$field_name] = $field_value;
                     }
                 }
                 $plg->params = json_encode($params);
             }
         }
         self::$plugins[] = $plg;
     }
     return self::$plugins;
 }
示例#3
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;
 }
示例#4
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;
 }
示例#5
0
 public function logout($userid = null, $options = array())
 {
     // Get a user object from the MApplication.
     $user = MFactory::getUser($userid);
     // Build the credentials array.
     $parameters['username'] = $user->get('username');
     $parameters['id'] = $user->get('id');
     // Set clientid in the options array if it hasn't been set already.
     if (!isset($options['clientid'])) {
         $options['clientid'] = $this->getClientId();
     }
     // Import the user plugin group.
     MPluginHelper::importPlugin('user');
     // OK, the credentials are built. Lets fire the onLogout event.
     $results = $this->triggerEvent('onUserLogout', array($parameters, $options));
     // Check if any of the plugins failed. If none did, success.
     if (!in_array(false, $results, true)) {
         // Use domain and path set in config for cookie if it exists.
         $cookie_domain = $this->getCfg('cookie_domain', '');
         $cookie_path = $this->getCfg('cookie_path', '/');
         setcookie(self::getHash('MLOGIN_REMEMBER'), false, time() - 86400, $cookie_path, $cookie_domain);
         return true;
     }
     // Trigger onUserLoginFailure Event.
     $this->triggerEvent('onUserLogoutFailure', array($parameters));
     return false;
 }
示例#6
0
文件: user.php 项目: vanie3/appland
 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;
 }
示例#7
0
文件: form.php 项目: vanie3/appland
 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);
         }
     }
 }
示例#8
0
文件: admin.php 项目: vanie3/appland
 public function save($data)
 {
     $dispatcher = MEventDispatcher::getInstance();
     $table = $this->getTable();
     $key = $table->getKeyName();
     $pk = !empty($data[$key]) ? $data[$key] : (int) $this->getState($this->getName() . '.id');
     $isNew = true;
     // Include the content plugins for the on save events.
     MPluginHelper::importPlugin('content');
     // Allow an exception to be thrown.
     try {
         // Load the row if saving an existing record.
         if ($pk > 0) {
             $table->load($pk);
             $isNew = false;
         }
         // Bind the data.
         if (!$table->bind($data)) {
             $this->setError($table->getError());
             return false;
         }
         // Prepare the row for saving
         $this->prepareTable($table);
         // Check the data.
         if (!$table->check()) {
             $this->setError($table->getError());
             return false;
         }
         // Trigger the onContentBeforeSave event.
         $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, $table, $isNew));
         if (in_array(false, $result, true)) {
             $this->setError($table->getError());
             return false;
         }
         // Store the data.
         if (!$table->store()) {
             $this->setError($table->getError());
             return false;
         }
         // Clean the cache.
         $this->cleanCache();
         // Trigger the onContentAfterSave event.
         $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, $table, $isNew));
     } catch (Exception $e) {
         $this->setError($e->getMessage());
         return false;
     }
     $pkName = $table->getKeyName();
     if (isset($table->{$pkName})) {
         $this->setState($this->getName() . '.id', $table->{$pkName});
     }
     $this->setState($this->getName() . '.new', $isNew);
     return true;
 }