/**
 * check if a file extension is permitted
 *
 * @param string $filePath
 * @param array $validExts
 * @param array $invalidExts
 * @return boolean
 */
function isValidExt($filePath, $validExts, $invalidExts = array())
{
    $tem = array();
    if (sizeof($validExts)) {
        foreach ($validExts as $k => $v) {
            $tem[$k] = strtolower(trim($v));
        }
    }
    $validExts = $tem;
    $tem = array();
    if (sizeof($invalidExts)) {
        foreach ($invalidExts as $k => $v) {
            $tem[$k] = strtolower(trim($v));
        }
    }
    $invalidExts = $tem;
    if (sizeof($validExts) && sizeof($invalidExts)) {
        foreach ($validExts as $k => $ext) {
            if (array_search($ext, $invalidExts) !== false) {
                unset($validExts[$k]);
            }
        }
    }
    if (sizeof($validExts)) {
        if (array_search(strtolower(getFileExt($filePath)), $validExts) !== false) {
            return true;
        } else {
            return false;
        }
    } elseif (array_search(strtolower(getFileExt($filePath)), $invalidExts) === false) {
        return true;
    } else {
        return false;
    }
}
Exemple #2
0
function directoryToArray($abs, $directory, $filterMap = NULL)
{
    $assets = array();
    $dir = $abs . $directory;
    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                if (!is_dir($dir . "/" . $file)) {
                    if ($filterMap) {
                        if (in_array(getFileExt($file), $filterMap)) {
                            if (fileIgnore($file)) {
                                $assets[basename($file)] = get_stylesheet_directory_uri() . $directory . $file;
                            }
                        }
                    } else {
                        if (fileIgnore($file)) {
                            $assets[basename($file)] = get_stylesheet_directory_uri() . $directory . $file;
                        }
                    }
                }
            }
        }
        closedir($handle);
    }
    return $assets;
}
 public static function init($image, $width = 120, $height = 120, $isCheck = false)
 {
     if (!is_file($image)) {
         return false;
     }
     //处理缩略图文件名
     $imageExt = getFileExt($image);
     $toImage = str_replace('.' . $imageExt, '_' . $width . '.' . $imageExt, $image);
     if (is_file(ROOT . $toImage)) {
         return $toImage;
     } elseif ($isCheck) {
         return false;
     }
     //获取图片信息
     self::imageInfo($image);
     //验证是否获取到信息
     if (empty(self::$image_w) || empty(self::$image_h) || empty(self::$image_ext)) {
         return false;
     }
     //如果图片比设置的小就直接返回
     if (self::$image_w <= $width && self::$image_h <= $height) {
         return $image;
     }
     //以原图做画布
     $a = 'imagecreatefrom' . self::$image_ext;
     $original = $a($image);
     if (self::$image_w > self::$image_h) {
         //宽 > 高
         $crop_x = (self::$image_w - self::$image_h) / 2;
         $crop_y = 0;
         $crop_w = $crop_h = self::$image_h;
     } else {
         $crop_x = 0;
         $crop_y = (self::$image_h - self::$image_w) / 2;
         $crop_w = $crop_h = self::$image_w;
     }
     if (!$height) {
         $height = floor(self::$image_h / (self::$image_w / $width));
         $crop_x = 0;
         $crop_y = 0;
         $crop_w = self::$image_w;
         $crop_h = self::$image_h;
     }
     $litter = imagecreatetruecolor($width, $height);
     if (!imagecopyresampled($litter, $original, 0, 0, $crop_x, $crop_y, $width, $height, $crop_w, $crop_h)) {
         return false;
     }
     //保存图片
     $keep = 'image' . self::$image_ext;
     $keep($litter, ROOT . $toImage);
     //关闭图片
     imagedestroy($original);
     imagedestroy($litter);
     return $toImage;
 }
Exemple #4
0
/**
 * 解析json文件
 *
 * @param  {string} $filePath 文件路径
 * @param  {boolean} $isRelatedToMock 是否相对于mock根目录
 * @return {Object}           json对象
 */
