Example #1
0
File: auth.php Project: pihizi/qf
 static function logout()
 {
     $token = self::token();
     Event::trigger('auth.logout', $token);
     session_unset();
     Event::trigger('auth.post_logout', $token);
 }
Example #2
0
 /**
  * Pub view for project files, notes etc.
  *
  * @return     void
  */
 public function displayTask()
 {
     require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'tables' . DS . 'publicstamp.php';
     // Incoming
     $stamp = Request::getVar('s', '');
     // Clean up stamp value (only numbers and letters)
     $regex = array('/[^a-zA-Z0-9]/');
     $stamp = preg_replace($regex, '', $stamp);
     // Load item reference
     $objSt = new Tables\Stamp($this->database);
     if (!$stamp || !$objSt->loadItem($stamp)) {
         App::redirect(Route::url('index.php?option=' . $this->_option));
         return;
     }
     // Can only serve files or notes at the moment
     if (!in_array($objSt->type, array('files', 'notes', 'publications'))) {
         App::redirect(Route::url('index.php?option=' . $this->_option));
         return;
     }
     // Serve requested item
     $content = Event::trigger('projects.serve', array($objSt->type, $objSt->projectid, $objSt->reference));
     // Output
     foreach ($content as $out) {
         if ($out) {
             return $out;
         }
     }
     // Redirect if nothing fetched
     App::redirect(Route::url('index.php?option=' . $this->_option));
     return;
 }
Example #3
0
 /**
  * Method to get a single record.
  *
  * @param   integer  $pk  The id of the primary key.
  *
  * @return  mixed  Object on success, false on failure.
  *
  * @since   2.5
  */
 public function getItem($pk = null)
 {
     $result = parent::getItem($pk);
     // Trigger the data preparation event.
     $results = Event::trigger('user.onContentPrepareData', array('com_users.note', $result));
     return $result;
 }
Example #4
0
 /**
  * Return data on a resource view (this will be some form of HTML)
  *
  * @param   object  $resource  Current resource
  * @param   string  $option    Name of the component
  * @param   array   $areas     Active area(s)
  * @param   string  $rtrn      Data to be returned
  * @return  array
  */
 public function onResources($model, $option, $areas, $rtrn = 'all')
 {
     if (!$model->type->params->get('plg_share')) {
         return;
     }
     $arr = array('area' => $this->_name, 'html' => '', 'metadata' => '');
     $resource = $model->resource;
     $sef = Route::url('index.php?option=com_resources&' . ($resource->alias ? 'alias=' . $resource->alias : 'id=' . $resource->id));
     $url = Request::base() . ltrim($sef, '/');
     // Incoming action
     $sharewith = Request::getVar('sharewith', '');
     if ($sharewith) {
         // Log the activity
         if (!User::isGuest()) {
             Event::trigger('system.logActivity', ['activity' => ['action' => 'shared', 'scope' => 'resource', 'scope_id' => $resource->id, 'description' => Lang::txt('PLG_RESOURCES_SHARE_ENTRY_SHARED', '<a href="' . $sef . '">' . $resource->title . '</a>', $sharewith), 'details' => array('with' => $sharewith, 'title' => $resource->title, 'url' => $sef)], 'recipients' => [['resource', $resource->id], ['user', $resource->created_by], ['user', User::get('id')]]]);
         }
         // Email form
         if ($sharewith == 'email') {
             // Instantiate a view
             $view = $this->view('email', 'options')->set('option', $option)->set('resource', $resource)->set('_params', $this->params)->set('url', $url)->setErrors($this->getErrors());
             // Return the output
             $view->display();
             exit;
         }
         return $this->share($sharewith, $url, $resource);
     }
     // Build the HTML meant for the "about" tab's metadata overview
     if ($rtrn == 'all' || $rtrn == 'metadata') {
         // Instantiate a view
         $view = $this->view('default', 'options')->set('option', $option)->set('resource', $resource)->set('_params', $this->params)->set('url', $url)->setErrors($this->getErrors());
         // Return the output
         $arr['metadata'] = $view->loadTemplate();
     }
     return $arr;
 }
