Skip to content

Commit 131f410

Browse files
committed
Merge pull request #43 from amin101/bugfix
Bugfix
2 parents a3f2e6a + 5771f7e commit 131f410

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,41 @@ PR is welcome!
135135
</script>
136136
```
137137
138+
##Independent use
139+
140+
If you are going to use filemanager independently,meaning set the value of an input to selected photo/file url,follow this structure:
141+
142+
1. create a popup window or modal(whatever you like):
143+
144+
```html
145+
<a href="/laravel-filemanager" id="feature-img-container"><img src="no_photo.jpg"></a>
146+
<input name="thumbnail" type="hidden" id="thumbnail">
147+
```
148+
149+
```javascript
150+
$('#feature-img-container').on('click', function(e)
151+
{
152+
153+
window.open(this.href, 'Filemanager', 'width=900,height=600');
154+
155+
return false;
156+
});
157+
```
158+
159+
2. define a function named `SetUrl`:
160+
161+
```javascript
162+
function SetUrl(url){
163+
164+
//set the value of the desired input to image url,often this is a hidden input
165+
$('#thumbnail').val(url);
166+
167+
//set or change the feature image src,recall wordpress feature image
168+
$('#feature-img-container').find('img').attr('src',url);
169+
}
170+
```
171+
172+
138173
## Config
139174

140175
In `config/lfm.php` :

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"tinymce",
1010
"upload",
1111
"file",
12-
"manager"
12+
"manager",
13+
"image"
1314
],
1415
"authors": [
1516
{

src/controllers/LfmController.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,18 @@ private function formatLocation($location, $type = null, $get_thumb = false)
9191
$working_dir = substr($working_dir, 1);
9292
}
9393

94+
9495
$location .= $working_dir;
9596

9697
if ($type === 'directory' || $type === 'thumb') {
9798
$location .= DIRECTORY_SEPARATOR;
9899
}
99100

100-
if ($type === 'thumb') {
101+
//if user is inside thumbs folder there is no need
102+
// to add thumbs substring to the end of $location
103+
$in_thumb_folder = preg_match('/'.Config::get('lfm.thumb_folder_name').'$/i',$working_dir);
104+
105+
if ($type === 'thumb' && !$in_thumb_folder) {
101106
$location .= Config::get('lfm.thumb_folder_name') . DIRECTORY_SEPARATOR;
102107
}
103108

@@ -126,6 +131,8 @@ public function getUrl($type = null)
126131

127132
$url = $this->formatLocation($url, $type);
128133

134+
$url = str_replace('\\','/',$url);
135+
129136
return $url;
130137
}
131138

@@ -155,7 +162,7 @@ public function getFileName($file)
155162
$working_dir_start = $lfm_dir_start + strlen($this->file_location);
156163
$lfm_file_path = substr($file, $working_dir_start);
157164

158-
$arr_dir = explode(DIRECTORY_SEPARATOR, $lfm_file_path);
165+
$arr_dir = explode('/', $lfm_file_path);
159166
$arr_filename['short'] = end($arr_dir);
160167
$arr_filename['long'] = DIRECTORY_SEPARATOR . $lfm_file_path;
161168

src/views/index.blade.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
<script src="/vendor/laravel-filemanager/js/cropper.min.js"></script>
151151
<script src="/vendor/laravel-filemanager/js/jquery.form.min.js"></script>
152152
<script>
153-
var ds = "{{ DIRECTORY_SEPARATOR }}";
153+
var ds = "{{ addslashes(DIRECTORY_SEPARATOR) }}";
154154
var home_dir = ds + "{{ (Config::get('lfm.allow_multi_user')) ? Auth::user()->user_field : '' }}";
155155
var shared_folder = ds + "{{ Config::get('lfm.shared_folder_name') }}";
156156
var image_url = "{{ Config::get('lfm.images_url') }}";
@@ -445,6 +445,7 @@ function getUrlParam(paramName) {
445445
446446
var field_name = getUrlParam('field_name');
447447
var url = item_url + file;
448+
url = url.replace(/\\/g,"/");
448449
449450
if (window.opener || window.tinyMCEPopup || field_name || getUrlParam('CKEditorCleanUpFuncNum') || getUrlParam('CKEditor')) {
450451
if (window.tinyMCEPopup) {
@@ -486,9 +487,8 @@ function getUrlParam(paramName) {
486487
parent.CKEDITOR.tools.callFunction(getUrlParam('CKEditorCleanUpFuncNum'));
487488
}
488489
} else {
489-
490490
// use FCKEditor 2.0 integration method
491-
if (data['Properties']['Width'] != '') {
491+
if (typeof data != 'undefined' && data['Properties']['Width'] != '') {
492492
var p = url;
493493
var w = data['Properties']['Width'];
494494
var h = data['Properties']['Height'];
@@ -507,6 +507,7 @@ function getUrlParam(paramName) {
507507
508508
window.close();
509509
}
510+
//end useFile
510511
511512
function notImp() {
512513
bootbox.alert('Not yet implemented!');;
@@ -533,6 +534,7 @@ function makeRandom() {
533534
}
534535
return text;
535536
}
537+
536538
</script>
537539
</body>
538540
</html>

0 commit comments

Comments
 (0)