function readJson($filePath, $isRelatedToMock = false)
{
    $ext = getFileExt($filePath);
    if (empty($ext)) {
        $filePath = $filePath . '.json';
    }
    if ($isRelatedToMock) {
        $filePath = Conf::$rootDir . '/mock/' . $filePath;
    } else {
        $filePath = Conf::$scriptDir . '/' . $filePath;
    }
    $json = file_get_contents($filePath);
    return json_decode($json, true);
}
function recurseDirectoryWithFilter(&$arrItems, $directory, $recursive, &$filterMap)
{
    if ($handle = opendir($directory)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                if (is_dir($directory . $file)) {
                    if ($recursive) {
                        recurseDirectoryWithFilter($arrItems, $directory . $file . "/", $recursive, $filterMap);
                    }
                } else {
                    if (isset($filterMap[getFileExt($file)])) {
                        $arrItems[] = $directory . $file;
                    }
                }
            }
        }
        closedir($handle);
    }
    return $arrItems;
}
Exemple #6
0
function getCssFileList($cssDir)
{
    $cssDir = rtrim($cssDir, '\\/') . '/';
    $fileList = array();
    //array('源css文件', '源css文件2'...));
    if (is_dir($cssDir)) {
        $dh = opendir($cssDir);
        while (($file = readdir($dh)) !== false) {
            if ($file != '.' && $file != '..') {
                if (is_dir($cssDir . $file)) {
                    $fileList2 = getCssFileList($cssDir . $file);
                    $fileList = array_merge($fileList, $fileList2);
                } else {
                    if (getFileExt($file) == 'css') {
                        $fileList[] = $cssDir . $file;
                    }
                }
            }
        }
        closedir($dh);
    }
    return $fileList;
}
Exemple #7
0
 $history->add($sessionImageInfo);
 if (CONFIG_SYS_DEMO_ENABLE) {
     //demo only
     if (isset($originalSessionImageInfo) && sizeof($originalSessionImageInfo)) {
         $imagePath = $sessionDir . $originalSessionImageInfo['info']['name'];
     } else {
         $imagePath = $sessionDir . uniqid(md5(time())) . "." . getFileExt($_POST['path']);
     }
 } else {
     if ($isSaveAsRequest) {
         //save as request
         //check save to folder if exists
         if (isset($_POST['save_to']) && strlen($_POST['save_to'])) {
             $imagePath = $originalImage;
         } else {
             $imagePath = addTrailingSlash(backslashToSlash($_POST['save_to'])) . $_POST['new_name'] . "." . getFileExt($_POST['path']);
         }
         if (!file_exists($_POST['save_to']) || !is_dir($_POST['save_to'])) {
             $error = IMG_SAVE_AS_FOLDER_NOT_FOUND;
         } elseif (file_exists($imagePath)) {
             $error = IMG_SAVE_AS_NEW_IMAGE_EXISTS;
         } elseif (!preg_match("/^[a-zA-Z0-9_\\- ]+\$/", $_POST['new_name'])) {
             $error = IMG_SAVE_AS_ERR_NAME_INVALID;
         }
     } else {
         //save request
         $imagePath = $originalImage;
     }
 }
 if ($image->saveImage($imagePath)) {
     if (CONFIG_SYS_DEMO_ENABLE) {
 function _createDocs(&$man, &$input)
 {
     $result = new Moxiecode_ResultSet("status,fromfile,tofile,message");
     $config = $man->getConfig();
     if (!$man->isToolEnabled("createdoc", $config)) {
         trigger_error("{#error.no_access}", FATAL);
         die;
     }
     for ($i = 0; isset($input["frompath" . $i]) && isset($input["toname" . $i]); $i++) {
         $fromFile =& $man->getFile($input["frompath" . $i]);
         $ext = getFileExt($fromFile->getName());
         $toFile =& $man->getFile($input["topath" . $i], $input["toname" . $i] . '.' . $ext);
         $toConfig = $toFile->getConfig();
         if (checkBool($toConfig['general.demo'])) {
             $result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.demo}");
             continue;
         }
         if ($man->verifyFile($toFile, "createdoc") < 0) {
             $result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), $man->getInvalidFileMsg());
             continue;
         }
         if (!$toFile->canWrite()) {
             $result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.no_write_access}");
             continue;
         }
         if (!checkBool($toConfig["filesystem.writable"])) {
             $result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.no_write_access}");
             continue;
         }
         if (!$fromFile->exists()) {
             $result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.template_missing}");
             continue;
         }
         if ($fromFile->copyTo($toFile)) {
             // Replace title
             $fields = $input["fields"];
             // Replace all fields
             if ($fields) {
                 // Read all data
                 $stream = $toFile->open('r');
                 $fileData = $stream->readToEnd();
                 $stream->close();
                 // Replace fields
                 foreach ($fields as $name => $value) {
                     $fileData = str_replace('${' . $name . '}', htmlentities($value), $fileData);
                 }
                 // Write file data
                 $stream = $toFile->open('w');
                 $stream->write($fileData);
                 $stream->close();
             }
             $result->add("OK", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#message.createdoc_success}");
         } else {
             $result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.createdoc_failed}");
         }
     }
     return $result->toArray();
 }
