diff --git a/css/imce-content.css b/css/imce-content.css index f746e0d..39f71e5 100755 --- a/css/imce-content.css +++ b/imce-content.css @@ -457,4 +457,17 @@ body.imce { } .box-view #file-list td.size, .box-view #file-list td.date, .box-view #file-list td.width, .box-view #file-list td.height { display: none; -} \ No newline at end of file +} +#dir-stat .imce_pager { + text-align:right; + width:49%; + + float:right; +} +#dir-stat .dir-stat-inner { + width:49%; + + float:left; +} + + diff --git a/imce.module b/imce.module index f3dc4bf..89f4940 100755 --- a/imce.module +++ b/imce.module @@ -69,6 +69,13 @@ function imce_theme() { $theme['imce_root_text'] = array( 'variables' => array('imce_ref' => NULL), ); + + $theme['imce_pager'] = array( + 'template' => 'imce-pager', + 'arguments' => array('imce' => NULL, 'start' => NULL, 'end' => NULL, 'total' => NULL, 'page' => NULL), + 'path' => $path, + ); + $theme['imce_user_page'] = array( 'variables' => array('account' => NULL), ); @@ -79,7 +86,7 @@ function imce_theme() { ); $theme['imce_content'] = array( 'template' => 'imce-content', - 'variables' => array('tree' => NULL, 'forms' => NULL, 'imce_ref' => NULL), + 'arguments' => array('tree' => NULL, 'forms' => NULL, 'imce_ref' => NULL, 'pager' => NULL), 'path' => $path, ); $theme['imce_page'] = array( @@ -198,4 +205,27 @@ function imce_user_page_access($account, $user = FALSE) { */ function imce_reg_dir($dirname) { return $dirname == '.' || is_int($dirname) || (is_string($dirname) && $dirname != '' && !preg_match('@(^\s)|(^/)|(^\./)|(\s$)|(/$)|(/\.$)|(\.\.)|(//)|(\\\\)|(/\./)@', $dirname)); -} \ No newline at end of file +} + + +function imce_get_pager($imce) { + $imce_showperpage = variable_get('imce_showperpage', 20); + if ($imce_showperpage != 0) { + $page = 1; + $total = intval(count($imce['files']) / $imce_showperpage); + if (isset($_GET['page'])) { + $page = intval($_GET['page']); + } + + $start = $page >= 7 ? $page - 4 : 1; + $end = $page >= 7 ? (($page + 4) > $total ? $total : $page + 4 ) : variable_get('imce_maxpages', 10); + + return theme('imce_pager', array('total'=>$total,'imce'=>$imce,'start'=>$start,'end'=>$end,'page'=>$page)); } + else { + return ''; + } + } + + + + diff --git a/inc/imce.admin.inc b/inc/imce.admin.inc index c2d3625..336bff5 100755 --- a/inc/imce.admin.inc +++ b/inc/imce.admin.inc @@ -63,7 +63,27 @@ function imce_admin_form($form, &$form_state) { $core = $rid == DRUPAL_ANONYMOUS_RID || $rid == DRUPAL_AUTHENTICATED_RID; $form['roles'][$rid] = imce_role_form($role, $form['#weighted'], $core); } +//pager settings + $form['pager'] = array( + '#type' => 'fieldset', + '#title' => t('Pager settings'), + '#collapsible' => true, + '#collapsed' => false, + ); + $form['pager']['imce_showperpage'] = array( + '#type' => 'textfield', + '#title' => t('Number files per page'), + '#default_value' => variable_get('imce_showperpage', 20), + '#description' => t('By default 20 shown per page. Smaller number faster rendering. Set to 0 for remove paging'), + ); + + $form['pager']['imce_maxpages'] = array( + '#type' => 'textfield', + '#title' => t('Maximum number of pages to display.'), + '#default_value' => variable_get('imce_maxpages', 10), + '#description' => t('By default 10 pages displayd in pager.'), + ); //common settings $form['common'] = array( '#type' => 'fieldset', @@ -183,6 +203,14 @@ function imce_admin_submit($form, &$form_state) { variable_set('imce_settings_replace', $form_state['values']['replace']); variable_set('imce_settings_thumb_method', $form_state['values']['thumb_method']); variable_set('imce_settings_disable_private', $form_state['values']['disable_private']); + if (isset($form_state['values']['imce_maxpages'])) { + variable_set('imce_maxpages', $form_state['values']['imce_maxpages']); + } + + if (isset($form_state['values']['imce_showperpage'])) { + variable_set('imce_showperpage', $form_state['values']['imce_showperpage']); + } + drupal_set_message(t('Changes have been saved.')); } @@ -737,4 +765,4 @@ function imce_admin_check_wildcard_upload($rid, $conf = NULL) { } //Include core profile functions. -include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'imce') . '/inc/imce.core.profiles.inc'; \ No newline at end of file +include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'imce') . '/inc/imce.core.profiles.inc'; diff --git a/inc/imce.page.inc b/inc/imce.page.inc index ab52aa7..7a40908 100755 --- a/inc/imce.page.inc +++ b/inc/imce.page.inc @@ -57,6 +57,7 @@ function imce_content($user, $scheme = NULL, $jsop = NULL) { $imce_ref = array('imce' => &$imce); $forms = array(); if (!$imce['error']) { + //process file upload. if (imce_perm_exists($imce, 'upload')) { $forms[] = drupal_get_form('imce_upload_form', $imce_ref); @@ -73,11 +74,20 @@ function imce_content($user, $scheme = NULL, $jsop = NULL) { } } - $content = theme('imce_content', array( - 'tree' => imce_create_tree($imce), - 'forms' => $forms, - 'imce_ref' => $imce_ref, - )); + //pager start + $page = 1; + $total = intval(count($imce['files']) / variable_get('imce_showperpage', 20)); + if (isset($_GET['page'])) { + $page = intval($_GET['page']); + } + + $start = $page >= 7 ? $page - 4 : 1; + $end = $page >= 7 ? (($page + 4) > $total ? $total : $page + 4 ) : variable_get('imce_maxpages', 10); + //pager end + + $pager = theme('imce_pager', array('imce'=>$imce, 'start'=>$start,'end'=> $end, 'total'=>$total, 'page'=>$page)); + + $content = theme('imce_content', array('tree'=>imce_create_tree($imce),'forms'=>$forms,'imce_ref'=>$imce_ref,'pager'=>$pager)); //make necessary changes for js conversion $imce['dir'] = str_replace('%2F', '/', rawurlencode($imce['dir'])); @@ -110,6 +120,8 @@ function imce_js($user, $scheme, $jsop = '') { } } } + //pager + $response['data']['dirpager'] = imce_get_pager($imce); //messages $response['messages'] = drupal_get_messages(); @@ -763,6 +775,7 @@ function imce_process_profile(&$imce) { $imce += $scan($imce['dir'], $imce); //run custom process functions + foreach (variable_get('imce_custom_process', array()) as $func => $state) { if ($state && function_exists($func)) { $func($imce); @@ -773,6 +786,7 @@ function imce_process_profile(&$imce) { if (!$imce['error'] && !imce_subdirectories_accessible($imce)) { $imce['subdirectories'] = array(); } + } /** @@ -973,7 +987,7 @@ function imce_scan_directory($dirname, $imce) { $directory['error'] = TRUE; return $directory; } - + while (($file = readdir($handle)) !== FALSE) { // Do not include dot files and folders @@ -1007,6 +1021,7 @@ function imce_scan_directory($dirname, $imce) { closedir($handle); sort($directory['subdirectories']); + return $directory; } @@ -1115,4 +1130,4 @@ function imce_file_register($file) { if (!db_query("SELECT 1 FROM {file_usage} WHERE module = 'imce' AND fid = :fid", array(':fid' => $file->fid))->fetchField()) { file_usage_add($file, 'imce', 'file', $file->fid); } -} \ No newline at end of file +} diff --git a/js/imce.js b/js/imce.js index 4e8948d..8935427 100755 --- a/js/imce.js +++ b/js/imce.js @@ -425,7 +425,7 @@ navUpdate: function(data, dir) { //set cache navCache: function (dir, newdir) { - var C = imce.cache[dir] = {'dir': dir, files: imce.el('file-list'), dirsize: imce.el('dir-size').innerHTML, perm: $.extend({}, imce.conf.perm)}; + var C = imce.cache[dir] = {'dir': dir, files: imce.el('file-list'), dirsize: imce.el('dir-size').innerHTML, dirpager: imce.el('dir-pager').innerHTML, perm: $.extend({}, imce.conf.perm)}; C.files.id = 'cached-list-'+ dir; imce.FW.appendChild(C.files); imce.invoke('cache', C, newdir); @@ -614,6 +614,7 @@ resData: function (data) { imce.fileRemove(removed[i]); } imce.conf.dirsize = data.dirsize; + imce.conf.dirpager = data.dirpager; imce.updateStat(); }, @@ -663,6 +664,7 @@ validateSelCount: function (Min, Max) { updateStat: function () { imce.el('file-count').innerHTML = imce.findex.length; imce.el('dir-size').innerHTML = imce.conf.dirsize; + imce.el('dir-pager').innerHTML = imce.conf.dirpager; }, //serialize selected files. return fids with a colon between them @@ -827,4 +829,4 @@ updateUI: function() { //initiate $(document).ready(imce.initiate); -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/js/imce_set_app.js b/js/imce_set_app.js index 419f7df..060a5ac 100755 --- a/js/imce_set_app.js +++ b/js/imce_set_app.js @@ -60,7 +60,9 @@ imce.hooks.load.push(function(win) { } } var filename = $('#'+ appFields.url, appWindow.document).val() || ''; - imce.highlight(filename.substr(filename.lastIndexOf('/')+1)); + if (typeof (filename) != 'undefined') { + imce.highlight(filename.substr(filename.lastIndexOf('/')+1)); + } } // Set send to sendtoFunc && imce.setSendTo(Drupal.t('Insert file'), sendtoFunc); @@ -94,4 +96,4 @@ var isFunc = function(str, scope) { return obj && i == len && (typeof obj == 'function' || typeof obj != 'string' && !obj.nodeName && obj.constructor != Array && /^[\s[]?function/.test(obj.toString())) ? obj : false; } -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/tpl/imce-content.tpl.php b/tpl/imce-content.tpl.php index 53a397c..ebf1bb6 100755 --- a/tpl/imce-content.tpl.php +++ b/tpl/imce-content.tpl.php @@ -87,11 +87,15 @@ $imce =& $imce_ref['imce'];//keep this line. $imce_ref)); /* see imce-file-list-tpl.php */?> -
+
+ ''. count($imce['files']) .'', '!dirsize' => ''. format_size($imce['dirsize']) .'', '!quota' => ''. ($imce['quota'] ? format_size($imce['quota']) : ($imce['tuquota'] ? format_size($imce['tuquota']) : t('unlimited quota'))) .'' )); ?> +
+
@@ -103,6 +107,8 @@ $imce =& $imce_ref['imce'];//keep this line. -
+
\ No newline at end of file +print $forms; ?>
+ + diff --git a/tpl/imce-file-list.tpl.php b/tpl/imce-file-list.tpl.php index 9447fa0..ef175ee 100755 --- a/tpl/imce-file-list.tpl.php +++ b/tpl/imce-file-list.tpl.php @@ -8,11 +8,22 @@ $imce =& $imce_ref['imce'];//keep this line. * You can always change the data created by format functions * such as format_size or format_date, or you can do css theming which is the best practice here. */ + $imce_showperpage = variable_get('imce_showperpage', 20); +if ($imce_showperpage != 0) { + $start = 0; + if (isset($_GET['page']) && $_GET['page'] != 1) { + $start = ($_GET['page'] - 1) * $imce_showperpage; + } + $files = array_slice($imce['files'], $start, $imce_showperpage); +} +else { + $files = $imce['files']; +} ?> $file) {?> +if ($imce['perm']['browse'] && !empty($files)) : + foreach ($files as $name => $file) : ?> @@ -20,6 +31,6 @@ if ($imce['perm']['browse'] && !empty($imce['files'])) { -
\ No newline at end of file + endforeach; +endif; ?> + diff --git a/_modified/tpl/imce-pager.tpl.php b/tpl/imce-pager.tpl.php new file mode 100755 index 0000000..7338444 --- /dev/null +++ b/tpl/imce-pager.tpl.php @@ -0,0 +1,29 @@ +: + variable_get('imce_maxpages', 10)) + { + for($i = $start; $i < $end; $i++) { + if ($page == $i) { + print l($i, 'imce', array('query' => array('app'=>'tinymce','page'=>$i), 'attributes' => array('style' => 'font-weight:bold;text-decoration:underline;'))).' | '; + } + else { + print l($i, 'imce', array('query' => array('app'=>'tinymce','page'=>$i))).' | '; + } + } + if (($page + 4) < $total) { + print ' ... | '; + } + print l($total, 'imce', array('query' => array('app'=>'tinymce','page'=>$total), 'attributes' => ($total == $page ? array('style' => 'font-weight:bold;text-decoration:underline;') : array()))).' | '; + } + else { + for($i = 1; $i <= $total+1; $i++) { + if ($page == $i) { + print l($i, 'imce', array('query' => array('app'=>'tinymce','page'=>$i), 'attributes' => array('style' => 'font-weight:bold;text-decoration:underline;'))).' | '; + } + else { + print l($i, 'imce', array('query' => array('app'=>'tinymce','page'=>$i))).' | '; + } + } + } + +?>