do_admin_uploaded($file_cmd);
}else{
$this->Finder();
}
}
public function Finder(){
global $config, $dataDir;
$this->page->head .= "\n".'';
$this->page->head .= "\n".'';
$this->page->head .= "\n".'';
$this->page->head .= "\n".'';
echo '
';
\gp\tool::LoadComponents('selectable,draggable,droppable,resizable,dialog,slider,button');
//get the finder language
$language = $config['langeditor'];
if( $language == 'inherit' ){
$language = $config['language'];
}
$lang_file = '/include/thirdparty/finder/js/i18n/'.$language.'.js';
$lang_full = $dataDir.$lang_file;
if( file_exists($lang_full) ){
$this->page->head .= "\n".'';
}else{
$language = 'en';
}
$this->finder_opts['lang'] = $language;
$this->finder_opts['customData']['verified'] = \gp\tool::new_nonce('post',true);
$this->finder_opts['uiOptions'] = array(
// toolbar configuration
'toolbar' => array(
array('back', 'forward','up','reload'),
array('home','netmount'),
array('mkdir', 'upload'), //'mkfile',
array('open', 'download', 'getfile'),
array('info'),
array('quicklook'),
array('copy', 'cut', 'paste'),
array('rm'),
array('duplicate', 'rename', 'edit', 'resize'),
array('extract', 'archive'),
array('search'),
array('view','sort'),
array('help')
),
// directories tree options
'tree' => array(
// expand current root on init
'openRootOnLoad' => true,
// auto load current dir parents
'syncTree' => true,
),
// navbar options
'navbar' => array(
'minWidth' => 150,
'maxWidth' => 500
),
// current working directory options
'cwd' => array(
// display parent directory in listing as ".."
'oldSchool' => false
)
);
$this->FinderPrep();
$this->finder_opts = \gp\tool\Plugins::Filter('FinderOptionsClient',array($this->finder_opts));
gpSettingsOverride('finder_options_client',$this->finder_opts);
$this->page->head_script .= "\n".'var finder_opts = '.json_encode($this->finder_opts).';';
}
public function FinderPrep(){
$this->finder_opts['url'] = \gp\tool::GetUrl('Admin_Finder');
$this->finder_opts['height'] = '100%';
$this->finder_opts['resizable'] = false;
}
public function do_admin_uploaded($file_cmd){
$this->Init();
$this->page->ajaxReplace = array();
switch($file_cmd){
case 'delete':
$this->DeleteConfirmed();
return;
case 'inline_upload':
$this->InlineUpload();
//dies
}
}
public function Init(){
global $langmessage, $dataDir;
$this->baseDir = $dataDir.'/data/_uploaded';
$this->thumbFolder = $dataDir.'/data/_uploaded/image/thumbnails';
$this->currentDir = $this->baseDir;
$this->page->label = $langmessage['uploaded_files'];
$this->imgTypes = array('bmp'=>1,'png'=>1,'jpg'=>1,'jpeg'=>1,'gif'=>1,'tiff'=>1,'tif'=>1,'svg'=>1,'svgz'=>1);
$this->SetDirectory();
//prompt to create the requested subdirectory
if( !file_exists($this->currentDir) ){
\gp\tool\Files::CheckDir($this->currentDir);
}
//is in thumbnail directory?
if( strpos($this->currentDir,$this->thumbFolder) !== false ){
$this->isThumbDir = true;
}
$this->currentDir_Thumb = $this->thumbFolder.$this->subdir;
}
/**
* Set the upload directory
*
*/
public function SetDirectory(){
$subdir = '';
$path = \gp\tool::WhichPage(); // get the current path, not using $page->requested since space characters will have been changed to underscores
$path = str_replace('\\','/',$path);
//@since 5.0
if( strpos($path,'Admin/Uploaded') === 0 ){
$path = substr($path,14);
$path = trim($path,'/');
$parts = explode('/',$path);
//backwards compat
}else{
$path = trim($path,'/');
$parts = explode('/',$path);
array_shift($parts);
}
if( count($parts) > 0 ){
$subdir = '/'.implode('/',$parts);
$subdir = \gp\tool\Editing::CleanArg($subdir);
}
if( !empty($_REQUEST['dir']) ){
$subdir .= \gp\tool\Editing::CleanArg($_REQUEST['dir']);
}
$subdir = \gp\tool\Files::Canonicalize($subdir);
$subdir = rtrim($subdir,'/');
$current_dir = $this->currentDir . $subdir;
if( !\gp\tool\Files::CheckPath( $current_dir, $this->currentDir ) ){
return;
}
$this->subdir = $subdir;
$this->currentDir = $current_dir;
}
public function ReadableMax(){
$value = ini_get('upload_max_filesize');
if( empty($value) ){
return '2 Megabytes';//php default
}
return $value;
}
public static function Max_File_Size(){
$value = ini_get('upload_max_filesize');
if( empty($value) ){
return;
}
$max = \gp\tool::getByteValue($value);
if( $max !== false ){
echo '';
}
}
/**
* Upload one image
*
*/
public function InlineUpload(){
if( count($_FILES['userfiles']['name']) != 1 ){
$this->InlineResponse('failed','Empty Array');
}
$name = $_FILES['userfiles']['name'][0];
if( empty($name) ){
$this->InlineResponse('failed','Empty Name');
}
$uploaded = $this->UploadFile(0);
if( $uploaded === false ){
reset($this->errorMessages);
$this->InlineResponse('failed',current($this->errorMessages));
}
\gp\tool\Plugins::Action('FileUploaded',$uploaded);
$return_content = self::ShowFile_Gallery($this->subdir,$uploaded);
if( is_string($return_content) ){
$this->InlineResponse('success',$return_content);
}else{
$this->InlineResponse('notimage','');
}
}
/**
* Output a list a images in a director for use in inline editing
* @static
*/
public static function InlineList($dir_piece){
global $langmessage, $dataDir, $page;
$page->ajaxReplace = array();
$dir_piece = \gp\tool::WinPath($dir_piece);
$dir = $dataDir.'/data/_uploaded'.$dir_piece;
$prev_piece = false;
while( ($dir_piece != '/') && !file_exists($dir) ){
$prev_piece = $dir_piece;
$dir = \gp\tool::DirName($dir);
$dir_piece = \gp\tool::DirName($dir_piece);
}
//new directory?
if( $prev_piece ){
$prev_piece = \gp\tool\Editing::CleanArg($prev_piece);
$dir_piece = $prev_piece;
$dir = $dataDir.'/data/_uploaded'.$prev_piece;
if( !\gp\tool\Files::CheckDir($dir) ){
message($langmessage['OOPS']);
$dir = \gp\tool::DirName($dir);
$dir_piece = \gp\tool::DirName($prev_piece);
}
}
//folder information
$folders = $files = array();
$allFiles = \gp\tool\Files::ReadFolderAndFiles($dir);
list($folders,$files) = $allFiles;
//available images
ob_start();
$image_count = 0;
foreach($files as $file){
$img = self::ShowFile_Gallery($dir_piece,$file);
if( is_string($img) ){
echo $img;
$image_count++;
}
}
$gp_gallery_avail_imgs = ob_get_clean();
$gp_option_area = self::InlineList_Options($dir_piece, $folders);
$folder_options = self::InlineList_Folder($image_count, $dir_piece);
//send content according to request
$cmd = \gp\tool::GetCommand();
switch($cmd){
case 'gallery_folder':
$page->ajaxReplace[] = array('inner','#gp_option_area',$gp_option_area);
$page->ajaxReplace[] = array('inner','#gp_gallery_avail_imgs',$gp_gallery_avail_imgs);
break;
default:
$content = '
'.$gp_option_area.'
'
.'
'.$gp_gallery_avail_imgs.'
';
$page->ajaxReplace[] = array('inner','#gp_image_area',$content);
break;
}
$page->ajaxReplace[] = array('inner','#gp_folder_options',$folder_options);
$page->ajaxReplace[] = array('gp_gallery_images','',''); //tell the script the images have been loaded
}
/**
* Return folder options for the InlineList
*
*/
public static function InlineList_Options($dir_piece, $folders){
global $langmessage, $dataDir;
$return = '';
$return .= '