Example #5
0
 /**
  * Get what's new based on a time period and category
  *
  * @param   string  $period   Time period to return results for
  * @param   string  $category Category to filter by
  * @param   integer $limit    Limit number of results returned
  * @return  array
  */
 public static function getBasedOnPeriodAndCategory($period = 'month', $category = '', $limit = 0)
 {
     // parse the time period for use by the whats new plugins
     $p = self::parseTimePeriod($period);
     // get the search areas
     $areas = array();
     $search_areas = \Event::trigger('whatsnew.onWhatsNewAreas');
     foreach ($search_areas as $search_area) {
         $areas = array_merge($areas, $search_area);
     }
     // get the results
     $config = array($p, $limit, 0, $areas);
     $results = \Event::trigger('onWhatsNew', $config);
     $new = array();
     $i = 0;
     foreach ($areas as $k => $area) {
         $new[$i]['alias'] = $k;
         $new[$i]['title'] = $k == 'resources' ? 'Resources' : $area;
         $new[$i]['results'] = $results[$i];
         $i++;
     }
     // check to see if we only want to return results for a certain category
     if ($category != '') {
         $index = 0;
         foreach ($areas as $k => $area) {
             if ($category == $k) {
                 return $new[$index];
             }
             $index++;
         }
     }
     return $new;
 }
 public function handle()
 {
     require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php';
     $ms = new \Components\Storefront\Models\Memberships();
     /* NEW
     		$subscription = StorefrontModelMemberships::getSubscriptionObject($this->type, $this->pId, $this->uId);
     		// Get the expiration for the current subscription (if any)
     		$currentExpiration = $subscription->getExpiration();
     		*/
     // Get current registration
     $membership = $ms->getMembershipInfo($this->crtId, $this->item['info']->pId);
     $expiration = $membership['crtmExpires'];
     /* Add the user to the corresponding user access group (pull access group ID from the meta) */
     try {
         // Get user ID for the cart
         require_once dirname(dirname(dirname(__DIR__))) . DS . 'models' . DS . 'Cart.php';
         $userId = \Components\Cart\Models\Cart::getCartUser($this->crtId);
         // Get the user group ID to set the user to (from meta)
         require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Product.php';
         $userGId = \Components\Storefront\Models\Product::getMeta($this->item['info']->pId, 'userGroupId');
         $add = \JUserHelper::addUserToGroup($userId, $userGId);
         if ($add instanceof \Exception) {
             mail(Config::get('mailfrom'), 'Error adding to the group', $add->getMessage() . ' Cart #' . $this->crtId);
         }
         $table = \JTable::getInstance('User', 'JTable', array());
         $table->load($userId);
         // Trigger the onAftereStoreUser event
         Event::trigger('onUserAfterSave', array($table->getProperties(), false, true, null));
     } catch (Exception $e) {
         // Error
         return false;
     }
 }
Example #7
0
 /**
  * Single shot defer handeler install
  */
 protected static function install_shutdown()
 {
     if (static::$inited_shutdown) {
         return;
     }
     // Disable time limit
     set_time_limit(0);
     // HHVM support
     if (function_exists('register_postsend_function')) {
         register_postsend_function(function () {
             Event::trigger('core.shutdown');
         });
     } else {
         if (function_exists('fastcgi_finish_request')) {
             register_shutdown_function(function () {
                 fastcgi_finish_request();
                 Event::trigger('core.shutdown');
             });
         } else {
             register_shutdown_function(function () {
                 Event::trigger('core.shutdown');
             });
         }
     }
     static::$inited_shutdown = true;
 }
 /**
  * Output the autocompleter
  *
  * @param   string  $what   The component to call
  * @param   string  $name   Name of the input field
  * @param   string  $value  The value of the input field
  * @param   string  $id     ID of the input field
  * @param   string  $class  CSS class(es) for the input field
  * @param   string  $size   The size of the input field
  * @param   string  $wsel   AC autopopulates a select list based on choice?
  * @param   string  $type   Allow single or multiple entries
  * @param   string  $dsabl  Readonly input
  * @return  string
  * @throws  \InvalidArgumentException  If wrong type passed
  */
 public function __invoke($what = null, $name = null, $value = null, $id = null, $class = null, $size = null, $wsel = false, $type = 'multi', $dsabl = false)
 {
     if (!in_array($what, array('tags', 'members', 'groups'))) {
         throw new \InvalidArgumentException(__METHOD__ . '(); ' . \Lang::txt('Autocompleter for "%s" not supported.', $what));
     }
     $id = $id ?: str_replace(array('[', ']'), '', $name);
     switch ($type) {
         case 'multi':
             $event = 'onGetMultiEntry';
             break;
         case 'single':
             $event = 'onGetSingleEntry';
             if ($wsel) {
                 $event = 'onGetSingleEntryWithSelect';
             }
             break;
         default:
             throw new \InvalidArgumentException(__METHOD__ . '(); ' . \Lang::txt('Autocompleter type "%s" not supported.', $type));
             break;
     }
     $results = \Event::trigger('hubzero.' . $event, array(array($what, $name, $id, $class, $value, $size, $wsel, $type, $dsabl)));
     if (count($results) > 0) {
         $results = implode("\n", $results);
     } else {
         $results = '<input type="text" name="' . $name . '" id="' . $id . '" value="' . $value . '" />';
     }
     return $results;
 }
