예제 #1
0
 /**
  * Save a review
  *
  * @return  void
  */
 public function savereview()
 {
     // Is the user logged in?
     if (User::isGuest()) {
         $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_LOGIN_NOTICE'));
         return;
     }
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $data = Request::getVar('review', array(), 'post', 'none', 2);
     // Bind the form data to our object
     $row = \Components\Resources\Reviews\Models\Review::oneOrNew($data['id'])->set($data);
     // Perform some text cleaning, etc.
     if ($row->isNew()) {
         $row->set('state', \Components\Resources\Reviews\Models\Review::STATE_PUBLISHED);
     }
     $row->set('comment', \Hubzero\Utility\Sanitize::stripImages(\Hubzero\Utility\Sanitize::clean($row->get('comment'))));
     $row->set('anonymous', $row->get('anonymous') ? 1 : 0);
     // Save the data
     if (!$row->save()) {
         $this->setError($row->getError());
         return;
     }
     // Calculate the new average rating for the parent resource
     $resource =& $this->resource;
     $resource->calculateRating();
     $resource->updateRating();
     // Instantiate a helper object and get all the contributor IDs
     $database = App::get('db');
     $helper = new \Components\Resources\Helpers\Helper($resource->id, $database);
     $helper->getContributorIDs();
     $users = $helper->contributorIDs;
     // Build the subject
     $subject = Config::get('sitename') . ' ' . Lang::txt('PLG_RESOURCES_REVIEWS_CONTRIBUTIONS');
     // Message
     $eview = new \Hubzero\Plugin\View(array('folder' => 'resources', 'element' => 'reviews', 'name' => 'emails'));
     $eview->option = $this->_option;
     $eview->user = User::getInstance();
     $eview->resource = $resource;
     $eview->review = $row;
     $message = $eview->loadTemplate();
     // Build the "from" data for the e-mail
     $from = array('name' => Config::get('sitename') . ' ' . Lang::txt('PLG_RESOURCES_REVIEWS_CONTRIBUTIONS'), 'email' => Config::get('mailfrom'));
     // Send message
     if (!Event::trigger('xmessage.onSendMessage', array('resources_new_comment', $subject, $message, $from, $users, $this->_option))) {
         $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_FAILED_TO_MESSAGE'));
     }
 }
예제 #2
0
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    Shawn Rice <*****@*****.**>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access.
defined('_HZEXEC_') or die;
$database = App::get('db');
// Instantiate a helper object
$helper = new \Components\Resources\Helpers\Helper($this->line->id, $database);
$helper->getContributors();
$helper->getContributorIDs();
/*
// Determine if they have access to edit
if (!Config::isGuest())
{
	if ((!$this->show_edit && $this->line->created_by == Config::get('id'))
	 || in_array(Config::get('id'), $helper->contributorIDs))
	{
		$this->show_edit = 2;
	}
}
*/
// Get parameters
$params = clone $this->config;
$rparams = new \Hubzero\Config\Registry($this->line->params);
$params->merge($rparams);
예제 #3
0
 /**
  * Save a review
  *
  * @return     void
  */
 public function savereview()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $resource_id = Request::getInt('resource_id', 0);
     // Do we have a resource ID?
     if (!$resource_id) {
         // No ID - fail! Can't do anything else without an ID
         $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_NO_RESOURCE_ID'));
         return;
     }
     $database = App::get('db');
     // Bind the form data to our object
     $row = new \Components\Resources\Tables\Review($database);
     if (!$row->bind($_POST)) {
         $this->setError($row->getError());
         return;
     }
     // Perform some text cleaning, etc.
     $row->id = Request::getInt('reviewid', 0);
     if (!$row->id) {
         $row->state = 1;
     }
     $row->comment = \Hubzero\Utility\Sanitize::stripImages(\Hubzero\Utility\Sanitize::clean($row->comment));
     $row->anonymous = $row->anonymous == 1 || $row->anonymous == '1' ? $row->anonymous : 0;
     $row->created = $row->created && $row->created != '0000-00-00 00:00:00' ? $row->created : Date::toSql();
     // 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 resource
     $resource =& $this->resource;
     $resource->calculateRating();
     $resource->updateRating();
     // Process tags
     $tags = trim(Request::getVar('review_tags', ''));
     if ($tags) {
         $rt = new \Components\Resources\Helpers\Tags($resource_id);
         $rt->setTags($tags, $row->user_id);
     }
     // Instantiate a helper object and get all the contributor IDs
     $helper = new \Components\Resources\Helpers\Helper($resource->id, $database);
     $helper->getContributorIDs();
     $users = $helper->contributorIDs;
     // Build the subject
     $subject = Config::get('sitename') . ' ' . Lang::txt('PLG_RESOURCES_REVIEWS_CONTRIBUTIONS');
     // Message
     $eview = new \Hubzero\Plugin\View(array('folder' => 'resources', 'element' => 'reviews', 'name' => 'emails'));
     $eview->option = $this->_option;
     $eview->user = User::getRoot();
     $eview->resource = $resource;
     $eview->review = $row;
     $message = $eview->loadTemplate();
     // Build the "from" data for the e-mail
     $from = array('name' => Config::get('sitename') . ' ' . Lang::txt('PLG_RESOURCES_REVIEWS_CONTRIBUTIONS'), 'email' => Config::get('mailfrom'));
     // Send message
     if (!Event::trigger('xmessage.onSendMessage', array('resources_new_comment', $subject, $message, $from, $users, $this->_option))) {
         $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_FAILED_TO_MESSAGE'));
     }
 }