/** * Generate a resource page from tool data * * @param integer $toolid Tool ID * @param array $tool Tool info to generate resource from * @return mixed False if error, integer if success */ public function createPage($toolid, $tool) { $tool['title'] = preg_replace('/\\s+/', ' ', $tool['title']); $params = array(); $params[] = 'pageclass_sfx='; $params[] = 'show_title=1'; $params[] = 'show_authors=1'; $params[] = 'show_assocs=1'; $params[] = 'show_type=1'; $params[] = 'show_logicaltype=1'; $params[] = 'show_rating=1'; $params[] = 'show_date=1'; $params[] = 'show_parents=1'; $params[] = 'series_banner='; $params[] = 'show_banner=1'; $params[] = 'show_footer=3'; $params[] = 'show_stats=0'; $params[] = 'st_appname=' . strtolower($tool['toolname']); $params[] = 'st_appcaption=' . $tool['title'] . $tool['version']; $params[] = 'st_method=com_narwhal'; // Initiate extended database class $row = new \Components\Resources\Tables\Resource($this->database); $row->created_by = User::get('id'); $row->created = Date::toSql(); $row->published = 2; // draft state $row->params = implode("\n", $params); $row->attribs = 'marknew=0'; $row->standalone = 1; $row->type = 7; $row->title = $tool['title']; $row->introtext = $tool['description']; $row->alias = $tool['toolname']; $row->access = 0; if (!$row->store()) { $this->setError($row->getError()); return false; } return $row->id; }
/** * Save an attachment * * @return void */ public function saveTask() { // Incoming $pid = Request::getInt('pid', 0); if (!$pid) { $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID')); $this->displayTask($pid); return; } // get tool object $obj = new \Components\Tools\Tables\Tool($this->database); $this->_toolid = $obj->getToolIdFromResource($pid); // make sure user is authorized to go further if (!$this->_checkAccess($this->_toolid)) { App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH')); return; } // Incoming file $file = Request::getVar('upload', '', 'files', 'array'); if (!$file['name']) { $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_FILE')); $this->displayTask($pid); return; } // Make the filename safe $file['name'] = Filesystem::clean($file['name']); // Ensure file names fit. $ext = Filesystem::extension($file['name']); $file['name'] = str_replace(' ', '_', $file['name']); if (strlen($file['name']) > 230) { $file['name'] = substr($file['name'], 0, 230); $file['name'] .= '.' . $ext; } // Instantiate a new resource object $row = new \Components\Resources\Tables\Resource($this->database); if (!$row->bind($_POST)) { $this->setError($row->getError()); $this->displayTask($pid); return; } $row->title = $row->title ? $row->title : $file['name']; $row->introtext = $row->title; $row->created = Date::toSql(); $row->created_by = User::get('id'); $row->published = 1; $row->publish_up = Date::toSql(); $row->publish_down = '0000-00-00 00:00:00'; $row->standalone = 0; $row->access = 0; $row->path = ''; // make sure no path is specified just yet // Check content if (!$row->check()) { $this->setError($row->getError()); $this->displayTask($pid); return; } // Store new content if (!$row->store()) { $this->setError($row->getError()); $this->displayTask($pid); return; } if (!$row->id) { $row->id = $row->insertid(); } // Build the path include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php'; $listdir = \Components\Resources\Tables\Html::build_path($row->created, $row->id, ''); $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')); $this->displayTask($pid); return; } } // Perform the upload if (!Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) { $this->setError(Lang::txt('COM_TOOLS_ERROR_UPLOADING')); } else { // File was uploaded // Check the file type $row->type = $this->_getChildType($file['name']); } if (!$row->path) { $row->path = $listdir . DS . $file['name']; } if (substr($row->path, 0, 1) == DS) { $row->path = substr($row->path, 1, strlen($row->path)); } // Store new content if (!$row->store()) { $this->setError($row->getError()); $this->displayTask($pid); return; } // Instantiate a Resources Assoc object $assoc = new \Components\Resources\Tables\Assoc($this->database); // Get the last child in the ordering $order = $assoc->getLastOrder($pid); $order = $order ? $order : 0; // Increase the ordering - new items are always last $order = $order + 1; // Create new parent/child association $assoc->parent_id = $pid; $assoc->child_id = $row->id; $assoc->ordering = $order; $assoc->grouping = 0; if (!$assoc->check()) { $this->setError($assoc->getError()); } if (!$assoc->store(true)) { $this->setError($assoc->getError()); } $this->_rid = $pid; // Push through to the attachments view $this->displayTask($pid); }
/** * Removes an item reported as abusive * * @param integer $referenceid ID of the database table row * @param integer $parentid If the element has a parent element * @param string $category Element type (determines table to look in) * @param string $message Message to user to append to * @return string */ public function deleteReportedItem($referenceid, $parentid, $category, $message) { if (!$this->_canHandle($category)) { return null; } $this->loadLanguage(); $database = App::get('db'); switch ($category) { case 'review': include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'resource.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'review.php'; // Delete the review $review = new \Components\Resources\Tables\Review($database); $review->load($referenceid); $review->state = 2; $review->store(); // Recalculate the average rating for the parent resource $resource = new \Components\Resources\Tables\Resource($database); $resource->load($parentid); $resource->calculateRating(); if (!$resource->store()) { $this->setError($resource->getError()); return false; } $message .= Lang::txt('PLG_SUPPORT_RESOURCES_NOTIFICATION_OF_REMOVAL', $parentid); break; case 'reviewcomment': $comment = \Hubzero\Item\Comment::oneOrFail($referenceid); $comment->set('state', $comment::STATE_DELETED); if (!$comment->save()) { $this->setError($comment->getError()); return false; } $message .= Lang::txt('PLG_SUPPORT_RESOURCES_NOTIFICATION_OF_REMOVAL', $parentid); break; } return $message; }