Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
- show .scad OpenSCAD files in the preview pane, as they are text/plain.
Browse files Browse the repository at this point in the history
- fix issue displaying quotes in properties dialog.
- remove support for numbered file names.
  • Loading branch information
Barry de Graaff committed Mar 28, 2019
1 parent d12e37d commit 66f2e17
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 84 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ Please note that a preference set by the user has priority over a preference set
| owncloud_zimlet_extra_toolbar_button_url | owncloud_zimlet_oc_folder | URL to open when `Go to Nextcloud` is clicked. Instead of a URL you can set it to `owncloud_zimlet_server_name` it opens the URL set in owncloud_zimlet_server_name (may be set by user). When set to `owncloud_zimlet_oc_folder` it opens the URL set in owncloud_zimlet_server_name combined with owncloud_zimlet_oc_folder (maybe set by user). See: owncloud_zimlet_extra_toolbar_button_title | |
| owncloud_zimlet_app_title | WebDAV | Change this if you want to rebrand WebDAV Client for your users. For example: ownCloud. | |
| owncloud_zimlet_max_upload_size | 104857600 (100MB) | Maximum upload size for upload dialog MB * 1024 * 1024. The back-end has a hardcoded maximum of 1048576000 (1GB). | |
| owncloud_zimlet_use_numbers | false | If set to true, a number will be used instead of filename when saving attachments. | |
| file_number | 1000000 | The number to start counting from. See owncloud_zimlet_use_numbers. | |
| owncloud_zimlet_disable_ocs_public_link_shares | false | Controls if users can share items with a public link. Set this to true if you use a DAV server that is not ownCloud/Nextcloud or if you want to disable public link sharing. | |
| owncloud_zimlet_welcome_url | https://barrydegraaff.github.io/owncloud/ | Page to load in the preview window when then the tab is clicked. | |
| owncloud_zimlet_accountname_with_domain | false | When false the username field in settings dialog is set to `username`, when true it is set to `[email protected]` | |
Expand Down
38 changes: 1 addition & 37 deletions extension/src/com/zextras/dav/UploadHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void doPost(
}

//to-do implement proper encoding and better sanitizing (allow more characters)
String fileNameString = getFileName(item.getName().replaceAll("\\\\|\\/|\\:|\\*|\\?|\\\"|\\<|\\>|\\||\\%|\\&|\\@|\\!|\\'|\\[|\\]", "").replace(" ", "%20"), userProperties.get(ZimletProperty.USE_NUMBERS));
String fileNameString = item.getName().replaceAll("\\\\|\\/|\\:|\\*|\\?|\\\"|\\<|\\>|\\||\\%|\\&|\\@|\\!|\\'|\\[|\\]", "").replace(" ", "%20");

fileNames.add(fileNameString);

Expand Down Expand Up @@ -253,42 +253,6 @@ private String uriDecode(String dirty) {
}
}

private String getFileName(String filename, String numberedFilenames) {
try {
FileInputStream input = new FileInputStream("/opt/zimbra/lib/ext/ownCloud/config.properties");
Properties prop = new Properties();
prop.load(input);
input.close();
String fileNumberStr = prop.getProperty("file_number");


if ("true".equals(numberedFilenames)) {
int fileNumber = Integer.parseInt(fileNumberStr);

fileNumber = fileNumber + 1;

FileOutputStream out = new FileOutputStream("/opt/zimbra/lib/ext/ownCloud/config.properties");
prop.setProperty("file_number", Integer.toString(fileNumber));
prop.store(out, "Updated file_number via getFileName.");
out.close();


if (filename.lastIndexOf(".") > -1) {
filename = fileNumberStr + filename.substring(filename.lastIndexOf("."));
} else {
filename = fileNumberStr;
}

}
return filename;

} catch (IOException ex) {
ex.printStackTrace();

return filename;
}
}