Example #9
0
 /**
  * Return data on a publication view (this will be some form of HTML)
  *
  * @param   object   $publication
  * @param   string   $option
  * @param   array    $areas
  * @param   string   $rtrn
  * @param   string   $version
  * @param   boolean  $extended
  * @return  array
  */
 public function onPublication($publication, $option, $areas, $rtrn = 'all', $version = 'default', $extended = true)
 {
     $arr = array('html' => '', 'metadata' => '', 'name' => 'share');
     // Hide if version not published
     if (!$extended || in_array($publication->state, array(4, 5, 6))) {
         return $arr;
     }
     $sef = Route::url('index.php?option=' . $option . '&id=' . $publication->id);
     $sef = rtrim($sef, '/') . '/?v=' . $publication->version_number;
     $url = Request::base() . ltrim($sef, '/');
     $mediaUrl = Request::base() . trim($sef, '/') . '/' . $publication->version_id . '/Image:master';
     // Incoming action
     $sharewith = Request::getVar('sharewith', '');
     if ($sharewith) {
         if (!User::isGuest()) {
             // Log the activity
             Event::trigger('system.logActivity', ['activity' => ['action' => 'shared', 'scope' => 'publication', 'scope_id' => $publication->id, 'description' => Lang::txt('PLG_PUBLICATIONS_SHARE_ENTRY_SHARED', '<a href="' . $sef . '">' . $publication->title . '</a>', $sharewith), 'details' => array('with' => $sharewith, 'title' => $publication->title, 'url' => $sef, 'version' => $publication->version_number)], 'recipients' => [['publication', $publication->id], ['user', $publication->created_by], ['user', User::get('id')]]]);
         }
         return $this->share($sharewith, $url, $mediaUrl, $publication, $version);
     }
     // Build the HTML meant for the "about" tab's metadata overview
     if ($rtrn == 'all' || $rtrn == 'metadata') {
         // Instantiate a view
         $view = $this->view('default', 'options')->set('option', $option)->set('publication', $publication)->set('version', $version)->set('_params', $this->params)->set('url', $url)->setErrors($this->getErrors());
         // Return the output
         $arr['metadata'] = $view->loadTemplate();
     }
     return $arr;
 }
Example #10
0
 public static function traceError($errno, $errstr, $errfile = null, $errline = null)
 {
     // This error code is not included in error_reporting
     if (!(error_reporting() & $errno)) {
         //todo throw exception
         return;
     }
     switch ($errno) {
         case E_USER_ERROR:
             $type = 'Fatal';
             break;
         case E_USER_WARNING:
         case E_WARNING:
             $type = 'Warning';
             break;
         case E_USER_NOTICE:
         case E_NOTICE:
         case E_STRICT:
             $type = 'Notice';
             break;
         default:
             $type = 'Error';
             break;
     }
     $e = new \ErrorException($type . ': ' . $errstr, 0, $errno, $errfile, $errline);
     $chk_specific = array_filter((array) Event::trigger('core.error.' . strtolower($type), $e));
     $chk_general = array_filter((array) Event::trigger('core.error', $e));
     if (!($chk_specific || $chk_general)) {
         static::traceException($e);
     }
     return true;
 }
