/** * Processes the uploaded files in the request. Most of the legwork is handled in {@link KickAssetUtil} * * @return SS_HTTPResponse */ public function upload(SS_HTTPRequest $r) { // We don't want anyone uploading to the root assets folder.. if (!$this->defaultFolder) { $this->defaultFolder = Folder::findOrMake("Uploads"); } $response = KickAssetUtil::handle_upload($r, $this->defaultFolder); if (empty($response)) { return new SS_HTTPResponse("File did not upload", 500); } if (is_array($response)) { return new SS_HTTPResponse(implode(',', $response), 200); } return new SS_HTTPResponse("Error: " . $response, 500); }
/** * Adds some metadata to a {@link File} object that is used by the view. This function * allows us to avoid having to use a decorator on the {@link File} class. * * @param File * @return array */ protected function getFields(File $f) { if ($f instanceof Folder) { return array('Link' => $this->Link($this->getBrowseAction() . '/' . $f->ID), 'Item' => $f); } $image = $f instanceof Image; $tooltipurl = ""; if ($image) { if ($f->getHeight() > 64 || $f->getWidth() > 64) { if ($f->getOrientation() == Image::ORIENTATION_SQUARE || $f->getOrientation() == Image::ORIENTATION_LANDSCAPE) { $tooltipurl = $f->getWidth() > self::$tooltip_size ? $f->SetWidth(self::$tooltip_size)->getURL() : $f->getURL(); } else { $tooltipurl = $f->getHeight() > self::$tooltip_size ? $f->setHeight(self::$tooltip_size)->getURL() : $f->getURL(); } } } return array('Link' => '', 'Item' => $f, 'IconURL' => $image ? ($i = $f->SetHeight(64)) ? $i->getURL() : KickAssetUtil::get_icon($f) : KickAssetUtil::get_icon($f), 'Image' => $image, 'TooltipURL' => $tooltipurl); }