/** * Sends a message to all contributors on a resource * * @param object $row Resource * @param object $database JDatabase * @return void */ private function _emailContributors($row, $database) { include_once dirname(dirname(__DIR__)) . DS . 'helpers' . DS . 'helper.php'; $helper = new Helper($row->id, $database); $helper->getContributorIDs(); $contributors = $helper->contributorIDs; if ($contributors && count($contributors) > 0) { // E-mail "from" info $from = array(); $from['email'] = Config::get('mailfrom'); $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_RESOURCES_SUBMISSIONS'); // Message subject $subject = Lang::txt('COM_RESOURCES_EMAIL_SUBJECT'); $base = Request::base(); $base = trim($base, '/'); if (substr($base, -13) == 'administrator') { $base = substr($base, 0, strlen($base) - 13); } $base = trim($base, '/'); // Build message $message = Lang::txt('COM_RESOURCES_EMAIL_MESSAGE', Config::get('sitename')) . "\r\n"; $message .= $base . DS . 'resources' . DS . $row->id; // Send message if (!Event::trigger('xmessage.onSendMessage', array('resources_submission_approved', $subject, $message, $from, $contributors, $this->_option))) { $this->setError(Lang::txt('COM_RESOURCES_ERROR_FAILED_TO_MESSAGE_USERS')); } } }
/** * Sets the state of a resource * Redirects to main listing * * @return void */ public function stateTask($publish = 1) { // Check for request forgeries Request::checkToken(['get', 'post']); // Incoming $pid = Request::getInt('pid', 0); $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; // Check for a resource if (count($ids) < 1) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_RESOURCES_ERROR_SELECT_TO', $this->_task), 'error'); return; } $i = 0; // Loop through all the IDs foreach ($ids as $id) { // Load the resource $resource = new Resource($this->database); $resource->load($id); // Only allow changes if the resource isn't checked out or // is checked out by the user requesting changes if (!$resource->checked_out || $resource->checked_out == Config::get('id')) { $old = $resource->published; $resource->published = $publish; // If we're publishing, set the UP date if ($publish) { $resource->publish_up = Date::toSql(); } // Is this a standalone resource and we need to email approved submissions? if ($resource->standalone == 1 && $this->config->get('email_when_approved')) { // If the state went from pending to published if ($resource->published == 1 && $old == 3) { $this->_emailContributors($resource, $this->database); // Log activity $recipients = array(['resource', $resource->id], ['user', $resource->created_by]); $helper = new Helper($resource->id, $this->database); $helper->getContributorIDs(); $contributors = $helper->contributorIDs; foreach ($contributors as $author) { if ($author > 0) { $recipients[] = ['user', $author]; } } Event::trigger('system.logActivity', ['activity' => ['action' => 'published', 'scope' => 'resource', 'scope_id' => $resource->title, 'description' => Lang::txt('COM_RESOURCES_ACTIVITY_ENTRY_PUBLISHED', '<a href="' . Route::url('index.php?option=com_resources&id=' . $resource->id) . '">' . $resource->title . '</a>'), 'details' => array('title' => $resource->title, 'url' => Route::url('index.php?option=com_resources&id=' . $resource->id))], 'recipients' => $recipients]); } } // Store and checkin the resource $resource->store(); $resource->checkin(); $i++; } } if ($i) { if ($publish == -1) { $this->setMessage(Lang::txt('COM_RESOURCES_ITEMS_ARCHIVED', $i)); } elseif ($publish == 1) { $this->setMessage(Lang::txt('COM_RESOURCES_ITEMS_PUBLISHED', $i)); } elseif ($publish == 0) { $this->setMessage(Lang::txt('COM_RESOURCES_ITEMS_UNPUBLISHED', $i)); } } // Redirect App::redirect($this->buildRedirectURL($pid)); }