Example #11
0
 /**
  * Process the index queue
  *
  * @museDescription  Processes the index queue
  *
  * @return  void
  **/
 public function processQueue()
 {
     require_once PATH_CORE . DS . 'components' . DS . 'com_search' . DS . 'models' . DS . 'indexqueue.php';
     require_once PATH_CORE . DS . 'components' . DS . 'com_search' . DS . 'models' . DS . 'blacklist.php';
     // Get the type needed to be indexed;
     $items = \Components\Search\Models\QueueDB::all()->where('status', '=', 0)->limit(100)->rows();
     // Refresh indexed material if no work to do
     if ($items->count() <= 0) {
         $items = \Components\Search\Models\QueueDB::all()->where('status', '=', 1)->where('action', '=', 'index')->order('modified', 'ASC')->limit(100)->rows();
     }
     // Get the blacklist
     $sql = "SELECT doc_id FROM #__search_blacklist;";
     $db = App::get('db');
     $db->setQuery($sql);
     $blacklist = $db->query()->loadColumn();
     foreach ($items as $item) {
         $format = Event::trigger('search.onIndex', array($item->type, $item->type_id, true));
         if (isset($format[0])) {
             $this->processRows($format[0], $item->action, $blacklist);
             $timestamp = \Hubzero\Utility\Date::of()->toSql();
             $item->set('modified', $timestamp);
             $item->set('status', 1);
         } else {
             $item->set('status', '2');
         }
         $item->save();
     }
 }
Example #12
0
 /** 
  * @dataProvider providerTrigger
  */
 public function testTrigger($data)
 {
     Event::trigger('test', $data);
     if ($data !== 'ok') {
         $this->fail('изменения не внесены');
     }
 }
Example #13
0
 public static function exec($query, $params = [])
 {
     $query = Filter::with('core.sql.query', $query);
     $statement = static::prepare($query);
     Event::trigger('core.sql.query', $query, $params, !!$statement);
     static::$last_exec_success = $statement && $statement->execute($params);
     return $statement;
 }
Example #14
0
 public static function error($message, $status = 501)
 {
     Event::trigger('api.error', [$message, $status]);
     Response::status($status);
     Response::json(['error' => ['type' => 'fatal', 'status' => $status, 'message' => $message]]);
     Response::send();
     exit;
 }
 function delete() {
     if (User::$current->logout()) {
         Event::trigger(Event::TYPE_USER_LOGOUT, User::$current->account);
         session_start();
         $this->flash('success', "erfolgreich ausgeloggt!");
     }
     $this->redirect_to(array('session', 'add'));
 }
Example #16
0
 /**
  * Return current user if it exists.
  * 
  * @return User instance or false
  */
 public static function user()
 {
     if (is_null(self::$user)) {
         // Not already cached
         self::$user = false;
         // Authentication logic
         $event = new Event('auth_check');
         $auth = $event->trigger(function () {
             // No authentification is required by application
             if (!Config::get('auth_sp_type')) {
                 return array();
             }
             // Check for local authentificaiton (script)
             if (AuthLocal::isAuthenticated()) {
                 return array('local', AuthLocal::attributes());
             }
             // Check for remote application/user
             if ((Config::get('auth_remote_application_enabled') || Config::get('auth_remote_user_enabled')) && AuthRemote::isAuthenticated() && (AuthRemote::application() && Config::get('auth_remote_application_enabled') || !AuthRemote::application() && Config::get('auth_remote_user_enabled'))) {
                 return array('remote', AuthRemote::attributes(), AuthRemote::application() && AuthRemote::isAdmin());
             }
             // Check for SP autentification
             if (AuthSP::isAuthenticated()) {
                 return array('sp', AuthSP::attributes());
             }
             return array();
         });
         self::$type = array_shift($auth);
         self::$attributes = array_shift($auth);
         if (count($auth)) {
             self::$isAdmin = array_shift($auth);
         }
         if (self::$attributes && array_key_exists('uid', self::$attributes)) {
             $user_filter = Config::get('auth_user_filter');
             if ($user_filter) {
                 self::$allowed = false;
                 if (is_string($user_filter)) {
                     if (preg_match('`^([^:]+):(.+)$`', $user_filter, $p)) {
                         self::$allowed = array_key_exists($p[1], self::$attributes) && preg_match('`' . $p[2] . '`', self::$attributes[$p[1]]);
                     }
                 } else {
                     self::$allowed = !(bool) $user_filter;
                 }
                 if (!self::$allowed) {
                     self::$type = null;
                     return;
                 }
             }
             // Set user if got uid attribute
             self::$user = User::fromAttributes(self::$attributes);
             // Save user additionnal attributes if enabled
             if (self::isSP() && Config::get('auth_sp_save_user_additional_attributes') && array_key_exists('additional', self::$attributes) && self::$user->additional_attributes != self::$attributes['additional']) {
                 self::$user->additional_attributes = self::$attributes['additional'];
                 self::$user->save();
             }
         }
     }
     return self::$user;
 }
Example #17
0
 static function shutdown()
 {
     Event::trigger('system.output');
     // 系统显示事件
     Event::trigger('system.shutdown');
     // 系统关闭事件
     Core::shutdown();
     // 内核关闭
 }
Example #18
0
 public function onSend(Envelope $envelope)
 {
     return array_reduce((array) \Event::trigger($this->listener, $envelope), function ($carry, $item) {
         if (is_bool($item)) {
             $carry[] = $item;
         }
         return $carry;
     }, []);
 }
Example #19
0
 public static function send($mail)
 {
     $envelope = static::create($mail);
     $results = (array) static::$driver->onSend($envelope);
     static::trigger('send', $envelope->to(), $envelope, static::$driver_name, $results);
     Event::trigger('core.email.send', $envelope->to(), $envelope, static::$driver_name, $results);
     return count($results) && array_reduce($results, function ($carry, $item) {
         return $carry && $item;
     }, true);
 }
Example #20
0
 /**
  * Method to get the data that should be injected in the form.
  *
  * @return	mixed	The data for the form.
  * @since	1.6
  */
 protected function loadFormData()
 {
     // Check the session for previously entered form data.
     $data = User::getState('com_users.edit.user.data', array());
     if (empty($data)) {
         $data = $this->getItem();
     }
     // TODO: Maybe this can go into the parent model somehow?
     // Trigger the data preparation event.
     $results = Event::trigger('user.onContentPrepareData', array('com_admin.profile', $data));
     // Check for errors encountered while preparing the data.
     if (count($results) && in_array(false, $results, true)) {
         $this->setError($dispatcher->getError());
     }
     return $data;
 }
Example #21
0
File: tabs.php Project: pihizi/qf
 function select($tid)
 {
     if ($this->tab_event) {
         Event::trigger($this->tab_event, $this);
     }
     if ($this->vars['tabs']) {
         if (!isset($this->vars['tabs'][$tid])) {
             $tid = key($this->vars['tabs']);
         }
         $this->vars['tabs'][$tid]['active'] = TRUE;
         $this->vars['selected'] = $tid;
         if ($this->content_event) {
             Event::trigger_one($this->content_event, $tid, $this);
         }
     }
     return $this;
 }
 function create($params) {
     if(empty($params['title'])){
        $this->render_ajax('error', 'Title missing');
     } else {
         if(!isset($params['content'])){
             $params['content'] = '';
         }
         $params['created_at'] = '#NOW';
         if(Comment::create($params, $obj)){
             $account = Account::find()->where(array('id' => $params['account_id']))->first();
             Event::trigger(Event::TYPE_ACCOUNT_COMMENT, User::$current->account, $account, $account->username);
             $this->render_ajax('success', 'Comment Created');
         } else {
             $this->render_ajax('error','Error! ' . $obj->errors[0]);
         }
         
     }
 }