Exemple #9
0
// We check if the data was submitted
if ($file && $type) {
    // We define some stuffs
    $type = normalizeFileType($type);
    $dir = JAPPIX_BASE . '/app/' . $type . '/';
    $path = $dir . $file;
    // Read request headers
    $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? trim($_SERVER['HTTP_IF_MODIFIED_SINCE']) : null;
    $if_modified_since = $if_modified_since ? strtotime($if_modified_since) : null;
    // Define the real type if this is a "store" file
    if ($type == 'store') {
        // Rewrite path
        $dir = JAPPIX_BASE . '/store/';
        $path = $dir . $file;
        // Extract the file extension
        switch (getFileExt($file)) {
            // CSS file
            case 'css':
                $type = 'stylesheets';
                break;
                // JS file
            // JS file
            case 'js':
                $type = 'javascripts';
                break;
                // Audio file
            // Audio file
            case 'ogg':
            case 'oga':
            case 'mp3':
                $type = 'sounds';
echo IMG_LBL_SAVE_AS;
?>
</th>
          </tr>
        </thead>
        <tbody>
        	<tr>
          	<th>
            	<label><?php 
echo IMG_LBL_NEW_NAME;
?>
</label>
            </th>
            <td>
            	<input type="text" id="new_name" class="input" name="new_name" value="" />&nbsp;.<?php 
echo getFileExt($path);
?>
            </td>
          </tr>
          <tr>
          	<th>
            	<label><?php 
echo IMG_LBL_SAVE_TO;
?>
</label>
            </th>
            <td>
            	<select class="input" name="save_to" id="save_to"></select>
            </td>
          </tr>
          <tr>
Exemple #11
0
function get_src_img_object($src_dir)
{
    $src;
    if (getFileExt($src_dir) == "gif") {
        $src = ImageCreateFromGIF($src_dir);
    } else {
        if (getFileExt($src_dir) == "jpg" || getFileExt($src_dir) == "jpeg") {
            $src = ImageCreateFromJPEG($src_dir);
        } else {
            if (getFileExt($src_dir) == "png") {
                $src = ImageCreateFromPNG($src_dir);
            }
        }
    }
    return $src;
}
Exemple #12
0
    die("alert('You need to run the installer or rename/remove the \"install\" directory.');");
}
error_reporting(E_ALL ^ E_NOTICE);
require_once "../includes/general.php";
require_once '../classes/Utils/JSCompressor.php';
$compress = true;
// Some PHP installations seems to
// output the dir rather than the current file here
// it gets to /js/ instead of /js/index.php
$baseURL = $_SERVER["PHP_SELF"];
// Hmm, stange?
if (strpos($baseURL, 'default.php/') > 0 || strpos($baseURL, 'index.php/') > 0) {
    $baseURL = $_SERVER["SCRIPT_NAME"];
}
// Is file, get dir
if (getFileExt($baseURL) == "php") {
    $baseURL = dirname($baseURL);
}
// Remove trailing slash if it has any
if ($baseURL && $baseURL[strlen($baseURL) - 1] == '/') {
    $baseURL = substr($baseURL, 0, strlen($baseURL) - 1);
}
// Remove any weird // or /// items
$baseURL = preg_replace('/\\/+/', '/', $baseURL);
if ($compress) {
    $compressor = new Moxiecode_JSCompressor(array('expires_offset' => 3600 * 24 * 10, 'disk_cache' => true, 'cache_dir' => '_cache', 'gzip_compress' => true, 'remove_whitespace' => true, 'charset' => 'UTF-8'));
    // Compress these
    $compressor->addFile('mox.js');
    $compressor->addFile('gz_loader.js');
    $compressor->addContent("mox.defaultDoc = 'index.php';");
    $compressor->addContent('mox.findBaseURL(/(\\/js\\/|\\/js\\/index\\.php)$/);');
$tmp = $_FILES['avatar']['tmp_name'];
$ecode = 0;
// check filesize
if (filesize($tmp) > $config->get('avatar_size') * 1000) {
    $ecode = 1;
}
// check height & width
$size = getimagesize($tmp);
if ($size[0] > $config->get('avatar_height')) {
    $ecode = 2;
}
if ($size[1] > $config->get('avatar_width')) {
    $ecode = 3;
}
// check filetype
$ext = getFileExt($_FILES['avatar']['name']);
$ext = strtolower($ext);
$validExt = strtolower($config->get('avatar_types'));
$validExt = explode(',', $validExt);
if (!in_array($ext, $validExt)) {
    $ecode = 4;
}
if ($ecode > 0) {
    unlink($tmp);
    jsRedirect('usercp.php?action=avatars&ecode=' . $ecode);
}
// everything is good, add the avatar
$file = time() . '-' . $user->id . '.' . $ext;
move_uploaded_file($tmp, './avatars/' . $file);
$id = $user->id;
$type = $_POST['type'];
Exemple #14
0
    switch ($mimetype) {
        case 'image/gif':
            $ext = 'gif';
            break;
        case 'image/jpeg':
            $ext = 'jpg';
            break;
        case 'image/png':
            $ext = 'png';
            break;
        default:
            $ext = null;
    }
    // Get the file extension if could not get it through MIME
    if (!$ext) {
        $ext = getFileExt($file_path);
    }
    if ($ext == 'gif' || $ext == 'jpg' || $ext == 'png') {
        // Resize the image
        resizeImage($file_path, $ext, 1024, 1024);
        // Copy the image
        $thumb = $file_path . '_thumb.' . $ext;
        copy($file_path, $thumb);
        // Create the thumbnail
        if (resizeImage($thumb, $ext, 140, 105)) {
            $thumb_xml = '<thumb>' . htmlspecialchars($location . 'store/share/' . $md5 . '_thumb.' . $ext) . '</thumb>';
        }
    }
    // Return the path to the file
    exit('<jappix xmlns=\'jappix:file:post\'>
		<href>' . htmlspecialchars($location . '?m=download&file=' . $md5 . '&key=' . $key . '&ext=.' . $ext) . '</href>
          	<th colspan="2"><?php echo IMG_LBL_SAVE_AS; ?></th>
          </tr>
        </thead>
        <tbody>
        	<tr>
          	<th>
            	<label><?php echo IMG_LBL_NEW_NAME; ?></label>
            </th>
            <td>
            	<input type="text" id="new_name" class="input" name="new_name" value="" />
              &nbsp;.&nbsp;<select id="ext" name="ext">
              <?php
								foreach(getValidTextEditorExts() as $v)
								{
									?>
									<option value="<?php echo $v; ?>" <?php echo (strtolower($v) == strtolower(getFileExt($path))?'selected':''); ?>><?php echo $v; ?></option>
									<?php
								}
							?>
              </select>
            </td>
          </tr>
          <tr>
          	<th>
            	<label><?php echo IMG_LBL_SAVE_TO; ?></label>
            </th>
            <td>
            	<select class="input" name="save_to" id="save_to">
              	
              </select>
            </td>
Exemple #16
0
function checkFile($filename)
{
    $ext = getFileExt($filename);
    $result_boolean = false;
    if (!eregi("htm", $ext) && !eregi("php", $ext)) {
        $result_boolean = true;
    }
    return $result_boolean;
}
function build_blocks($items, $folder)
{
    global $ignore_file_list, $ignore_ext_list, $sort_by, $toggle_sub_folders;
    $objects = array();
    $objects['directories'] = array();
    $objects['files'] = array();
    foreach ($items as $c => $item) {
        if ($item == ".." or $item == ".") {
            continue;
        }
        // IGNORE FILE
        if (in_array($item, $ignore_file_list)) {
            continue;
        }
        if ($folder) {
            $item = "{$folder}/{$item}";
        }
        $file_ext = getFileExt($item);
        // IGNORE EXT
        if (in_array($file_ext, $ignore_ext_list)) {
            continue;
        }
        // DIRECTORIES
        if (is_dir($item)) {
            $objects['directories'][] = $item;
            continue;
        }
        // FILE DATE
        $file_time = date("U", filemtime($item));
        // FILES
        $objects['files'][$file_time . "-" . $item] = $item;
    }
    foreach ($objects['directories'] as $c => $file) {
        display_block($file);
        if ($toggle_sub_folders) {
            $sub_items = (array) scandir($file);
            if ($sub_items) {
                echo "<div class='sub' data-folder=\"{$file}\">";
                build_blocks($sub_items, $file);
                echo "</div>";
            }
        }
    }
    // SORT BEFORE LOOP
    if ($sort_by == "date_asc") {
        ksort($objects['files']);
    } elseif ($sort_by == "date_desc") {
        krsort($objects['files']);
    } elseif ($sort_by == "name_asc") {
        natsort($objects['files']);
    } elseif ($sort_by == "name_desc") {
        arsort($objects['files']);
    }
    foreach ($objects['files'] as $t => $file) {
        $fileExt = getFileExt($file);
        if (in_array($file, $ignore_file_list)) {
            continue;
        }
        if (in_array($fileExt, $ignore_ext_list)) {
            continue;
        }
        display_block($file);
    }
}
Exemple #18
0
		<div id="windowSaveAs" class="jqmWindow" style="display:none">
    	<a href="#" class="jqmClose" id="windowSaveClose"><?php echo LBL_ACTION_CLOSE; ?></a>
      <form id="formSaveAs" name="formSaveAs" action="" method="post">
    	<table class="tableForm" cellpadding="0" cellspacing="0">
      	<thead>
        	<tr>
          	<th colspan="2"><?php echo IMG_LBL_SAVE_AS; ?></th>
          </tr>
        </thead>
        <tbody>
        	<tr>
          	<th>
            	<label><?php echo IMG_LBL_NEW_NAME; ?></label>
            </th>
            <td>
            	<input type="text" id="new_name" class="input" name="new_name" value="" />&nbsp;.<?php echo getFileExt($path); ?>
            </td>
          </tr>
          <tr>
          	<th>
            	<label><?php echo IMG_LBL_SAVE_TO; ?></label>
            </th>
            <td>
            	<select class="input" name="save_to" id="save_to"></select>
            </td>
          </tr>
          <tr>
          	<th>&nbsp;
            </th>
            <td>
            <span class="comments">*</span>
Exemple #19
0
    readfile($file_path);
    unlink($file_path);
} else {
    if (isset($_FILES['file']) && !empty($_FILES['file']) && (isset($_POST['id']) && !empty($_POST['id'])) && (isset($_POST['location']) && !empty($_POST['location']))) {
        header('Content-Type: text/xml; charset=utf-8');
        // Get the file name
        $tmp_filename = $_FILES['file']['tmp_name'];
        $filename = $_FILES['file']['name'];
        // Get the location
        if (HOST_UPLOAD) {
            $location = HOST_UPLOAD . '/';
        } else {
            $location = $_POST['location'];
        }
        // Get the file new name
        $ext = getFileExt($filename);
        $new_name = preg_replace('/(^)(.+)(\\.)(.+)($)/i', '$2', $filename);
        // Define some vars
        $name = sha1(time() . $filename);
        $path = JAPPIX_BASE . '/tmp/send/' . $name . '.' . $ext;
        // Forbidden file?
        if (!isSafeAllowed($filename) || !isSafeAllowed($name . '.' . $ext)) {
            exit('<jappix xmlns=\'jappix:file:send\'>
    <error>forbidden-type</error>
    <id>' . htmlspecialchars($_POST['id']) . '</id>
</jappix>');
        }
        // File upload error?
        if (!is_uploaded_file($tmp_filename) || !move_uploaded_file($tmp_filename, $path)) {
            exit('<jappix xmlns=\'jappix:file:send\'>
    <error>move-error</error>
Exemple #20
0
         $logos_arr_4_name = $_FILES['logo_own_4_location']['name'];
         $logos_arr_4_tmp = $_FILES['logo_own_4_location']['tmp_name'];
     }
     // File infos array
     $logos = array(array($logos_arr_1_name, $logos_arr_1_tmp, JAPPIX_BASE . '/store/logos/desktop_home.png'), array($logos_arr_2_name, $logos_arr_2_tmp, JAPPIX_BASE . '/store/logos/desktop_app.png'), array($logos_arr_3_name, $logos_arr_3_tmp, JAPPIX_BASE . '/store/logos/mobile.png'), array($logos_arr_4_name, $logos_arr_4_tmp, JAPPIX_BASE . '/store/logos/mini.png'));
     // Check for errors
     $logo_error = false;
     $logo_not_png = false;
     $logo_anything = false;
     foreach ($logos as $sub_array) {
         // Nothing?
         if (!$sub_array[0] || !$sub_array[1]) {
             continue;
         }
         // Not an image?
         if (getFileExt($sub_array[0]) != 'png') {
             $logo_not_png = true;
             continue;
         }
         // Upload error?
         if (!move_uploaded_file($sub_array[1], $sub_array[2])) {
             $logo_error = true;
             continue;
         }
         $logo_anything = true;
     }
     // Not an image?
     if ($logo_not_png) {
         ?>
 <p class="info smallspace fail"><?php 
         _e("This is not a valid image, please use the PNG format!");
 }
 // Local music search
 $xml = '<data>';
 $searchquery = strtolower($searchquery);
 // Escape the regex special characters
 $searchquery = escapeRegex($searchquery);
 // Search in the directory
 $repertory = '../store/music/';
 $scan = scandir($repertory);
 foreach ($scan as $current) {
     // This file match our query!
     if (is_file($repertory . $current) && $current && preg_match('/(^|\\s|\\[)(' . $searchquery . ')(.+)?(\\.(og(g|a)|mp3|wav))$/i', strtolower($current))) {
         // Get the basic informations
         $title = preg_replace('/^(.+)(\\.)(og(g|a)|mp3|wav)$/i', '$1', $current);
         $url = $location . 'store/music/' . $current;
         $ext = getFileExt($current);
         $id = md5($url);
         // Get the MIME type
         if ($ext == 'mp3') {
             $type = 'audio/mpeg';
         } else {
             if ($ext == 'wav') {
                 $type = 'audio/x-wav';
             } else {
                 $type = 'audio/ogg';
             }
         }
         // Get the advanced informations
         $locked_title = $title;
         $artist = '';
         $source = '';
Exemple #22
0
 /**
  * get next available file name
  *
  * @param string $fileToMove the path of the file will be moved to
  * @param string $destFolder the path of destination folder
  * @return string
  */
 function getNextAvailableFileName($fileToMove, $destFolder)
 {
     $folderPath = addslashes(backslashToSlash(getParentPath($fileToMove)));
     $destFolder = addslashes(backslashToSlash(getParentPath($destFolder)));
     $finalPath = $destFolder . basename($fileToMove);
     if (file_exists($fileToMove)) {
         if (is_file()) {
             $fileExt = getFileExt($fileToMove);
             $fileBaseName = basename($fileToMove, '.' . $fileExt);
             $count = 1;
             while (file_exists($destFolder . $fileBaseName . $count . "." . $fileExt)) {
                 $count++;
             }
             $filePath = $destFolder . $fileBaseName . $count . "." . $fileExt;
         } elseif (is_dir()) {
             $folderName = basename($fileToMove);
             $count = 1;
             while (file_exists($destFolder . $folderName . $count)) {
                 $count++;
             }
             $filePath = $destFolder . $fileBaseName . $count;
         }
     }
     return $finalPath;
 }
*/
// Someone is trying to hack us?
if (!defined('JAPPIX_BASE')) {
    exit;
}
// Music upload?
if (isset($_POST['upload'])) {
    // Get the file path
    $name_music = $_FILES['music_file']['name'];
    $temp_music = $_FILES['music_file']['tmp_name'];
    // Any special name submitted?
    if (isset($_POST['music_title']) && !empty($_POST['music_title'])) {
        // Add a form var
        $music_title = $_POST['music_title'];
        // Get the file extension
        $ext_music = getFileExt($name_music);
        // New name
        $name_music = '';
        // Add the artist name?
        if (isset($_POST['music_artist']) && !empty($_POST['music_artist'])) {
            // Add a form var
            $music_artist = $_POST['music_artist'];
            // Add the current POST var to the global string
            $name_music .= $_POST['music_artist'] . ' - ';
        }
        // Add the music title
        $name_music .= $_POST['music_title'];
        // Add the album name?
        if (isset($_POST['music_album']) && !empty($_POST['music_album'])) {
            // Add a form var
            $music_album = $_POST['music_album'];
Exemple #24
0
/**
 * ajax save name
 * @author Logan Cai (cailongqun [at] yahoo [dot] com [dot] cn)
 * @link www.phpletter.com
 * @since 22/May/2007
 *
 */
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "inc" . DIRECTORY_SEPARATOR . "config.php";
$error = '';
$path = addTrailingSlash(backslashToSlash($_POST['folder'])) . $_POST['name'];
if (CONFIG_SYS_VIEW_ONLY || !CONFIG_OPTIONS_EDITABLE) {
    $error = SYS_DISABLED;
} elseif (isset($_POST['save_as_request'])) {
    if (!preg_match('/^[a-zA-Z0-9_\\-.]+$/', $_POST['name'])) {
        $error = TXT_SAVE_AS_ERR_NAME_INVALID;
    } elseif (array_search(strtolower(getFileExt($_POST['name'])), getValidTextEditorExts()) === false) {
        $error = TXT_DISALLOWED_EXT;
    } elseif (!isUnderRoot($_POST['folder'])) {
        $error = ERR_FOLDER_PATH_NOT_ALLOWED;
    } else {
        if (!empty($_POST['save_as_request'])) {
            //save as request
            if (file_exists($path)) {
                $error = TXT_FILE_EXIST;
            } else {
                if (($fp = @fopen($path, 'w+')) !== false) {
                    if (@fwrite($fp, $_POST['text'])) {
                        @fclose($fp);
                    } else {
                        $error = TXT_CONTENT_WRITE_FAILED;
                    }
 /**
  * Lists files.
  */
 function _listFiles(&$man, $input)
 {
     $result = new Moxiecode_ResultSet("name,path,size,type,created,modified,attribs,custom");
     $config = $man->getConfig();
     $files = array();
     $refilter = false;
     $rootNames = $man->_getRootNames();
     $filterRootPath = isset($input["root_path"]) && $input["root_path"] != null ? $man->toAbsPath($man->decryptPath($input["root_path"])) : null;
     if (isset($input["path"]) && $input["path"]) {
         // URL specified
         if (isset($input["url"]) && $input["path"] == '{default}') {
             $input["path"] = $man->convertURIToPath($input["url"]);
         }
         if (isset($input['remember_last_path'])) {
             if ($input['remember_last_path'] != 'auto') {
                 $remember = checkBool($input['remember_last_path']);
             } else {
                 $remember = checkBool($config['general.remember_last_path']);
             }
             if ($remember) {
                 if (isset($_COOKIE["MCManager_" . $man->getType() . "_lastPath"]) && $input["path"] == '{default}') {
                     $tmpPath = $_COOKIE["MCManager_" . $man->getType() . "_lastPath"];
                     if ($man->getFSFromPath($tmpPath) == "file" && $tmpPath) {
                         $input["path"] = $tmpPath;
                     }
                 } else {
                     if ($man->getFSFromPath($input["path"]) == "file") {
                         setcookie("MCManager_" . $man->getType() . "_lastPath", $input["path"], time() + 3600 * 24 * 30);
                     }
                     // 30 days
                 }
             }
         }
         $input["path"] = $man->toAbsPath($man->decryptPath($input["path"]));
         $result->setHeader("path", $man->encryptPath($input["path"]));
         $result->setHeader("visual_path", checkBool($config['general.user_friendly_paths']) ? $man->toVisualPath($input["path"]) : $man->encryptPath($input["path"]));
         // Move path inside rootpath if it's localfs
         if ($filterRootPath && $man->getFSFromPath($input["path"]) == 'file') {
             if (!$man->isChildPath($filterRootPath, $input["path"])) {
                 $input["path"] = $filterRootPath;
             }
             $result->setHeader("path", $man->encryptPath($input["path"]));
             $result->setHeader("visual_path", checkBool($config['general.user_friendly_paths']) ? $man->toVisualPath($input["path"], $filterRootPath) : $man->encryptPath($input["path"]));
         }
         // Not valid path use default path
         if ($man->getFSFromPath($input["path"]) == 'file' && !$man->verifyPath($input["path"])) {
             $input["path"] = $config['filesystem.path'];
             $result->setHeader("path", $man->encryptPath($input["path"]));
             $result->setHeader("visual_path", checkBool($config['general.user_friendly_paths']) ? $man->toVisualPath($input["path"]) : $man->encryptPath($input["path"]));
         }
         $file =& $man->getFile($input["path"]);
         $config = $file->getConfig();
         $attribs = ($file->canRead() && checkBool($config["filesystem.readable"]) ? "R" : "-") . ($file->canWrite() && checkBool($config["filesystem.writable"]) ? "W" : "-");
         $result->setHeader("attribs", $attribs);
         $files = $this->_listDefault($man, $file, $input, $result, $filterRootPath);
     } else {
         trigger_error("ListFiles input not valid.", FATAL);
         die;
     }
     if (isset($input["page_size"])) {
         $pages = ceil(count($files) / $input["page_size"]);
         // Setup response
         $result->setHeader("pages", $pages > 1 ? $pages : 1);
         $result->setHeader("count", count($files));
         if (!isset($input["page"])) {
             $input["page"] = 0;
         }
         // Remove non visible files
         $files = array_slice($files, $input["page"] * $input["page_size"], $input["page_size"]);
     }
     // Add directories
     $listFS = $man->getFSFromPath($input["path"]);
     foreach ($files as $file) {
         // Remove files below root
         if ($filterRootPath && $listFS == 'file') {
             if (!$man->isChildPath($filterRootPath, $file->getAbsolutePath())) {
                 continue;
             }
         }
         // Setup fields
         $custom = array();
         // Attribs: R = Read, W = Write (cut/delete/rename), D = Download, S = Stream/Preview, I = Insert
         $attribs = ($file->canRead() && checkBool($config["filesystem.readable"]) ? "R" : "-") . ($file->canWrite() && checkBool($config["filesystem.writable"]) ? "W" : "-");
         $cdate = date($config['filesystem.datefmt'], $file->getCreationDate());
         $mdate = date($config['filesystem.datefmt'], $file->getLastModified());
         $filePath = $man->encryptPath($file->getAbsolutePath());
         if ($file->isFile()) {
             $type = getFileExt($file->getName());
         } else {
             if (isset($input["count_children"]) && checkBool($input["count_children"])) {
                 $this->_countChildren($file, $custom);
             }
             $type = "folder";
         }
         $man->dispatchEvent("onCustomInfo", array(&$file, "list", &$custom));
         // Special treatment of roots
         $name = $file->getName();
         if ($input["path"] == "root:///") {
             foreach ($rootNames as $rootPath => $rootName) {
                 if ($file->getAbsolutePath() == $rootPath) {
                     $name = $rootName;
                     break;
                 }
             }
         }
         $result->add(utf8_encode($name), $filePath, $file->getLength(), $type, $cdate, $mdate, $attribs, $custom);
     }
     if (isset($input["config"])) {
         $result->setConfig($man->getJSConfig($config, $input["config"]));
     }
     return $result->toArray();
 }
Exemple #26
0
        }
    }
}
if (empty($_POST) || $baddata) {
    if (!empty($_POST) && $text->is_missing_required) {
        foreach ($text->missing_fields as $miss) {
            $problems[] = $l['missing-field'] . $miss;
        }
        $baddata = true;
    }
    // build timezone options.
    $timezone = build_timezone_list($config->get('server_timezone'));
    // build template preview <select> data
    $dir = dir(template_folder);
    while ($file = $dir->read()) {
        if (strtolower(getFileExt($file)) == 'gif') {
            $preview[] = $file;
        }
    }
    $dir->close();
    $st = '<select name="template" onchange="document.images.temlpatePreview.src = \'templates/\' + this[this.selectedIndex].value + \'.gif\';">';
    $st .= "\n";
    foreach ($preview as $img) {
        $name = str_replace('_', ' ', $img);
        $name = substr($name, 0, -4);
        // to remove .gif
        $img = substr($img, 0, -4);
        $st .= '<option value="' . $img . '">' . $name . '</option>' . "\n";
        //$st .= '<option value="./templates/' . $img . '">' . $name . "</option>\n";
    }
    $st .= "\n</select>\n";
                    <label><?php 
echo IMG_LBL_NEW_NAME;
?>
</label>
                </th>
                <td>
                    <input type="text" id="new_name" class="input" name="new_name" value=""/>
                    &nbsp;.&nbsp;<select id="ext" name="ext">
                        <?php 
foreach (getValidTextEditorExts() as $v) {
    ?>
                            <option value="<?php 
    echo $v;
    ?>
" <?php 
    echo strtolower($v) == strtolower(getFileExt($path)) ? 'selected' : '';
    ?>
><?php 
    echo $v;
    ?>
</option>
                        <?php 
}
?>
                    </select>
                </td>
            </tr>
            <tr>
                <th>
                    <label><?php 
echo IMG_LBL_SAVE_TO;
 function _streamThumb(&$man, $input)
 {
     if (!$man->verifyPath($input["path"]) < 0) {
         trigger_error("Path verification failed.", FATAL);
         die;
     }
     $path = $man->decryptPath($input["path"]);
     $file =& $man->getFile($path);
     $ext = getFileExt($file->getName());
     $config = $file->getConfig();
     $urlprefix = $man->toUnixPath($config['preview.urlprefix']);
     $urlsuffix = $man->toUnixPath($config['preview.urlsuffix']);
     // NOTE: Verify more stuff here before proceeding.
     if ($man->verifyFile($file, "thumbnail", $config) < 0) {
         trigger_error("Path verification failed.", FATAL);
         die;
     }
     //$imageutils = new $config['thumbnail'];
     //$canEdit = $imageutils->canEdit($ext);
     // Check if we have an EXIF JPG file.
     if ($config['thumbnail.use_exif'] == true && function_exists("exif_thumbnail") && (strtolower($ext) == "jpg" || strtolower($ext) == "jpeg")) {
         $image = @exif_thumbnail($file->getAbsolutePath(), $exif_width, $exif_height, $exif_type);
         if ($image !== false) {
             header('Content-type: ' . image_type_to_mime_type($exif_type));
             echo $image;
             return null;
         }
     }
     $thumbnail = $this->_createThumb($man, $file);
     if ($thumbnail != false) {
         header('Content-type: ' . mapMimeTypeFromUrl($thumbnail->getName(), "../" . $config['stream.mimefile']));
         if (!readfile($thumbnail->getAbsolutePath())) {
             header("Location: " . $urlprefix . $man->convertPathToURI($thumbnail->getAbsolutePath()) . $urlsuffix);
         }
     } else {
         header('Content-type: ' . mapMimeTypeFromUrl($file->getName(), "../" . $config['stream.mimefile']));
         if (!readfile($file->getAbsolutePath())) {
             header("Location: " . $urlprefix . $man->convertPathToURI($file->getAbsolutePath()) . $urlsuffix);
         }
     }
     return null;
 }
function browseFolder($folder, $mode)
{
    // Scan the target directory
    $directory = JAPPIX_BASE . '/store/' . $folder;
    $scan = scandir($directory);
    $scan = array_diff($scan, array('.', '..', '.svn', 'index.html'));
    $keep_get = keepGet('(s|b|k)', false);
    // Odd/even marker
    $marker = 'odd';
    // Not in the root folder: show previous link
    if (strpos($folder, '/') != false) {
        // Filter the folder name
        $previous_folder = substr($folder, 0, strrpos($folder, '/'));
        echo '<div class="one-browse previous manager-images"><a href="./?b=' . $mode . '&s=' . urlencode($previous_folder) . $keep_get . '">' . T_("Previous") . '</a></div>';
    }
    // Empty or non-existing directory?
    if (!count($scan) || !is_dir($directory)) {
        echo '<div class="one-browse ' . $marker . ' alert manager-images">' . T_("The folder is empty.") . '</div>';
        return false;
    }
    // Echo the browsing HTML code
    foreach ($scan as $current) {
        // Generate the item path$directory
        $path = $directory . '/' . $current;
        $file = $folder . '/' . $current;
        // Directory?
        if (is_dir($path)) {
            $type = 'folder';
            $href = './?b=' . $mode . '&s=' . urlencode($file) . $keep_get;
            $target = '';
        } else {
            $type = getFileType(getFileExt($path));
            $href = $path;
            $target = ' target="_blank"';
        }
        echo '<div class="one-browse ' . $marker . ' ' . $type . ' manager-images"><a href="' . $href . '"' . $target . '>' . htmlspecialchars($current) . '</a><input type="checkbox" name="element_' . md5($file) . '" value="' . htmlspecialchars($file) . '" /></div>';
        // Change the marker
        if ($marker == 'odd') {
            $marker = 'even';
        } else {
            $marker = 'odd';
        }
    }
    return true;
}
         break;
     case "flip":
         if (!$image->flip($_POST['flip_angle'])) {
             $error = IMG_SAVE_FLIP_FAILED;
         }
         break;
     case "rotate":
         if (!$image->rotate((int) $_POST['angle'])) {
             $error = IMG_SAVE_ROTATE_FAILED;
         }
         break;
     default:
         $error = IMG_SAVE_UNKNOWN_MODE;
 }
 if (empty($error)) {
     $sessionNewPath = $session->getSessionDir() . uniqid(md5(time())) . "." . getFileExt($_POST['path']);
     if (!@copy($_POST['path'], $sessionNewPath)) {
         $error = IMG_SAVE_BACKUP_FAILED;
     } else {
         addSessionHistory($_POST['path'], $sessionNewPath);
         if ($image->saveImage($_POST['path'])) {
             $imageInfo = $image->getFinalImageInfo();
             $info .= ",width:" . $imageInfo['width'] . "\n";
             $info .= ",height:" . $imageInfo['height'] . "\n";
             $info .= ",size:'" . transformFileSize($imageInfo['size']) . "'\n";
         } else {
             $error = IMG_SAVE_FAILED;
         }
     }
 } else {
     //$image->DestroyImages();