@Override
public void doOptions(
HttpServletRequest httpServletRequest,
Expand Down
1 change: 0 additions & 1 deletion extension/src/com/zextras/dav/ZimletProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class ZimletProperty
public static String DAV_SERVER_NAME = "owncloud_zimlet_server_name";
public static String DAV_SERVER_PORT = "owncloud_zimlet_server_port";
public static String DAV_SERVER_PATH = "owncloud_zimlet_server_path";
public static String USE_NUMBERS = "owncloud_zimlet_use_numbers";

public static String OC_PATH = "owncloud_zimlet_oc_folder";
}
2 changes: 0 additions & 2 deletions webdav-client-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ owncloud_zimlet_extra_toolbar_button_title=Go to Nextcloud
owncloud_zimlet_extra_toolbar_button_url=owncloud_zimlet_oc_folder
owncloud_zimlet_app_title=WebDAV
owncloud_zimlet_max_upload_size=104857600
owncloud_zimlet_use_numbers=false
file_number=1000000
owncloud_zimlet_welcome_url=${OWNCLOUD_DOC_URL}
owncloud_zimlet_accountname_with_domain=false
owncloud_zimlet_disable_auto_upload_on_exceed=false
Expand Down
17 changes: 11 additions & 6 deletions zimlet/OwnCloudListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,17 +598,17 @@ OwnCloudListView.prototype._onItemSelected = function(ev) {
zimletInstance.onlyOfficeToken = dav_download_options[1];
if(dav_download_options[0] == 'true')
{
var regex = /\.pdf$|\.odt$|\.ods$|\.odp$|\.mp4$|\.webm$|\.jpg$|\.jpeg$|\.png$|\.txt$|\.md$|\.doc$|\.docx$|\.xls$|\.xlsx$|\.ppt$|\.pptx$|\.djvu$/i;
var regex = /\.pdf$|\.odt$|\.ods$|\.odp$|\.mp4$|\.webm$|\.jpg$|\.jpeg$|\.png$|\.txt$|\.scad$|\.md$|\.doc$|\.docx$|\.xls$|\.xlsx$|\.ppt$|\.pptx$|\.djvu$/i;
}
else
{
if(zimletInstance._zimletContext.getConfig("owncloud_zimlet_onlyoffice_api_url"))
{
var regex = /\.pdf$|\.mp4$|\.webm$|\.jpg$|\.jpeg$|\.png$|\.txt$|\.md$|\.docx$|\.xlsx$|\.pptx$/i;
var regex = /\.pdf$|\.mp4$|\.webm$|\.jpg$|\.jpeg$|\.png$|\.txt$|\.scad$|\.md$|\.docx$|\.xlsx$|\.pptx$/i;
}
else
{
var regex = /\.pdf$|\.mp4$|\.webm$|\.jpg$|\.jpeg$|\.png$|\.txt$|\.md$/i;
var regex = /\.pdf$|\.mp4$|\.webm$|\.jpg$|\.jpeg$|\.png$|\.txt$|\.scad$|\.md$/i;
}
}
if(!item.isDirectory() && davResource._href.match(regex))
Expand Down Expand Up @@ -667,6 +667,9 @@ OwnCloudListView.prototype.preview = function(davResource, token) {
case (davResource._href.match(/\.txt$/i) || {}).input:
contentType = 'text/plain';
break;
case (davResource._href.match(/\.scad$/i) || {}).input:
contentType = 'text/plain';
break;
case (davResource._href.match(/\.md$/i) || {}).input:
contentType = 'text/plain';
break;
Expand Down Expand Up @@ -860,7 +863,7 @@ OwnCloudListView.prototype.preview = function(davResource, token) {
//see also function OwnCloudApp
document.getElementById('WebDAVPreviewContainer').innerHTML='<iframe id="WebDAVPreview" src="" style="width:'+(zimletInstance.appWidth/2+zimletInstance.appWidthCorrection)+'px; height:'+ zimletInstance.appHeight +'px; border:0px">';

if(davResource._href.match(/\.txt$/i))
if(davResource._href.match(/\.txt$|\.scad$/i))
{
document.getElementById('WebDAVPreview').src=href;
}
Expand Down Expand Up @@ -938,8 +941,9 @@ OwnCloudListView.prototype._itemPropertiesListener = function(ev) {

var content = "<table>";
var location = "/"+(davResource.getHref()).replace(tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_server_path'], "");
content += "<tr><td style='width:100px'>"+ ZmMsg.path + ": </td><td style='width:550px;'><input id='props_owncloud_zimlet_server_path' readonly style='width:98%;color:black;border:0;' value='"+location+"'></td></tr>";
content += "<tr><td style='width:100px'>"+ ZmMsg.type + ": </td><td style='width:550px;'><input readonly style='width:98%;color:black;border:0;' value='"+davResource.getContentType()+"'></td></tr>";

content += "<tr><td style='width:100px'>"+ ZmMsg.path + ": </td><td style='width:550px;'><input id='props_owncloud_zimlet_server_path' readonly style='width:98%;color:black;border:0;'></td></tr>";
content += "<tr><td style='width:100px'>"+ ZmMsg.type + ": </td><td style='width:550px;'><input readonly style='width:98%;color:black;border:0;' value='"+davResource.getContentType()+"'></td></tr>";
if(!davResource.isDirectory())
{
content += "<tr><td style='width:100px'>"+ ZmMsg.size + ": </td><td style='width:550px;'><input readonly style='width:98%;color:black;border:0;' value='"+AjxUtil.formatSize(davResource.getContentLength())+"'></td></tr>";
Expand All @@ -949,6 +953,7 @@ OwnCloudListView.prototype._itemPropertiesListener = function(ev) {

zimletInstance._propertiesdialog = new ZmDialog( { title:ZmMsg.properties, parent:zimletInstance.getShell(), standardButtons:[DwtDialog.OK_BUTTON], disposeOnPopDown:true } );
zimletInstance._propertiesdialog.setContent('<div style=\'width:600px; height: 75px;\'>'+content+'</div>');
document.getElementById('props_owncloud_zimlet_server_path').value = location;
zimletInstance._propertiesdialog.setButtonListener(DwtDialog.OK_BUTTON, new AjxListener(this, this.okbtnProperties,[davResource]));
zimletInstance._propertiesdialog._setAllowSelection();
document.getElementById(zimletInstance._propertiesdialog.__internalId+'_handle').style.backgroundColor = '#eeeeee';
Expand Down
36 changes: 2 additions & 34 deletions zimlet/tk_barrydegraaff_owncloud_zimlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,25 +162,6 @@ ownCloudZimlet.prototype.init =
tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_oc_folder'] = this.getUserProperty("owncloud_zimlet_oc_folder");
}

//Set default value in case no owncloud_zimlet_use_numbers is set
if(!this.getUserProperty("owncloud_zimlet_use_numbers"))
{
if(this._zimletContext.getConfig("owncloud_zimlet_use_numbers"))
{
//Did the admin specify one? Use that:
tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_use_numbers'] = this._zimletContext.getConfig("owncloud_zimlet_use_numbers");
}
else
{
//Seems like the admins wants to clear this field, do it:
tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_use_numbers'] = "";
}
}
else
{
tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_use_numbers'] = this.getUserProperty("owncloud_zimlet_use_numbers");
}

//Set default value
if(!this.getUserProperty("owncloud_zimlet_template"))
{
Expand Down Expand Up @@ -1337,7 +1318,6 @@ ownCloudZimlet.prototype.displayDialog =
"<td style='min-width:200px'>"+ZmMsg.location+"&nbsp;ownCloud/Nextcloud:&nbsp;</td>" +
"<td style='min-width:400px'><input style='width:98%' type='text' id='owncloud_zimlet_oc_folder' value='"+tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_oc_folder']+"'></td>" +
"</tr>" +
"<tr class='owncloud_zimlet_userprefs'><td style='min-width:200px'>"+ZmMsg.usePrefix + " " + (ZmMsg.number).toLowerCase()+":&nbsp;</td><td><table><tr class='oc_userprefs'><td><input type='checkbox' id='owncloud_zimlet_use_numbers' value='true' " + (tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_use_numbers']=='false' ? '' : 'checked') +"></td></tr></table></td></tr>" +
"<tr class='owncloud_zimlet_userprefs'><td style='min-width:200px'>"+ZmMsg.template+":&nbsp;</td><td style='min-width:400px'><textarea placeholder='"+ZmMsg.clickToAdd+"' onclick='ownCloudZimlet.prototype.setTemplate()' rows='6' id='owncloud_zimlet_template'>" + tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_template'] +"</textarea></td></tr>" +
"<tr><td colspan=2><br><br><small>"+ZmMsg.versionLabel+" "+ownCloudZimlet.version +"</small></td></tr>"
"</table>" +
Expand All @@ -1354,11 +1334,10 @@ ownCloudZimlet.prototype.displayDialog =
zimletInstance._dialog._tabGroup.addMember(document.getElementById('owncloud_zimlet_server_port'),4);
zimletInstance._dialog._tabGroup.addMember(document.getElementById('owncloud_zimlet_server_path'),5);
zimletInstance._dialog._tabGroup.addMember(document.getElementById('owncloud_zimlet_oc_folder'),6);
zimletInstance._dialog._tabGroup.addMember(document.getElementById('owncloud_zimlet_use_numbers'),7);
zimletInstance._dialog._tabGroup.addMember(document.getElementById('owncloud_zimlet_template'),8);
zimletInstance._dialog._tabGroup.addMember(document.getElementById('owncloud_zimlet_template'),7);
zimletInstance._dialog._tabGroup.addMember(document.getElementById(zimletInstance._dialog._button[1].__internalId));
zimletInstance._dialog._tabGroup.addMember(document.getElementById(zimletInstance._dialog._button[2].__internalId));
zimletInstance._dialog._baseTabGroupSize = 8;
zimletInstance._dialog._baseTabGroupSize = 7;
break;
case 2:
//Default dialog
Expand Down Expand Up @@ -1495,17 +1474,6 @@ ownCloudZimlet.prototype.prefSaveBtn = function()
}
tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_password'] = document.getElementById('owncloud_zimlet_password').value;

if(document.getElementById("owncloud_zimlet_use_numbers").checked)
{
this.setUserProperty("owncloud_zimlet_use_numbers", "true", false);
tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_use_numbers'] = "true";
}
else
{
this.setUserProperty("owncloud_zimlet_use_numbers", "false", false);
tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_use_numbers'] = "false";
}

this.setUserProperty("owncloud_zimlet_server_name", serverName, false);
tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_server_name'] = serverName;

Expand Down
3 changes: 1 addition & 2 deletions zimlet/tk_barrydegraaff_owncloud_zimlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ along with this program. If not, see http://www.gnu.org/licenses/.
-->
<zimlet name="tk_barrydegraaff_owncloud_zimlet"
version="1.1.2"
version="1.1.3"
target="main compose-window view-window"
label="WebDAV"
description="Attach from and save to WebDAV">
Expand Down Expand Up @@ -51,7 +51,6 @@ along with this program. If not, see http://www.gnu.org/licenses/.
<property type="string" label="" name="owncloud_zimlet_server_port" rows="1"/>
<property type="string" label="" name="owncloud_zimlet_server_path" rows="1"/>
<property type="string" label="" name="owncloud_zimlet_oc_folder" rows="1"/>
<property type="string" label="" name="owncloud_zimlet_use_numbers" rows="1"/>
<property type="string" label="" name="owncloud_zimlet_template" rows="1"/>
</userProperties>
<contentObject>
Expand Down

0 comments on commit 66f2e17

Please sign in to comment.