PageRenderTime 107ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/windwalker/helpers/elfinder.php

https://bitbucket.org/asikart-extension/joomclouds-client
PHP | 241 lines | 145 code | 43 blank | 53 comment | 7 complexity | bab73fb00e0fc4b7fef896c5a8538677 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Windwalker.Framework
  4. * @subpackage Helpers
  5. *
  6. * @copyright Copyright (C) 2012 Asikart. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. * @author Generated by AKHelper - http://asikart.com
  9. */
  10. // No direct access
  11. defined('_JEXEC') or die;
  12. /**
  13. * elFinder Connector & Displayer.
  14. *
  15. * @package Windwalker.Framework
  16. * @subpackage Helpers
  17. */
  18. class AKHelperElfinder
  19. {
  20. /**
  21. * display
  22. */
  23. public static function display($com_option = null, $option = array())
  24. {
  25. // Init some API objects
  26. // ================================================================================
  27. $date = JFactory::getDate( 'now' , JFactory::getConfig()->get('offset') ) ;
  28. $uri = JFactory::getURI() ;
  29. $user = JFactory::getUser() ;
  30. $app = JFactory::getApplication() ;
  31. $doc = JFactory::getDocument() ;
  32. $lang = JFactory::getLanguage();
  33. $lang_code = $lang->getTag();
  34. $lang_code = str_replace('-', '_', $lang_code) ;
  35. // Script
  36. self::_displayScript($com_option, $option);
  37. // Base Toolbar
  38. $toolbar_base = array(
  39. array('back', 'forward'),
  40. array('reload'),
  41. //array('home', 'up'),
  42. array('mkdir', 'mkfile', 'upload'),
  43. //array('open', 'download', 'getfile'),
  44. array('info'),
  45. array('quicklook'),
  46. array('copy', 'cut', 'paste'),
  47. array('rm'),
  48. array('duplicate', 'rename', 'edit', 'resize'),
  49. //array('extract', 'archive'),
  50. array('search'),
  51. array('view'),
  52. array('help')
  53. );
  54. // Get Request
  55. $com_option = $com_option ? $com_option : JRequest::getVar('option') ;
  56. $finder_id = JRequest::getVar('finder_id') ;
  57. $modal = ( JRequest::getVar('tmpl') == 'component' ) ? true : false ;
  58. $root = JArrayHelper::getValue($option, 'root', JRequest::getVar('root', '/'));
  59. $start_path = JArrayHelper::getValue($option, 'start_path', JRequest::getVar('start_path', '/'));
  60. $site_root = JURI::root(true).'/' ;
  61. $toolbar = JArrayHelper::getValue($option, 'toolbar', $toolbar_base);
  62. $toolbar = $toolbar ? json_encode($toolbar) : json_encode($toolbar_base) ;
  63. $onlymimes = JArrayHelper::getValue($option, 'onlymimes', JRequest::getVar('onlymimes', null));
  64. $onlymimes = is_array($onlymimes) ? implode(',', $onlymimes) : $onlymimes;
  65. $onlymimes = $onlymimes ? "'".str_replace(",", "','", $onlymimes)."'" : '';
  66. // Get INI setting
  67. $upload_max = ini_get('upload_max_filesize') ;
  68. $upload_num = ini_get('max_file_uploads') ;
  69. $upload_limit = 'Max upload size: '.$upload_max ;
  70. $upload_limit .= ' | Max upload files: '.$upload_num ;
  71. // Set Script
  72. $getFileCallback = !$modal ? '' : "
  73. ,
  74. getFileCallback : function(file){
  75. if (window.parent) window.parent.AKFinderSelect( '{$finder_id}',AKFinderSelected, window.elFinder, '{$site_root}');
  76. }";
  77. $script = <<<SCRIPT
  78. var AKFinderSelected ;
  79. var elFinder ;
  80. // Init elFinder
  81. jQuery(document).ready(function($) {
  82. elFinder = $('#elfinder').elfinder({
  83. url : 'index.php?option={$com_option}&task=elFinderConnector&root={$root}&start_path={$start_path}' ,
  84. width : '100%' ,
  85. height : 445 ,
  86. onlyMimes : [$onlymimes],
  87. lang : '{$lang_code}',
  88. uiOptions : {
  89. toolbar : {$toolbar}
  90. },
  91. handlers : {
  92. select : function(event, elfinderInstance) {
  93. var selected = event.data.selected;
  94. if (selected.length) {
  95. AKFinderSelected = [];
  96. jQuery.each(selected, function(i, e){
  97. AKFinderSelected[i] = elfinderInstance.file(e);
  98. });
  99. }
  100. }
  101. }
  102. {$getFileCallback}
  103. }).elfinder('instance');
  104. elFinder.ui.statusbar.append( '<div class="akfinder-upload-limit">{$upload_limit}</div>' );
  105. });
  106. SCRIPT;
  107. $doc->addScriptDeclaration($script);
  108. echo '<div class="row-fluid">
  109. <div id="elfinder" class="span12 ak-finder"></div>
  110. </div>' ;
  111. }
  112. /**
  113. * Set Script for Finder Display
  114. */
  115. public static function _displayScript($com_option, $option = array())
  116. {
  117. $doc = JFactory::getDocument() ;
  118. $lang = JFactory::getLanguage();
  119. $lang_code = $lang->getTag();
  120. $lang_code = str_replace('-', '_', $lang_code) ;
  121. // Include elFinder and JS
  122. // ================================================================================
  123. JHtml::_('behavior.framework', true);
  124. if( JVERSION >= 3){
  125. // jQuery
  126. JHtml::_('jquery.framework', true);
  127. JHtml::_('bootstrap.framework', true);
  128. }else{
  129. $doc->addStyleSheet(JURI::base().'/components/'.$com_option.'/includes/bootstrap/css/bootstrap.min.css');
  130. // jQuery
  131. AKHelper::_('include.addJS', 'jquery/jquery.js', 'ww') ;
  132. $doc->addScriptDeclaration('jQuery.noConflict();');
  133. }
  134. $assets_url = AKHelper::_('path.getWWUrl').'/assets' ;
  135. // elFinder includes
  136. $doc->addStylesheet( $assets_url.'/js/jquery-ui/css/smoothness/jquery-ui-1.8.24.custom.css' );
  137. $doc->addStylesheet( $assets_url.'/js/elfinder/css/elfinder.min.css' );
  138. $doc->addStylesheet( $assets_url.'/js/elfinder/css/theme.css' );
  139. $doc->addscript( $assets_url.'/js/jquery-ui/js/jquery-ui.min.js' );
  140. $doc->addscript( $assets_url.'/js/elfinder/js/elfinder.min.js' );
  141. JHtml::script( $assets_url.'/js/elfinder/js/i18n/elfinder.'.$lang_code.'.js' );
  142. AKHelper::_('include.core');
  143. }
  144. /**
  145. * connector
  146. */
  147. public static function connector($com_option = null, $option = array())
  148. {
  149. error_reporting( JArrayHelper::getValue($option, 'error_reporting', 0) ); // Set E_ALL for debuging
  150. $elfinder_path = AKPATH_ASSETS.'/js/elfinder/php/' ;
  151. include_once $elfinder_path.'elFinderConnector.class.php';
  152. include_once $elfinder_path.'elFinder.class.php';
  153. include_once $elfinder_path.'elFinderVolumeDriver.class.php';
  154. /**
  155. * Simple function to demonstrate how to control file access using "accessControl" callback.
  156. * This method will disable accessing files/folders starting from '.' (dot)
  157. *
  158. * @param string $attr attribute name (read|write|locked|hidden)
  159. * @param string $path file path relative to volume root directory started with directory separator
  160. * @return bool|null
  161. **/
  162. function access($attr, $path, $data, $volume) {
  163. return strpos(basename($path), '.') === 0 // if file/folder begins with '.' (dot)
  164. ? !($attr == 'read' || $attr == 'write') // set read+write to false, other (locked+hidden) set to true
  165. : null; // else elFinder decide it itself
  166. }
  167. // Get Some Request
  168. $com_option = $com_option ? $com_option : JRequest::getVar('option') ;
  169. $root = JRequest::getVar('root', '/') ;
  170. $start_path = JRequest::getVar('start_path', '/') ;
  171. $opts = array(
  172. // 'debug' => true,
  173. 'roots' => array(
  174. array(
  175. 'driver' => 'LocalFileSystem', // driver for accessing file system (REQUIRED)
  176. 'path' => JPath::clean(JPATH_ROOT.'/'.$root, '/'), // path to files (REQUIRED)
  177. 'startPath' => JPath::clean(JPATH_ROOT.'/'.$root.'/'.$start_path. '/') ,
  178. 'URL' => JPath::clean(JURI::root(true).'/'.$root.'/'.$start_path, '/'), // URL to files (REQUIRED)
  179. 'tmbPath' => JPath::clean(JPATH_CACHE.'/AKFinderThumb'),
  180. 'tmbURL' => JURI::root() . 'cache/AKFinderThumb',
  181. //'tmbSize' => 128,
  182. 'tmp' => JPath::clean(JPATH_CACHE.'/AKFinderTemp'),
  183. 'accessControl' => 'access', // disable and hide dot starting files (OPTIONAL)
  184. 'uploadDeny' => array('text/x-php'),
  185. //'uploadAllow' => array('image'),
  186. 'disabled' => array('archive', 'extract', 'rename', 'mkfile')
  187. )
  188. )
  189. );
  190. $opts = array_merge( $opts, $option );
  191. foreach( $opts['roots'] as $driver ):
  192. include_once $elfinder_path.'elFinderVolume'.$driver['driver'].'.class.php';
  193. endforeach;
  194. // run elFinder
  195. $connector = new elFinderConnector(new elFinder($opts));
  196. $connector->run();
  197. }
  198. }