26 const NAME =
'upload_url';
28 const NAME_PARAM =
'name';
29 const ACCEPT_PARAM =
'accept';
30 const REJECT_PARAM =
'reject';
31 const GETURL_PARAM =
'geturl';
32 const LEVEL_PARAM =
'level';
34 public function __construct()
36 parent::__construct(self::NAME, array(
37 self::TITLE => _(
"Upload from URL"),
38 self::MENU_LIST =>
"Upload::From URL",
39 self::DEPENDENCIES => array(
"agent_unpack",
"showjobs"),
44 protected function handleUpload(Request $request)
46 $folderId = intval($request->get(self::FOLDER_PARAMETER_NAME));
47 $description = stripslashes($request->get(self::DESCRIPTION_INPUT_NAME));
48 $description = $this->basicShEscaping($description);
50 $getUrlThatMightIncludeSpaces =
trim($request->get(self::GETURL_PARAM));
51 $getURL = str_replace(
" ",
"%20", $getUrlThatMightIncludeSpaces);
54 return array(
false, _(
"Invalid URL"), $description);
56 if (preg_match(
"@^((http)|(https)|(ftp))://([[:alnum:]]+)@i", $getURL) != 1) {
57 return array(
false, _(
"Invalid URL"), $description);
59 $getURL = $this->basicShEscaping($getURL);
61 $name = $request->get(self::NAME_PARAM);
63 $name = basename($getURL);
65 $shortName = basename($name);
66 if (empty($shortName)) {
74 $public = $request->get(
'public');
77 $uploadId =
JobAddUpload($userId, $groupId, $shortName, $getURL, $description, $mode, $folderId, $publicPermission);
78 if (empty($uploadId)) {
79 $text = _(
"Failed to insert upload record");
80 return array(
false, $text, $description);
83 $level = intval($request->get(self::LEVEL_PARAM));
89 $accept = preg_replace(
'/\s*,\s*/',
',',
trim($request->get(self::ACCEPT_PARAM)));
90 $accept = $this->basicShEscaping($accept);
91 $reject = preg_replace(
'/\s*,\s*/',
',',
trim($request->get(self::REJECT_PARAM)));
92 $reject = $this->basicShEscaping($reject);
95 $jobId = JobAddJob($userId, $groupId,
"wget", $uploadId);
96 if (empty($jobId) || ($jobId < 0)) {
97 return array(
false, _(
"Failed to insert job record"), $description);
100 $jqArgs =
"$uploadId - $getURL -l $level ";
101 if (! empty($accept)) {
102 $jqArgs .=
"-A $accept ";
104 $jqArgs .= empty($reject) ?
"-R index.html* " :
"-R $reject,index.html* ";
106 $jobqueueId =
JobQueueAdd($jobId,
"wget_agent", $jqArgs, NULL, NULL);
107 if (empty($jobqueueId)) {
109 "Failed to insert task 'wget_agent' into job queue", $description);
112 $message = $this->postUploadAddJobs($request, $shortName, $uploadId, $jobId,
true);
113 return array(
true, $message, $description, $uploadId);
116 protected function handleView(Request $request, $vars)
118 $vars[
'geturlField'] = self::GETURL_PARAM;
119 $vars[
'nameField'] = self::NAME_PARAM;
120 $vars[
'acceptField'] = self::ACCEPT_PARAM;
121 $vars[
'rejectField'] = self::REJECT_PARAM;
122 $vars[
'levelField'] = self::LEVEL_PARAM;
123 return $this->
render(
"upload_url.html.twig", $this->mergeWithDefault($vars));
static getUserId()
Get the current user's id.
render($templateName, $vars=null, $headers=null)
JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host=NULL, $jq_cmd_args=NULL)
Insert a jobqueue + jobdepends records.
static getGroupId()
Get the current user's group id.
JobAddUpload($userId, $groupId, $job_name, $filename, $desc, $UploadMode, $folder_pk, $public_perm=Auth::PERM_NONE)
Insert a new upload record, and update the foldercontents table.
char * trim(char *ptext)
Trimming whitespace.