4 public function __construct()
6 $cache = Config::main()->get('cache');
9 throw new Exception('Cache file not found');
11 $this->db = new PDO('sqlite:/'.$cache);
14 public function findTitles($keyword)
16 $media_dir = Config::main()->get('media_dir_A');
17 $results = array('count' => 0, 'list' => []);
18 $sql = sprintf("SELECT path, title, timestamp, size FROM details WHERE path LIKE %s AND mime IS NOT NULL",
19 $this->db->quote('%'.$keyword.'%'));
21 $sth = $this->db->query($sql);
22 if ($sth === false) return $results;
25 while ($row = $sth->fetchObject()) {
26 $id = "{$row->TIMESTAMP}-{$row->SIZE}";
27 if (!array_key_exists($id, $seen)) {
32 $path = substr($row->PATH, strlen($media_dir)+1);
34 if (($pos = strrpos($path, '.')) > strlen($path)-10)
35 $path = substr($path, 0, $pos);
37 if (($pos = strpos($path, '/')) < 20) {
38 $section = substr($path, 0, $pos);
39 $path = substr($path, $pos+1);
42 if (!array_key_exists($section, $results['list']))
43 $results['list'][$section] = [];
44 $results['list'][$section][] = ['path' => dirname($path), 'name' => basename($path), 'title' => $row->TITLE];