function smarty_modifier_abbrnum($string, $tail = 2) { if (intval($string) < 1000) { return $string; } else { return abbrnum($string, $tail, array('', 'K', 'M', 'B'), 1000); } }
if (!in_array($t, array('csv', 'xml', 'dom', 'img'))) { $t = 'img'; } $list = array(); // first build a list of icons from our local directory $dir = $ps->conf['theme']['icons_dir']; $url = $ps->conf['theme']['icons_url']; if ($dh = @opendir($dir)) { while (($file = @readdir($dh)) !== false) { if (substr($file, 0, 1) == '.') { continue; } // skip dot files $fullfile = catfile($dir, $file); if (is_dir($fullfile)) { continue; } // skip directories if (is_link($fullfile)) { continue; } // skip symlinks $info = getimagesize($fullfile); $size = @filesize($fullfile); $list[$file] = array('filename' => rawurlencode($file), 'url' => catfile($url, rawurlencode($file)), 'desc' => ps_escape_html(sprintf("%s - %dx%d - %s", $file, $info[0], $info[1], abbrnum($size))), 'size' => $size, 'width' => $info[0], 'height' => $info[1], 'attr' => $info[3]); } @closedir($dh); } ksort($list); $fields = array('filename', 'url', 'size', 'width', 'height'); output_list($t, $list, $fields, $idstr);
function validate_img($file) { global $form, $cms, $ps; $c = $ps->conf['theme']['icons']; $ext = $ps->conf['theme']['images']['search_ext']; if (empty($ext)) { $ext = 'png, jpg, gif'; } $list = explode(',', $ext); $list = array_map('trim', $list); $match = '\\.(' . implode('|', $list) . ')$'; $res = true; if (!preg_match("/{$match}/", $file['name'])) { return $cms->trans("Image type must be one of the following:") . ' <b>' . implode(', ', $list) . '</b>'; # } elseif ($file['info'][2] > 3) { # return $cms->trans("Image type is invalid"); } elseif ($c['max_size'] and $file['size'] > $c['max_size']) { return $cms->trans("Image size is too large") . " (" . abbrnum($file['size']) . " > " . abbrnum($c['max_size']) . ")"; } elseif ($file['info'][0] > $c['max_width'] or $file['info'][1] > $c['max_height']) { return $cms->trans("Image dimensions are too big") . " ({$file['info'][0]}x{$file['info'][1]} > " . $c['max_width'] . "x" . $c['max_height'] . ")"; } elseif (substr($file['name'], 0, 1) == '.') { return $cms->trans("Image name can not start with a period"); } return $res; }
function abbrnum0($string, $tail = 0) { if (intval($string) < 1000) { return $string; } else { return abbrnum($string, $tail, array('', 'K', 'M', 'B'), 1000); } }