Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Wpct ERP Forms
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
codeccoop
WordPress
plugins
Wpct ERP Forms
Commits
1142fc36
Commit
1142fc36
authored
1 year ago
by
Lucas García
Browse files
Options
Downloads
Patches
Plain Diff
feat: attachments module
parent
33c0fd6b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
includes/attachments.php
+65
-0
65 additions, 0 deletions
includes/attachments.php
includes/submissions.php
+1
-63
1 addition, 63 deletions
includes/submissions.php
wpct-crm-forms.php
+1
-0
1 addition, 0 deletions
wpct-crm-forms.php
with
67 additions
and
63 deletions
includes/attachments.php
0 → 100644
+
65
−
0
View file @
1142fc36
<?php
/**
* Store uploads on a custom folder under a custom endpoint
*/
add_filter
(
'gform_upload_path'
,
'wpct_crm_forms_upload_path'
,
90
,
2
);
function
wpct_crm_forms_upload_path
(
$path_info
,
$form_id
)
{
$upload_dir
=
wp_upload_dir
();
$base_path
=
apply_filters
(
'wpct_crm_forms_upload_path'
,
$upload_dir
[
'basedir'
]
.
'/crm-forms'
);
if
(
!
(
$base_path
&&
is_string
(
$base_path
)))
throw
new
Exception
(
'WPCT CRM Forms: Invalid upload path'
);
$base_path
=
preg_replace
(
'/\/$/'
,
''
,
$base_path
);
$path
=
$base_path
.
'/'
.
implode
(
'/'
,
[
$form_id
,
date
(
'Y'
),
date
(
'm'
)]);
if
(
!
is_dir
(
$path
))
mkdir
(
$path
,
0700
,
true
);
$path_info
[
'path'
]
=
$path
;
$url
=
get_site_url
()
.
'/index.php?'
;
$url
.
=
'crm-forms-attachment='
.
urlencode
(
str_replace
(
$base_path
,
''
,
$path
)
.
'/'
);
$path_info
[
'url'
]
=
$url
;
return
$path_info
;
};
/*
* Attachments delivery handler
*/
add_action
(
'init'
,
'wpct_crm_forms_download_file'
);
function
wpct_crm_forms_download_file
()
{
if
(
!
isset
(
$_GET
[
'crm-forms-attachment'
]))
return
;
$upload_dir
=
wp_upload_dir
();
$base_path
=
apply_filters
(
'wpct_crm_forms_upload_path'
,
$upload_dir
[
'basedir'
]
.
'/crm-forms'
);
if
(
!
(
$base_path
&&
is_string
(
$base_path
)))
throw
new
Exception
(
'WPCT CRM Forms: Invalid upload path'
);
$base_path
=
preg_replace
(
'/\/$/'
,
''
,
$base_path
);
$path
=
$base_path
.
urldecode
(
$_GET
[
'crm-forms-attachment'
]);
if
(
!
(
is_user_logged_in
()
&&
file_exists
(
$path
)))
{
global
$wp_query
;
status_header
(
404
);
$wp_query
->
set_404
();
$template_path
=
get_404_template
();
if
(
file_exists
(
$template_path
))
require_once
(
$template_path
);
die
();
}
$filetype
=
wp_check_filetype
(
$path
);
if
(
!
$filetype
[
'type'
])
{
$filetype
[
'type'
]
=
mime_content_type
(
$path
);
}
nocache_headers
();
header
(
'X-Robots-Tag: noindex'
,
true
);
header
(
'Content-Type: '
.
$filetype
[
'type'
]);
header
(
'Content-Description: File Transfer'
);
header
(
'Content-Disposition: inline; filename="'
.
wp_basename
(
$path
)
.
'"'
);
header
(
'Content-Transfer-Encoding: binary'
);
header
(
'Content-Length: '
.
filesize
(
$path
));
if
(
ob_get_contents
())
ob_end_clean
();
readfile
(
$path
);
die
();
}
This diff is collapsed.
Click to expand it.
includes/submissions.php
+
1
−
63
View file @
1142fc36
...
...
@@ -57,7 +57,7 @@ function wpct_crm_forms_parse_form_entry($entry, $form)
function
wpct_crm_forms_format_value
(
$value
,
$field
,
$input
=
null
)
{
if
(
$field
->
type
===
'fileupload'
)
{
if
(
!
is_array
(
$field
->
get_entry_inputs
()))
return
json_decode
(
$value
)
[
0
]
;
return
implode
(
','
,
json_decode
(
$value
)
)
;
}
return
$value
;
...
...
@@ -126,65 +126,3 @@ function wpct_crm_forms_prepare_submission($form_vals)
$form_vals
=
wpct_crm_forms_cleanup_empties
(
$form_vals
);
return
wpct_crm_forms_get_submission_payload
(
$form_vals
);
}
/**
* Store uploads on a custom folder
*/
add_filter
(
'gform_upload_path'
,
'wpct_crm_forms_upload_path'
,
90
,
2
);
function
wpct_crm_forms_upload_path
(
$path_info
,
$form_id
)
{
$upload_dir
=
wp_upload_dir
();
$base_path
=
apply_filters
(
'wpct_crm_forms_upload_path'
,
$upload_dir
[
'basedir'
]
.
'/crm-forms'
);
if
(
!
(
$base_path
&&
is_string
(
$base_path
)))
throw
new
Exception
(
'WPCT CRM Forms: Invalid upload path'
);
$base_path
=
preg_replace
(
'/\/$/'
,
''
,
$base_path
);
$path
=
$base_path
.
'/'
.
implode
(
'/'
,
[
$form_id
,
date
(
'Y'
),
date
(
'm'
)]);
if
(
!
is_dir
(
$path
))
mkdir
(
$path
,
0700
,
true
);
$path_info
[
'path'
]
=
$path
;
$url
=
get_site_url
()
.
'/index.php?'
;
$url
.
=
'crm-forms-attachment='
.
urlencode
(
str_replace
(
$base_path
,
''
,
$path
)
.
'/'
);
$path_info
[
'url'
]
=
$url
;
return
$path_info
;
};
add_action
(
'init'
,
'wpct_crm_forms_download_file'
);
function
wpct_crm_forms_download_file
()
{
if
(
!
isset
(
$_GET
[
'crm-forms-attachment'
]))
return
;
$upload_dir
=
wp_upload_dir
();
$base_path
=
apply_filters
(
'wpct_crm_forms_upload_path'
,
$upload_dir
[
'basedir'
]
.
'/crm-forms'
);
if
(
!
(
$base_path
&&
is_string
(
$base_path
)))
throw
new
Exception
(
'WPCT CRM Forms: Invalid upload path'
);
$base_path
=
preg_replace
(
'/\/$/'
,
''
,
$base_path
);
$path
=
$base_path
.
urldecode
(
$_GET
[
'crm-forms-attachment'
]);
if
(
!
(
is_user_logged_in
()
&&
file_exists
(
$path
)))
{
global
$wp_query
;
status_header
(
404
);
$wp_query
->
set_404
();
$template_path
=
get_404_template
();
if
(
file_exists
(
$template_path
))
require_once
(
$template_path
);
die
();
}
$filetype
=
wp_check_filetype
(
$path
);
if
(
!
$filetype
[
'type'
])
{
$filetype
[
'type'
]
=
mime_content_type
(
$path
);
}
nocache_headers
();
header
(
'X-Robots-Tag: noindex'
,
true
);
header
(
'Content-Type: '
.
$filetype
[
'type'
]);
header
(
'Content-Description: File Transfer'
);
header
(
'Content-Disposition: inline; filename="'
.
wp_basename
(
$path
)
.
'"'
);
header
(
'Content-Transfer-Encoding: binary'
);
header
(
'Content-Length: '
.
filesize
(
$path
));
if
(
ob_get_contents
())
ob_end_clean
();
readfile
(
$path
);
die
();
}
This diff is collapsed.
Click to expand it.
wpct-crm-forms.php
+
1
−
0
View file @
1142fc36
...
...
@@ -19,6 +19,7 @@ require_once "includes/options-page.php";
/* Webhooks */
require_once
"includes/webhooks.php"
;
require_once
"includes/submissions.php"
;
require_once
"includes/attachments.php"
;
/* Fields population */
require_once
"includes/fields-population.php"
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment