]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
3 | /** | |
4 | * Music Player Daemon API | |
5 | * | |
6 | * PHP Version 5 | |
7 | * | |
8 | * LICENSE: This source file is subject to version 3.01 of the PHP license | |
9 | * that is available thorugh the world-wide-web at the following URI: | |
10 | * http://www.php.net/license/3_01.txt. If you did not receive a copy of | |
11 | * the PHP License and are unable to obtain it through the web, please | |
12 | * send a note to license@php.net so we can mail you a copy immediately. | |
13 | * | |
14 | * @category Networking | |
15 | * @package Net_MPD | |
16 | * @author Graham Christensen <graham.christensen@itrebal.com> | |
17 | * @copyright 2006 Graham Christensen | |
18 | * @license http://www.php.net/license/3_01.txt | |
19 | * @version CVS: $ID:$ | |
20 | */ | |
21 | ||
22 | /** | |
23 | * API for the database portion of Music Player Daemon commands | |
24 | * | |
25 | * Used for maintaining and working with the MPD database | |
26 | * | |
27 | * @category Networking | |
28 | * @package Net_MPD | |
29 | * @author Graham Christensen <graham.christensen@itrebal.com> | |
30 | * @copyright 2006 Graham Christensen | |
31 | * @license http://www.php.net/license/3_01.txt | |
32 | * @version CVS: $ID:$ | |
33 | */ | |
34 | class Net_MPD_Database extends Net_MPD_Common | |
35 | { | |
36 | /** | |
37 | * Case sensitive search for data in the database | |
38 | * | |
39 | * @param array $params array('search_field' => 'search for') | |
40 | * @param bool $caseSensitive True for case sensitivity, false for not [default false] | |
41 | * @return array | |
42 | */ | |
43 | public function find($params, $caseSensitive = false) | |
44 | { | |
45 | $prms = array(); | |
46 | foreach($params as $key => $value) { | |
47 | $prms[] = $key; | |
48 | $prms[] = $value; | |
49 | } | |
50 | $cmd = $caseSensitive ? 'find' : 'search'; | |
51 | ||
52 | $out = $this->runCommand($cmd, $prms); | |
53 | if (!isset($out['file'])) { | |
54 | return array(); | |
55 | } | |
56 | return $out['file']; | |
57 | } | |
58 | ||
59 | ||
60 | ||
61 | /** | |
62 | * List all metadata of matches to the search | |
63 | * | |
64 | * @param string $metadata1 metadata to list | |
65 | * @param string $metadata2 metadata field to search in, optional | |
66 | * @param string $search data to search for in search field, | |
67 | * required if search field provided | |
68 | * @return array | |
69 | */ | |
70 | public function getMetadata($metadata1, $metadata2 = null, $search = null) | |
71 | { | |
72 | //Make sure that if metadata2 is set, search is as well | |
73 | if (!is_null($metadata2)) { | |
74 | if (is_null($search)) { | |
75 | return false; | |
76 | } | |
77 | } | |
78 | if (!is_null($metadata2)) { | |
79 | $out = $this->runCommand('list', array($metadata1, $metadata2, $search), 1); | |
80 | } else { | |
81 | $out = $this->runCommand('list', $metadata1, 1); | |
82 | } | |
83 | return $out[$metadata1]; | |
84 | } | |
85 | ||
86 | ||
87 | ||
88 | /** | |
89 | * Lists all files and folders in the directory recursively | |
90 | * | |
91 | * @param $dir string directory to start in, optional | |
92 | * @return array | |
93 | */ | |
94 | public function getAll($dir = '') | |
95 | { | |
96 | return $this->runCommand('listall', $dir, 1); | |
97 | } | |
98 | ||
99 | ||
100 | ||
101 | /** | |
102 | * Lists all files/folders recursivly, listing any related informaiton | |
103 | * | |
104 | * @param $dir string directory to start in, optional | |
105 | * @return array | |
106 | */ | |
107 | public function getAllInfo($dir = '') | |
108 | { | |
109 | return $this->runCommand('listallinfo', $dir); | |
110 | } | |
111 | ||
112 | /** | |
113 | * Lists content of the directory | |
114 | * | |
115 | * @param $dir string directory to work in, optional | |
116 | * @return array | |
117 | */ | |
118 | public function getInfo($dir = '') | |
119 | { | |
120 | return $this->runCommand('lsinfo', $dir); | |
121 | } | |
122 | } | |
123 | ?> |