Example #23
0
 /**
  * Initiate application configuration
  * 
  * @static
  * @access	public
  */
 public static function _init()
 {
     if (!is_null(static::$_identity)) {
         return;
     }
     \Config::load('app', true);
     static::$_identity = \Config::get('app.identity');
     if (\Config::get('app.maintenance_mode') == true) {
         static::_maintenance_mode();
     }
     $lang = \Session::get(static::$_identity . '_lang');
     if (!is_null($lang)) {
         \Config::set('language', $lang);
         static::$_language = $lang;
     } else {
         static::$_language = \Config::get('language');
     }
     \Event::trigger('load_language');
     \Event::trigger('load_acl');
 }
 function delete($params){
     if(isset($params['id']) && !empty($params['id'])){
         $id = $params['id'];
         $partner = AccountPartner::find($id);
         $partner_account = $partner->partner;
         if($partner){
             if($partner->destroy()){
                 $this->flash('success', 'Partner deleted');
                 Event::trigger(Event::TYPE_ACCOUNT_PARTNER_REMOVE, User::$current, $partner->account, $partner->partner->username);
             } else {
                 $this->flash('error', 'Deletion failed');
             }
         } else {
             $this->flash('error', 'Partner-Account not found!');
         }
     } else {
         $this->flash('error', 'No ID!');
     }
     $this->redirect_back();
 }
 function update($params){
     $params['updated_by'] = User::$current->id;
     $note = AccountNote::find($params['account_id']);
     if($note){
         $params['updated_by'] = User::$current->id;
         if($note->update($params)){
             Event::trigger(Event::TYPE_ACCOUNT_NOTE, User::$current, $note->account);
             $this->render_ajax('success', 'Note updated');
         } else {
             $errormsg = isset($note->errors[0]) ? $note->errors[0] : '';
             $this->render_ajax('error', 'Error on update ' . $errormsg);
         }
     } else {
         if(AccountNote::create($params)){
             $this->render_ajax('success', 'Note created');
         } else {
             $errormsg = isset($note->errors[0]) ? $note->errors[0] : '';
             $this->render_ajax('error', 'Error on creation ' . $errormsg);
         }
     }
 }
Example #26
0
 public function send()
 {
     $uid = md5(uniqid(time()));
     $headers = [];
     if ($this->from) {
         $headers[] = 'From: ' . $this->from;
     }
     if ($this->replyTo) {
         $headers[] = 'Reply-To: ' . $this->replyTo;
     }
     $headers[] = 'MIME-Version: 1.0';
     $headers[] = "Content-Type: multipart/mixed; boundary=\"" . $uid . "\"";
     $headers[] = "This is a multi-part message in MIME format.";
     $headers[] = "--{$uid}";
     $headers[] = "Content-type: text/html; charset=UTF-8";
     $headers[] = "Content-Transfer-Encoding: quoted-printable";
     $headers[] = '';
     $headers[] = quoted_printable_encode($this->message);
     $headers[] = '';
     foreach ($this->attachments as $file) {
         $name = basename($file);
         $headers[] = "--{$uid}";
         $headers[] = "Content-type: application/octet-stream; name=\"" . $name . "\"";
         $headers[] = "Content-Transfer-Encoding: base64";
         $headers[] = "Content-Disposition: attachment; filename=\"" . $name . "\"";
         $headers[] = '';
         $headers[] = chunk_split(base64_encode(file_get_contents($file)));
         $headers[] = '';
     }
     $headers[] = "--{$uid}--";
     $success = true;
     foreach ($this->recipients as $to) {
         $body = implode("\r\n", $headers);
         $success = mail($to, $this->subject, '', $body);
         Event::trigger('core.email.send', $to, $this->from, $this->subject, $body, $success);
         $success = $success && $success;
     }
     return $success;
 }
Example #27
0
 /**
  * Build the Less file
  *
  * @param string $dest      The destination CSS file
  * @param bool   $force     If set to true, will build whereas the cache status
  * @param array  $variables Less variables to set before compiling the Less file
  */
 public function build($dest, $force = false, $variables = array())
 {
     if (!is_dir(dirname($dest))) {
         mkdir(dirname($dest), 0755, true);
     }
     $compiler = new \lessc();
     $lastCompilationFile = App::cache()->getCacheFilePath($this->getLastCompilationInfoFilename());
     if (!$force && is_file($lastCompilationFile)) {
         $cache = (include $lastCompilationFile);
     } else {
         $cache = $this->source;
     }
     $compiler->setFormatter('compressed');
     $compiler->setPreserveComments(false);
     $compilation = $compiler->cachedCompile($cache, $force);
     if (!is_array($cache) || $compilation['updated'] > $cache['updated']) {
         file_put_contents($dest, '/*** ' . date('Y-m-d H:i:s') . ' ***/' . PHP_EOL . $compilation['compiled']);
         $event = new Event('built-less', array('source' => $this->source, 'dest' => $dest));
         $event->trigger();
         // Save the compilation information
         unset($compilation['compiled']);
         $this->saveLastCompilationInfo($compilation);
     }
 }
