/** * Upload a screenshot * * @return void */ public function uploadTask() { // Incoming $pid = Request::getInt('pid', 0); if (!$pid) { $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID')); $this->displayTask($pid, $version); return; } $version = Request::getVar('version', 'dev'); $title = preg_replace('/\\s+/', ' ', Request::getVar('title', '')); $allowed = array('.gif', '.jpg', '.png', '.bmp'); $changing_version = Request::getInt('changing_version', 0); if ($changing_version) { // reload screen $this->displayTask($pid, $version); return; } // Get resource information $resource = new \Components\Resources\Tables\Resource($this->database); $resource->load($pid); // Incoming file $file = Request::getVar('upload', '', 'files', 'array'); if (!$file['name']) { $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_FILE')); $this->displayTask($pid, $version); return; } // Make the filename safe $file['name'] = Filesystem::clean($file['name']); $file['name'] = str_replace(' ', '_', $file['name']); $file['name'] = str_replace('-tn', '', $file['name']); $file_basename = substr($file['name'], 0, strripos($file['name'], '.')); // strip extention $file_ext = substr($file['name'], strripos($file['name'], '.')); // Make sure we have an allowed format if (!in_array(strtolower($file_ext), $allowed)) { $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_WRONG_FILE_FORMAT')); $this->displayTask($pid, $version); return; } // Get version id $objV = new \Components\Tools\Tables\Version($this->database); $vid = $objV->getVersionIdFromResource($pid, $version); if ($vid == NULL) { $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_VERSION_ID_NOT_FOUND')); $this->displayTask($pid, $version); return; } // Instantiate a new screenshot object $row = new \Components\Resources\Tables\Screenshot($this->database); // Check if file with the same name already exists $files = $row->getFiles($pid, $vid); if (count($files) > 0) { $files = \Components\Tools\Helpers\Utils::transform($files, 'filename'); foreach ($files as $f) { if ($f == $file['name']) { // append extra characters in the end $file['name'] = $file_basename . '_' . time() . $file_ext; $file_basename = $file_basename . '_' . time(); } } } $row->title = preg_replace('/"((.)*?)"/i', "“\\1”", $title); $row->versionid = $vid; $ordering = $row->getLastOrdering($pid, $vid); $row->ordering = $ordering ? $ordering + 1 : count($files) + 1; // put in the end $row->filename = $file['name']; $row->resourceid = $pid; // Check content if (!$row->check()) { $this->setError($row->getError()); $this->displayTask($pid, $version); return; } // Build the path include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php'; $listdir = \Components\Resources\Helpers\Html::build_path($resource->created, $pid, ''); $listdir .= DS . $vid; $path = $this->_buildUploadPath($listdir, ''); // Make sure the upload path exist if (!is_dir($path)) { if (!Filesystem::makeDirectory($path)) { $this->setError(Lang::txt('COM_TOOLS_UNABLE_TO_CREATE_UPLOAD_PATH') . $path); $this->displayTask($pid, $version); return; } } // Perform the upload if (!\Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) { $this->setError(Lang::txt('COM_TOOLS_ERROR_UPLOADING')); } else { // Store new content if (!$row->store()) { $this->setError($row->getError()); $this->displayTask($pid, $version); return; } if (!$row->id) { $row->id = $row->insertid(); } // Create thumbnail $ss_height = intval($this->config->get('screenshot_maxheight', 58)) > 30 ? intval($this->config->get('screenshot_maxheight', 58)) : 58; $ss_width = intval($this->config->get('screenshot_maxwidth', 91)) > 80 ? intval($this->config->get('screenshot_maxwidth', 91)) : 91; $tn = \Components\Resources\Helpers\Html::thumbnail($file['name']); if ($file_ext != '.swf') { $this->_createThumb($path . DS . $file['name'], $ss_width, $ss_height, $path, $tn); } else { //$this->_createAnimThumb($path . DS . $file['name'], $ss_width, $ss_height, $path, $tn); } } // Store new content if (!$row->store()) { $this->setError($row->getError()); $this->displayTask($pid, $version); return; } $this->_rid = $pid; // Push through to the screenshot view $this->displayTask($pid, $version); }
/** * Save a list of authors * * @param array $authors List of authors to add * @param string $version Tool version * @param integer $rid Resource ID * @param integer $revision Revision number * @param string $toolname Tool name * @return boolean False if errors, True if not */ public function saveAuthors($authors, $version = 'dev', $rid = 0, $revision = 0, $toolname = '') { if (!$rid) { return false; } if ($authors) { $authors = Utils::transform($authors, 'uidNumber'); } $dev_authors = $this->getToolAuthors('dev', $rid); $dev_authors = Utils::transform($dev_authors, 'uidNumber'); if ($dev_authors && $version == 'dev') { // update $to_delete = array_diff($current_authors, $authors); if ($to_delete) { foreach ($to_delete as $del) { $query = "DELETE FROM #__author_assoc WHERE authorid=" . $this->_db->quote($del) . " AND subid=" . $this->_db->quote($rid) . " AND subtable='resources'"; $this->_db->setQuery($query); $this->_db->query(); } } } // add new authors if ($version == 'dev') { // development version is updated $to_delete = array_diff($dev_authors, $authors); $rc = new \Components\Resources\Tables\Contributor($this->_db); $rc->subtable = 'resources'; $rc->subid = $rid; if ($to_delete) { foreach ($to_delete as $del) { $query = "DELETE FROM #__author_assoc WHERE authorid=" . $this->_db->quote($del) . " AND subid=" . $this->_db->quote($rid) . " AND subtable='resources'"; $this->_db->setQuery($query); $this->_db->query(); } } // Get the last child in the ordering $order = $rc->getLastOrder($rid, 'resources'); $order = $order + 1; // new items are always last foreach ($authors as $authid) { // Check if they're already linked to this resource $rc->loadAssociation($authid, $rid, 'resources'); if (!$rc->authorid) { $xprofile = User::getInstance($authid); // New record $rc->authorid = $authid; $rc->ordering = $order; $rc->name = addslashes($xprofile->get('name')); $rc->organization = addslashes($xprofile->get('organization')); $rc->createAssociation(); $order++; } } } else { if ($dev_authors) { // new version is being published, transfer data from author_assoc $i = 0; foreach ($dev_authors as $authid) { $name = ''; $organization = ''; // Check the author_assoc table first, as that's what gets updated when you edit the tool info $query = "SELECT name, organization FROM `#__author_assoc` "; $query .= "WHERE subid= " . $this->_db->quote($rid); $query .= " AND authorid=" . $this->_db->quote($authid); $query .= " AND subtable='resources'"; $this->_db->setQuery($query); $author = $this->_db->loadObject(); if ($author) { $name = $author->name; $organization = $author->organization; } if (!$name || !$organization) { // Do we have name/org info in previous version? $query = "SELECT name, organization FROM #__tool_authors "; $query .= "WHERE toolname=" . $this->_db->quote($toolname) . " AND uid=" . $this->_db->quote($authid) . " AND revision < " . $this->_db->quote($revision); $query .= " AND name IS NOT NULL AND organization IS NOT NULL "; $query .= " ORDER BY revision DESC LIMIT 1"; $this->_db->setQuery($query); $info = $this->_db->loadObjectList(); if ($info) { $name = $name ?: $info[0]->name; $organization = $organization ?: $info[0]->organization; } // If we still don't have it, try to grab it from the profile if (!$name || !$organization) { $xprofile = User::getInstance($authid); $name = $name ?: $xprofile->get('name'); $organization = $organization ?: $xprofile->get('organization'); } } $query = "INSERT INTO {$this->_tbl} (toolname, revision, uid, ordering, version_id, name, organization) VALUES ('" . $toolname . "','" . $revision . "','" . $authid . "','" . $i . "', '" . $version . "', '" . addslashes($name) . "', '" . addslashes($organization) . "')"; $this->_db->setQuery($query); if (!$this->_db->query()) { return false; } $i++; } } } return true; }
/** * Send an email to one or more users * * @param string $toolid Tool ID * @param string $summary Message subject * @param string $comment Message * @param unknown $access Parameter description (if any) ... * @param string $action Parameter description (if any) ... * @param array $toolinfo Array of tool information * @return void */ protected function _email($toolid, $summary, $comment, $access, $action, $toolinfo = array()) { $headline = ''; // Get tool information $obj = new \Components\Tools\Tables\Tool($this->database); $obj->getToolStatus($toolid, $this->_option, $status, 'dev'); if (empty($status) && !empty($toolinfo)) { $status = $toolinfo; } // Get team $team = \Components\Tools\Helpers\Utils::transform($status['developers'], 'uidNumber'); // Get admins $admins = array(); if ($this->config->get('access-admin-component')) { $admins[] = User::get('username'); } $admingroup = $this->config->get('admingroup', ''); $group = \Hubzero\User\Group::getInstance($admingroup); if (is_object($group)) { $members = $group->get('members'); $managers = $group->get('managers'); $members = array_merge($members, $managers); if ($members) { foreach ($members as $member) { $muser = User::getInstance($member); if (is_object($muser)) { $admins[] = $member; } } } } $inteam = in_array(User::get('id'), $team) ? 1 : 0; // collector for those who need to get notified $users = array(); switch ($action) { case 1: $action = 'contribtool_info_changed'; $headline = Lang::txt('COM_TOOLS_INFORMATION_CHANGED'); //$users = $team; break; case 2: $action = 'contribtool_status_changed'; $headline = $summary; //$users = $this->config->get('access-admin-component') ? $team : $admins; //if (!$inteam) //{ //$users[] = User::get('id'); // cc person who made the change if not in team //} break; case 3: $action = 'contribtool_new_message'; $headline = Lang::txt('COM_TOOLS_new message'); //$users = $this->config->get('access-admin-component') && $access != 1 ? $team : $admins; break; case 4: $action = 'contribtool_status_changed'; $headline = Lang::txt('COM_TOOLS_NEW_REGISTRATION'); //$users = array_merge($team, $admins); break; case 5: $action = 'contribtool_status_changed'; $headline = Lang::txt('COM_TOOLS_REGISTRATION_CANCELLED'); //$users = array_merge($team, $admins); break; } // send messages to everyone $users = array_merge($team, $admins); // make sure we are not mailing twice $users = array_unique($users); // Build e-mail components $subject = Lang::txt(strtoupper($this->_option)) . ', ' . Lang::txt('COM_TOOLS_TOOL') . ' ' . $status['toolname'] . '(#' . $toolid . '): ' . $headline; $from = Config::get('sitename') . ' ' . Lang::txt('COM_TOOLS_CONTRIBTOOL'); $hub = array('email' => Config::get('mailfrom'), 'name' => $from); $live_site = rtrim(Request::base(), '/'); // Compose Message $message = strtoupper(Lang::txt('COM_TOOLS_TOOL')) . ': ' . $status['title'] . ' (' . $status['toolname'] . ')' . "\r\n"; $message .= strtoupper(Lang::txt('COM_TOOLS_SUMMARY')) . ': ' . $summary . "\r\n"; $message .= strtoupper(Lang::txt('COM_TOOLS_WHEN')) . ' ' . Date::of(Date::toSql())->toLocal(Lang::txt('DATE_FORMAT_HZ1')) . "\r\n"; $message .= strtoupper(Lang::txt('COM_TOOLS_BY')) . ': ' . User::get('username') . "\r\n"; $message .= '----------------------------' . "\r\n\r\n"; if ($comment) { $message .= strtoupper(Lang::txt('COM_TOOLS_MESSAGE')) . ': ' . "\r\n"; $message .= $comment . "\r\n"; $message .= '----------------------------' . "\r\n\r\n"; } $message .= Lang::txt('COM_TOOLS_TIP_URL_TO_STATUS') . "\r\n"; $message .= $live_site . Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=status&app=' . $status['toolname']) . "\r\n"; // fire off message if ($summary or $comment) { if (!Event::trigger('xmessage.onSendMessage', array($action, $subject, $message, $hub, $users, $this->_option))) { Notify::error(Lang::txt('COM_TOOLS_FAILED_TO_MESSAGE')); } } }
/** * Short description for 'saveMemberGroups' * * Long description (if any) ... * * @param string $toolid Parameter description (if any) ... * @param array $newgroups Parameter description (if any) ... * @param string $editversion Parameter description (if any) ... * @param array $membergroups Parameter description (if any) ... * @return boolean Return description (if any) ... */ public function saveMemberGroups($toolid = NULL, $newgroups, $editversion = 'dev', $membergroups = array()) { if (!$toolid) { return false; } require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'models' . DS . 'tool.php'; $membergroups = \Components\Tools\Models\Tool::getToolGroups($toolid); $membergroups = \Components\Tools\Helpers\Utils::transform($membergroups, 'cn'); $newgroups = \Components\Tools\Helpers\Utils::transform($newgroups, 'cn'); $to_delete = array_diff($membergroups, $newgroups); if (count($to_delete) > 0 && $editversion != 'current') { foreach ($to_delete as $del) { $query = "DELETE FROM {$this->_tbl} WHERE cn=" . $this->_db->quote($del) . " AND toolid=" . $this->_db->quote($toolid) . " AND role=0"; $this->_db->setQuery($query); $this->_db->query(); } } if (count($newgroups) > 0) { foreach ($newgroups as $newgroup) { if (\Hubzero\User\Group::exists($newgroup) && !in_array($newgroup, $membergroups)) { // create an entry in tool_groups table $this->save($newgroup, $toolid, '0'); } } } return true; }