function rename_check($event, $args, $finder) { $name = $args['name']; if (gp_restrict_uploads && !admin_uploaded::AllowedExtension($name)) { return false; } $args['name'] = $name; return $args; }
function SaveHeaderImage() { global $page, $dataDir, $dirPrefix, $langmessage; includeFile('tool/Images.php'); $page->ajaxReplace = array(); //source file $source_file_rel = $_REQUEST['file']; if (!empty($_REQUEST['src'])) { $source_file_rel = rawurldecode($_REQUEST['src']); if (!empty($dirPrefix)) { $len = strlen($dirPrefix); $source_file_rel = substr($source_file_rel, $len); } } $source_file_rel = '/' . ltrim($source_file_rel, '/'); $source_file_full = $dataDir . $source_file_rel; if (!file_exists($source_file_full)) { message($langmessage['OOPS'] . ' (Source file not found)'); return; } $src_img = thumbnail::getSrcImg($source_file_full); if (!$src_img) { message($langmessage['OOPS'] . ' (Couldn\'t create image [1])'); return; } //size and position variables $orig_w = $width = imagesx($src_img); $orig_h = $height = imagesy($src_img); $posx = $posy = 0; if (isset($_REQUEST['posx']) && is_numeric($_REQUEST['posx'])) { $posx = $_REQUEST['posx']; } if (isset($_REQUEST['posy']) && is_numeric($_REQUEST['posy'])) { $posy = $_REQUEST['posy']; } if (isset($_REQUEST['width']) && is_numeric($_REQUEST['width'])) { $width = $_REQUEST['width']; } if (isset($_REQUEST['height']) && is_numeric($_REQUEST['height'])) { $height = $_REQUEST['height']; } //check to see if the image needs to be resized if ($posx == 0 && $posy == 0 && $width == $orig_w && $height == $orig_h) { $this->SetImage($source_file_rel, $width, $height); return; } //destination file $name = basename($source_file_rel); $parts = explode('.', $name); $type = array_pop($parts); if (count($parts) > 1) { $time_part = array_pop($parts); if (!ctype_digit($time_part)) { $parts[] = $time_part; } } $name = implode('.', $parts); $time = time(); if (isset($_REQUEST['time']) && ctype_digit($_REQUEST['time'])) { $time = $_REQUEST['time']; } //$dest_img_rel = '/data/_uploaded/headers/'.$name.'.'.$time.'.'.$type; $dest_img_rel = '/data/_uploaded/headers/' . $name . '.' . $time . '.png'; $dest_img_full = $dataDir . $dest_img_rel; //make sure the folder exists if (!gpFiles::CheckDir(dirname($dest_img_full))) { message($langmessage['OOPS'] . ' (Couldn\'t create directory)'); return false; } if (!thumbnail::createImg($src_img, $dest_img_full, $posx, $posy, 0, 0, $orig_w, $orig_h, $orig_w, $orig_h, $width, $height)) { message($langmessage['OOPS'] . ' (Couldn\'t create image [2])'); return; } if ($this->SetImage($dest_img_rel, $width, $height)) { includeFile('admin/admin_uploaded.php'); admin_uploaded::CreateThumbnail($dest_img_full); } }
/** * Add an uploaded plugin * */ function UploadPlugin() { global $langmessage, $dataDir; includeFile('admin/admin_uploaded.php'); includeFile('thirdparty/pclzip-2-8-2/pclzip.lib.php'); if (empty($_FILES['plugin'])) { message($langmessage['OOPS'] . ' (No File)'); return; } $plugin_file = $_FILES['plugin']; if (strpos($plugin_file['name'], '.zip') === false) { message($langmessage['OOPS'] . ' (Not a zip file)'); return; } // Unzip uses a lot of memory, but not this much hopefully @ini_set('memory_limit', '256M'); $archive = new PclZip($plugin_file['tmp_name']); // get plugin name and check file types $plugin_name = false; $remove_path = ''; $list = $archive->listContent(); foreach ($list as $file) { //plugin name if (strpos($file['filename'], 'plugin.js') !== false) { $new_plugin_name = $this->FindPluginName($archive, $file); if (!$new_plugin_name) { continue; } //use the most relevant plugin name $new_path = dirname($file['filename']); if (!$plugin_name || strlen($new_path) < strlen($remove_path)) { $plugin_name = $new_plugin_name; $remove_path = $new_path; } } //don't check extensions on folder if (isset($file['folder']) && $file['folder']) { continue; } if (!admin_uploaded::AllowedExtension($file['filename'], false)) { message($langmessage['OOPS'] . ' (File type not allowed:' . htmlspecialchars($file['filename']) . ')'); return false; } } if (!$plugin_name) { message($langmessage['OOPS'] . ' (Unknown plugin name)'); return; } //make sure plugin name isn't already in build_config if ($this->build_config && isset($this->build_config['plugins']) && isset($this->build_config['plugins'][$plugin_name]) && $this->build_config['plugins'][$plugin_name] > 0) { msg($langmessage['addon_key_defined'], '<i>' . $plugin_name . '</i>'); return; } // check destination directory $destination = $dataDir . '/data/_ckeditor/' . $plugin_name; $temp_dir = false; if (file_exists($destination)) { $temp_dir = $destination . '_' . time(); if (!rename($destination, $temp_dir)) { message($langmessage['OOPS'] . ' (Couldn\'t remove old plugin)'); return; } } elseif (!gpFiles::CheckDir($destination)) { msg($destination); message($langmessage['OOPS'] . ' (Couldn\'t create plugin folder)'); return; } //extract // extract $return = $archive->extract(PCLZIP_OPT_PATH, $destination, PCLZIP_OPT_REMOVE_PATH, $remove_path); if (!is_array($return)) { if ($temp_dir) { rename($temp_dir, $destination); } message($langmessage['OOPS'] . ' (Extract Failed)'); return; } // save configuration if (!array_key_exists($plugin_name, $this->cke_config['plugins'])) { $this->cke_config['plugins'][$plugin_name] = array('installed' => time()); } $this->cke_config['plugins'][$plugin_name]['updated'] = time(); $this->SaveConfig(); message($langmessage['SAVED']); // remove temporary if ($temp_dir) { gpFiles::RmAll($temp_dir); } }
function GalleryImages() { if (isset($_GET['dir'])) { $dir_piece = $_GET['dir']; //}elseif( isset($this->meta_data['gallery_dir']) ){ // $dir_piece = $this->meta_data['gallery_dir']; } else { $dir_piece = '/image'; } //remember browse directory $this->meta_data['gallery_dir'] = $dir_piece; //$this->SaveThis(); includeFile('admin/admin_uploaded.php'); admin_uploaded::InlineList($dir_piece); }
function GalleryImages() { global $page, $dataDir, $langmessage; includeFile('admin/admin_uploaded.php'); $page->ajaxReplace = array(); if (isset($_GET['dir'])) { $dir_piece = $_GET['dir']; } elseif (isset($this->meta_data['gallery_dir'])) { $dir_piece = $this->meta_data['gallery_dir']; } else { $dir_piece = '/image'; } $dir_piece = common::WinPath($dir_piece); $dir = $dataDir . '/data/_uploaded' . $dir_piece; $prev_piece = false; while ($dir_piece != '/' && !file_exists($dir)) { $prev_piece = $dir_piece; $dir = dirname($dir); $dir_piece = dirname($dir_piece); } //remember browse directory $this->meta_data['gallery_dir'] = $dir_piece; $this->SaveThis(); //new directory? if ($prev_piece) { $prev_piece = gp_edit::CleanArg($prev_piece); $dir_piece = $prev_piece; $dir = $dataDir . '/data/_uploaded' . $prev_piece; if (!gpFiles::CheckDir($dir)) { message($langmessage['OOPS']); $dir = dirname($dir); $dir_piece = dirname($prev_piece); } } admin_uploaded::InlineList($dir, $dir_piece); }
/** * Add an uploaded plugin * */ function UploadPlugin() { global $langmessage, $dataDir; includeFile('admin/admin_uploaded.php'); $archive = $this->UploadedArchive(); if (!$archive) { return false; } // get plugin name and check file types $list = $archive->ListFiles(); $plugin_name = ''; $remove_path = ''; foreach ($list as $file) { //don't check extensions on folder if ($file['size'] == 0) { continue; } //check extension if (!admin_uploaded::AllowedExtension($file['name'], false)) { msg($langmessage['OOPS'] . ' (File type not allowed:' . htmlspecialchars($file['name']) . ')'); return false; } //plugin name if (strpos($file['name'], 'plugin.js') !== false) { $new_plugin_name = $this->FindPluginName($archive, $file['name']); if (!$new_plugin_name) { continue; } //use the most relevant plugin name $new_path = dirname($file['name']); if (!$plugin_name || strlen($new_path) < strlen($remove_path)) { $plugin_name = $new_plugin_name; $remove_path = $new_path; } } } if (!$this->CanUpload($plugin_name)) { return; } //extract to temporary location $extract_temp = $dataDir . \gp\tool\FileSystem::TempFile('/data/_temp/' . $plugin_name); if (!$archive->extractTo($extract_temp)) { gpFiles::RmAll($extract_temp); msg($langmessage['OOPS'] . ' (Couldn\'t extract to temp location)'); return false; } //move to _ckeditor folder $destination = $dataDir . '/data/_ckeditor/' . $plugin_name; $rename_from = $extract_temp . '/' . ltrim($remove_path, '/'); if (!gpFiles::Replace($rename_from, $destination)) { msg($langmessage['OOPS'] . ' (Not replaced)'); return false; } // save configuration if (!array_key_exists($plugin_name, $this->cke_config['plugins'])) { $this->cke_config['plugins'][$plugin_name] = array('installed' => time()); } $this->cke_config['plugins'][$plugin_name]['updated'] = time(); $this->SaveConfig(); msg($langmessage['SAVED']); }
/** * Update the name of an image in the index when renamed * */ function RenameResized($removed, $added) { $added_img = admin_uploaded::TrimBaseDir($added['realpath']); $removed_img = admin_uploaded::TrimBaseDir($removed['realpath']); $index = array_search($removed_img, gp_resized::$index); if (!$index) { return false; } gp_resized::$index[$index] = $added_img; }