Example #28
0
 /**
  * Save a review
  *
  * @return  void
  */
 public function savereview()
 {
     // Is the user logged in?
     if (User::isGuest()) {
         $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_LOGIN_NOTICE'));
         return;
     }
     $publication =& $this->publication;
     // Do we have a publication ID?
     if (!$publication->exists()) {
         // No ID - fail! Can't do anything else without an ID
         $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_NO_RESOURCE_ID'));
         return;
     }
     $database = App::get('db');
     // Bind the form data to our object
     $row = new \Components\Publications\Tables\Review($database);
     if (!$row->bind($_POST)) {
         $this->setError($row->getError());
         return;
     }
     // Perform some text cleaning, etc.
     $row->id = Request::getInt('reviewid', 0);
     $row->state = 1;
     $row->comment = \Hubzero\Utility\Sanitize::stripAll($row->comment);
     $row->anonymous = $row->anonymous == 1 || $row->anonymous == '1' ? $row->anonymous : 0;
     $row->created = $row->created ? $row->created : Date::toSql();
     $row->created_by = User::get('id');
     $message = $row->id ? Lang::txt('PLG_PUBLICATIONS_REVIEWS_EDITS_SAVED') : Lang::txt('PLG_PUBLICATIONS_REVIEWS_REVIEW_POSTED');
     // Check for missing (required) fields
     if (!$row->check()) {
         $this->setError($row->getError());
         return;
     }
     // Save the data
     if (!$row->store()) {
         $this->setError($row->getError());
         return;
     }
     // Calculate the new average rating for the parent publication
     $publication->table()->calculateRating();
     $publication->table()->updateRating();
     // Process tags
     $tags = trim(Request::getVar('review_tags', ''));
     if ($tags) {
         $rt = new \Components\Publications\Helpers\Tags($database);
         $rt->tag_object($row->created_by, $publication->get('id'), $tags, 1, 0);
     }
     // Get version authors
     $users = $publication->table('Author')->getAuthors($publication->get('version_id'), 1, 1, true);
     // Build the subject
     $subject = Config::get('sitename') . ' ' . Lang::txt('PLG_PUBLICATIONS_REVIEWS_CONTRIBUTIONS');
     // Message
     $eview = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'reviews', 'name' => 'emails'));
     $eview->option = $this->_option;
     $eview->juser = User::getInstance();
     $eview->publication = $publication;
     $message = $eview->loadTemplate();
     $message = str_replace("\n", "\r\n", $message);
     // Build the "from" data for the e-mail
     $from = array();
     $from['name'] = Config::get('sitename') . ' ' . Lang::txt('PLG_PUBLICATIONS_REVIEWS_CONTRIBUTIONS');
     $from['email'] = Config::get('mailfrom');
     // Send message
     if (!Event::trigger('xmessage.onSendMessage', array('publications_new_comment', $subject, $message, $from, $users, $this->_option))) {
         $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_FAILED_TO_MESSAGE'));
     }
     App::redirect(Route::url($publication->link('reviews')), $message);
     return;
 }
