function rub_get($type, $id, $exts) { if (!$type) { return; } $files = rub_list('~' . $type . '/', 0, 0, $exts); $res = $files[$id]; if (!$res) { $res = array(); } return $res; }
public static function find($dir, $id, $what = 'articles') { if ($what == 'images') { $exts = array('jpg', 'gif', 'png'); } if ($what == 'articles') { $exts = array('docx', 'mht', 'tpl', 'html', 'txt', 'php'); } if ($what == 'image') { $exts = array('jpg', 'gif', 'png'); } if ($what == 'article') { $exts = array('docx', 'mht', 'tpl', 'html', 'txt', 'php'); } if ($what == 'dir') { $exts = array(); } $files = rub_list($dir, 0, 0, $exts); if (isset($files[$id])) { $files[$id]['idfinded'] = true; //Найдено по id $src = $dir . $files[$id]['file']; if ($what == 'dir') { return $src . '/'; } else { return $src; } } foreach ($files as $d) { if (mb_strtolower($d['name']) == mb_strtolower($id)) { $src = $dir . $d['file']; if ($what == 'dir') { return $src . '/'; } else { return $src; } } } }
} exit; } else { return Ans::err($res, 'id что?'); } } elseif (isset($_GET['list'])) { if (isset($_GET['lim'])) { $lim = $_GET['lim']; } else { $lim = '0,100'; } $p = explode(',', $lim); if (sizeof($p) != 2) { return Ans::err($ans, 'Is wrong paramter lim'); } $start = (int) $p[0]; $count = (int) $p[1]; $ar = rub_list($dir, $start, $count, $exts); $ar = array_values($ar); if (!empty($_GET['chunk'])) { $chunk = (int) $_GET['chunk']; if (!$chunk) { $chunk = 1; } $ar = array_chunk($ar, $chunk); } $ans['list'] = $ar; return Ans::ret($ans); } else { return Ans::err($ans, 'Недостаточно параметров'); }