Ejemplo n.º 1
0
function showThumb($photo)
{
    $thumbPath = get_thumb_path($photo);
    $imgsize = getSize($thumbPath);
    $output = '<img src="' . urldecode($thumbPath) . '" alt="' . get_image_iptc($photo, "caption") . '" title="' . get_image_iptc($photo, "caption") . '" ' . $imgsize[3] . ' />';
    return $output;
}
Ejemplo n.º 2
0
function get_dir_content($path = '', $options = '')
{
    /*
    	Get the content from dir
    	@path - path to directory
    	@options - associative array with options to out
    		options[dirs] - bool get information about folders default true
    		options[dir_col] - array specify information to get for dir, posible values - empty, readable, sample - array('empty', 'readable', 'date') default null
    		options[files] - bool get information about files default true
    		options[file_col] - array specify information to get for file, posible values - filesize, date, img_size, thumb, sample - array('filesize', 'date', 'img_size', 'thumb') default null
    			options[file_col][thumb] - path to thumbnail of file accerding of curent configuration, if file not found and it support - return empty strinf, if not support - return path to file
    		options[sort] - string sort type (date, filesize) default null
    		options[sort_r] - bool Descending of sorting default false
    		options[allowed_ext] - array containt the extension of files to out, sample - array('gz', 'zip') default all out
    		options[clear] - bool using clearstatcache(); function before read the dir default true
    		options['extra_inf'] - associative array with additional info to out
    			extra_inf['is_writable'] - get the write premission on current path, default false
    	return a array('dir', 'files', 'inf') or if the options[file_col] specify the out array('dirs', 'files'=>array('name', specified colum)), where 'extra_inf' array key - key containt additional info such as write premmision as 'inf'=>array('is_writable'=>1, 'option_name'=>option_value,...)
    */
    // Apply options
    if (isset($options) && !empty($options) && is_array($options)) {
        $get_dirs = array_key_exists('dirs', $options) ? (bool) $options['dirs'] : true;
        $dir_col = array_key_exists('dir_col', $options) && (is_array($options['dir_col']) || is_string($options['dir_col'])) ? $options['dir_col'] : null;
        $get_files = array_key_exists('files', $options) ? (bool) $options['files'] : true;
        $file_col = array_key_exists('file_col', $options) && (is_array($options['file_col']) || is_string($options['file_col'])) ? $options['file_col'] : null;
        $sort_type = array_key_exists('sort', $options) ? $options['sort'] : null;
        $sort_reverse = array_key_exists('sort_r', $options) ? (bool) $options['sort_r'] : false;
        $allowed_ext = array_key_exists('allowed_ext', $options) && is_array($options['allowed_ext']) && !empty($options['allowed_ext']) ? $options['allowed_ext'] : null;
        $clear_cache = array_key_exists('clear', $options) ? (bool) $options['clear'] : true;
        // Additional info array
        if (isset($options['extra_inf']) && !empty($options['extra_inf']) && is_array($options['extra_inf'])) {
            $extra_inf = $options['extra_inf'];
            $extra_inf['is_writable'] = array_key_exists('is_writable', $extra_inf) ? (bool) $extra_inf['is_writable'] : false;
        }
    } else {
        $get_dirs = true;
        $dir_col = null;
        $get_files = true;
        $file_col = null;
        $sort_type = null;
        $sort_reverse = false;
        $allowed_ext = null;
        $clear_cache = true;
        $extra_inf['is_writable'] = false;
    }
    if ($clear_cache) {
        clearstatcache();
    }
    $dirs = array();
    // Direcrotys in dir
    $files = array();
    // Files in dir
    $inf = array();
    // Additional information array
    $files_size = array();
    // File size information array
    $files_date = array();
    // File date information array
    $imgs_size = array();
    // Image size information array
    $thumb = array();
    // Image thumbnail information array
    /*------- Check must be a external and function must accept evrefing - in theory -----------------*/
    global $CFG;
    $path = realpath($path) . DIRECTORY_SEPARATOR;
    if (!is_subdir($CFG->imgUploadDir, $path)) {
        // Exit if try to read above root dir
        return;
    }
    if (is_readable($path) && ($handle = opendir($path))) {
        $n = 0;
        while (false !== ($file = readdir($handle))) {
            if ($file === '.' || $file === '..') {
                continue;
            }
            $n++;
            if ($get_dirs && is_dir($path . $file)) {
                if (isset($sort_type) && $sort_type == 'date') {
                    $key = filemtime($path . $file) . '_' . $n;
                } else {
                    $key = $n;
                }
                $dirs[$key] = $file;
                if (isset($dir_col)) {
                    if (is_array($dir_col) && in_array('empty', $dir_col) || $dir_col === 'empty') {
                        $dirs_empty[$file] = intval(folder_is_empty($path . $file));
                    }
                    if (is_array($dir_col) && in_array('readable', $dir_col) || $dir_col === 'readable') {
                        $dirs_readable[$file] = intval(is_readable($path . $file));
                    }
                    if (is_array($dir_col) && in_array('date', $dir_col) || $dir_col === 'date') {
                        $dirs_date[$file] = intval(filemtime($path . $file));
                    }
                }
            } else {
                if ($get_files && is_file($path . $file) && (!isset($allowed_ext) || in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), $allowed_ext))) {
                    if (isset($sort_type) && $sort_type == 'date') {
                        $key = filemtime($path . $file) . '_' . $n;
                    } elseif (isset($sort_type) && $sort_type == 'filesize') {
                        $key = filesize($path . $file) . '_' . $n;
                    } else {
                        $key = $n;
                    }
                    $files[$key] = $file;
                    if (isset($file_col)) {
                        if (is_array($file_col) && in_array('filesize', $file_col) || $file_col === 'filesize') {
                            $files_size[$file] = filesize($path . $file);
                        }
                        if (is_array($file_col) && in_array('date', $file_col) || $file_col === 'date') {
                            $files_date[$file] = filemtime($path . $file);
                        }
                        if (is_array($file_col) && in_array('img_size', $file_col) || $file_col === 'img_size') {
                            if (is_readable($path . $file) && extension_loaded('gd') && function_exists('getimagesize')) {
                                $img_size = getimagesize($path . $file);
                                if ($img_size !== false) {
                                    $imgs_size[$file] = $img_size;
                                }
                            }
                        }
                        if (is_array($file_col) && in_array('thumb', $file_col) || $file_col === 'thumb') {
                            $file_thumb = get_thumb_path($path . $file);
                            if (!empty($file_thumb)) {
                                $thumb[$file] = $file_thumb;
                            }
                        }
                    }
                }
            }
        }
        closedir($handle);
    }
    // Sort
    if (isset($sort_type) && $sort_type === 'date') {
        ksort($dirs, SORT_NUMERIC);
        ksort($files, SORT_NUMERIC);
    } elseif (isset($sort_type) && $sort_type === 'filesize') {
        natcasesort($dirs);
        ksort($files, SORT_NUMERIC);
    } else {
        natcasesort($dirs);
        natcasesort($files);
    }
    // Order
    if ($sort_reverse && isset($sort_type) && $sort_type !== 'filesize') {
        $dirs = array_reverse($dirs);
    }
    if ($sort_reverse) {
        $files = array_reverse($files);
    }
    // Rebild index
    $dirs = array_values($dirs);
    if (isset($dir_col)) {
        $n = 0;
        $dir = array();
        foreach ($dirs as $key => $val) {
            $dir[$n]['name'] = $dirs[$key];
            if (is_array($dir_col) && in_array('empty', $dir_col) || $dir_col === 'empty') {
                $dir[$n]['empty'] = $dirs_empty[$val];
            }
            if (is_array($dir_col) && in_array('readable', $dir_col) || $dir_col === 'readable') {
                $dir[$n]['readable'] = $dirs_readable[$val];
            }
            if (is_array($dir_col) && in_array('date', $dir_col) || $dir_col === 'date') {
                $dir[$n]['date'] = $dirs_date[$val];
            }
            $n++;
        }
        $dirs = $dir;
        unset($dir);
    }
    $files = array_values($files);
    if (isset($file_col)) {
        $n = 0;
        $file = array();
        foreach ($files as $key => $val) {
            $file[$n]['name'] = $files[$key];
            if (isset($files_size[$val])) {
                $file[$n]['filesize'] = $files_size[$val];
            }
            if (isset($files_date[$val])) {
                $file[$n]['date'] = $files_date[$val];
            }
            if (isset($imgs_size[$val]) && is_array($imgs_size[$val])) {
                $file[$n]['img_size'] = $imgs_size[$val][0] . 'x' . $imgs_size[$val][1];
            }
            if (isset($thumb[$val]) && !empty($thumb[$val])) {
                $file[$n]['thumb'] = $thumb[$val];
            }
            $n++;
        }
        $files = $file;
        unset($file);
    }
    if (isset($extra_inf) && !empty($extra_inf) && is_array($extra_inf)) {
        if (in_array('is_writable', $extra_inf) && $extra_inf['is_writable'] === true) {
            $inf['is_writable'] = (int) is_writable($path);
        }
        unset($extra_inf);
    }
    return array('dirs' => $dirs, 'files' => $files, 'inf' => $inf);
}