Example #29
0
 /**
  * Saves a project
  * Redirects to main listing
  *
  * @param   boolean  $redirect
  * @return  void
  */
 public function saveTask($redirect = false)
 {
     // Check for request forgeries
     Request::checkToken();
     // Config
     $setup_complete = $this->config->get('confirm_step', 0) ? 3 : 2;
     // Incoming
     $formdata = $_POST;
     $id = Request::getVar('id', 0);
     $action = Request::getVar('admin_action', '');
     $message = rtrim(\Hubzero\Utility\Sanitize::clean(Request::getVar('message', '')));
     // Load model
     $model = new Models\Project($id);
     if (!$model->exists()) {
         App::redirect('index.php?option=' . $this->_option, Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error');
     }
     $title = $formdata['title'] ? rtrim($formdata['title']) : $model->get('title');
     $type = isset($formdata['type']) ? $formdata['type'] : 1;
     $model->set('title', $title);
     $model->set('about', rtrim(\Hubzero\Utility\Sanitize::clean($formdata['about'])));
     $model->set('type', $type);
     $model->set('modified', Date::toSql());
     $model->set('modified_by', User::get('id'));
     $model->set('private', Request::getInt('private', 0));
     $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_SAVED');
     // Was project suspended?
     $suspended = false;
     if ($model->isInactive()) {
         $suspended = $model->table('Activity')->checkActivity($id, Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_SUSPENDED'));
     }
     $subject = Lang::txt('COM_PROJECTS_PROJECT') . ' "' . $model->get('alias') . '" ';
     $sendmail = 0;
     // Get project managers
     $managers = $model->table('Owner')->getIds($id, 1, 1);
     // Admin actions
     if ($action) {
         switch ($action) {
             case 'delete':
                 $model->set('state', 2);
                 $what = Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_DELETED');
                 $subject .= Lang::txt('COM_PROJECTS_MSG_ADMIN_DELETED');
                 $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_DELETED');
                 break;
             case 'suspend':
                 $model->set('state', 0);
                 $what = Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_SUSPENDED');
                 $subject .= Lang::txt('COM_PROJECTS_MSG_ADMIN_SUSPENDED');
                 $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_SUSPENDED');
                 break;
             case 'reinstate':
                 $model->set('state', 1);
                 $what = $suspended ? Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_REINSTATED') : Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_ACTIVATED');
                 $subject .= $suspended ? Lang::txt('COM_PROJECTS_MSG_ADMIN_REINSTATED') : Lang::txt('COM_PROJECTS_MSG_ADMIN_ACTIVATED');
                 $this->_message = $suspended ? Lang::txt('COM_PROJECTS_SUCCESS_REINSTATED') : Lang::txt('COM_PROJECTS_SUCCESS_ACTIVATED');
                 break;
         }
         // Add activity
         $model->recordActivity($what, 0, '', '', 'project', 0, $admin = 1);
         $sendmail = 1;
     } elseif ($message) {
         $subject .= ' - ' . Lang::txt('COM_PROJECTS_MSG_ADMIN_NEW_MESSAGE');
         $sendmail = 1;
         $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_MESSAGE_SENT');
     }
     // Save changes
     if (!$model->store()) {
         $this->setError($model->getError());
         return false;
     }
     // Incoming tags
     $tags = Request::getVar('tags', '', 'post');
     // Save the tags
     $cloud = new Models\Tags($model->get('id'));
     $cloud->setTags($tags, User::get('id'), 1);
     // Save params
     $incoming = Request::getVar('params', array());
     if (!empty($incoming)) {
         foreach ($incoming as $key => $value) {
             if ($key == 'quota' || $key == 'pubQuota') {
                 // convert GB to bytes
                 $value = Helpers\Html::convertSize(floatval($value), 'GB', 'b');
             }
             $model->saveParam($key, $value);
         }
     }
     // Add members if specified
     $this->model = $model;
     $this->_saveMember();
     // Change ownership
     $this->_changeOwnership();
     // Send message
     if ($this->config->get('messaging', 0) && $sendmail && count($managers) > 0) {
         // Email config
         $from = array();
         $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_PROJECTS');
         $from['email'] = Config::get('mailfrom');
         // Html email
         $from['multipart'] = md5(date('U'));
         // Message body
         $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'admin_plain'));
         $eview->option = $this->_option;
         $eview->subject = $subject;
         $eview->action = $action;
         $eview->project = $model;
         $eview->message = $message;
         $body = array();
         $body['plaintext'] = $eview->loadTemplate(false);
         $body['plaintext'] = str_replace("\n", "\r\n", $body['plaintext']);
         // HTML email
         $eview->setLayout('admin_html');
         $body['multipart'] = $eview->loadTemplate();
         $body['multipart'] = str_replace("\n", "\r\n", $body['multipart']);
         // Send HUB message
         Event::trigger('xmessage.onSendMessage', array('projects_admin_notice', $subject, $body, $from, $managers, $this->_option));
     }
     Notify::message($this->_message, 'success');
     // Redirect to edit view?
     if ($redirect) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=edit&id=' . $id, false));
     } else {
         App::redirect(Route::url('index.php?option=' . $this->_option, false));
     }
 }
Example #30
0
 /**
  * Load team editor
  *
  * @return  html
  */
 protected function _loadTeamEditor()
 {
     // Get plugin output
     $content = Event::trigger('projects.onProject', array($this->model, $this->_task, array('team')));
     if (!isset($content[0])) {
         // Must never happen
         return false;
     }
     if (isset($content[0]['msg']) && !empty($content[0]['msg'])) {
         $this->_setNotification($content[0]['msg']['message'], $content[0]['msg']['type']);
     }
     return $content[0]['html'];
 }