Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch-contrib
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch-contrib
Commits
855b7802
提交
855b7802
authored
2月 05, 2011
作者:
Mitch Capper
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
ssh://git.freeswitch.org/freeswitch-contrib
上级
c898261f
f75dbeb7
隐藏空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
779 行增加
和
246 行删除
+779
-246
index.php
sathieu/cisco-xml/browser/index.php
+21
-2
default.css
sathieu/cisco-xml/browser/static/default.css
+49
-0
dynamic.js
sathieu/cisco-xml/browser/static/dynamic.js
+4
-0
Cisco-XML.php
sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php
+10
-1
Backend.php
sathieu/cisco-xml/lib/MediaBrotha/Backend.php
+36
-53
FileSystem.php
sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
+54
-31
LDAP.php
sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
+98
-0
Root.php
sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
+21
-12
VLC.php
sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
+50
-34
Core.php
sathieu/cisco-xml/lib/MediaBrotha/Core.php
+101
-46
Frontend.php
sathieu/cisco-xml/lib/MediaBrotha/Frontend.php
+2
-4
CiscoXML.php
sathieu/cisco-xml/lib/MediaBrotha/Frontend/CiscoXML.php
+34
-27
HTML.php
sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTML.php
+127
-0
HTTP.php
sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTTP.php
+33
-0
Media.php
sathieu/cisco-xml/lib/MediaBrotha/Media.php
+68
-36
MediaIterator.php
sathieu/cisco-xml/lib/MediaBrotha/MediaIterator.php
+71
-0
没有找到文件。
sathieu/cisco-xml/browser/index.php
浏览文件 @
855b7802
...
...
@@ -33,12 +33,31 @@ ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'../lib');
require
(
'Cisco-XML/Cisco-XML.php'
);
require_once
(
'MediaBrotha/Core.php'
);
// Init
MediaBrotha_Core
::
init
();
MediaBrotha_Core
::
connectFrontend
(
'CiscoXML'
,
Array
(
'push_url'
=>
'http://cisco:cisco@192.168.0.220/CGI/Execute'
));
if
(
CiscoIPPhone
::
userAgentIsCiscoIPPhone
())
{
MediaBrotha_Core
::
connectFrontend
(
'CiscoXML'
,
Array
(
'push_url'
=>
'http://cisco:cisco@192.168.0.220/CGI/Execute'
));
}
else
{
MediaBrotha_Core
::
connectFrontend
(
'HTML'
);
}
// Backends
MediaBrotha_Core
::
loadBackend
(
'FileSystem'
,
Array
(
'base_path'
=>
'/home/share/music/'
));
MediaBrotha_Core
::
loadBackend
(
'VLC'
,
Array
(
'http_intf'
=>
'http://127.0.0.1:8080'
));
$ldap_connect_config
=
Array
(
'host'
=>
'127.0.0.1'
,
//'binddn' => 'cn=nobody,cn=internal,dc=example,dc=org',
//'bindpw' => 'not24get',
'basedn'
=>
'dc=sathieu,dc=net'
,
'filter'
=>
'(objectClass=*)'
,
'scope'
=>
'one'
,
);
MediaBrotha_Core
::
loadBackend
(
'LDAP'
,
Array
(
'ldap_connect_config'
=>
$ldap_connect_config
));
// Roots
MediaBrotha_Core
::
addRootMedia
(
'file:///home/share/music/'
,
Array
(
'display_name'
=>
'Fichiers'
));
MediaBrotha_Core
::
addRootMedia
(
'ldap:///'
,
Array
(
'display_name'
=>
'Annuaire'
));
MediaBrotha_Core
::
go
();
sathieu/cisco-xml/browser/static/default.css
0 → 100644
浏览文件 @
855b7802
/*
* body > ul#mediaListElement > li.mediaElement
*/
li
.mediaElement
{
padding
:
2px
;
margin
:
0px
;
list-style-type
:
none
;
}
li
.mediaElement
:nth-child
(
odd
)
{
background-color
:
#d1e3ed
;
}
/*
* body > ul#mediaListElement
*/
#mediaListElement
{
padding
:
2px
;
margin
:
0px
;
}
/*
* body > ul#mediaListElement > li.mediaElement > ul.mediaActionsListElement
*/
li
.mediaElement
.mediaActionsListElement
{
padding
:
2px
;
margin
:
0px
;
margin-left
:
20px
;
list-style-type
:
none
;
-moz-transition-property
:
max-height
,
opacity
,
visibility
;
-moz-transition-duration
:
3s
,
2s
,
0.2s
;
-moz-transition-delay
:
0s
,
1s
,
1s
;
max-height
:
0px
;
opacity
:
0
;
visibility
:
hidden
;
}
li
.mediaElement
:hover
.mediaActionsListElement
{
-moz-transition-property
:
max-height
,
opacity
,
visibility
;
-moz-transition-duration
:
0.5s
,
2s
,
0.2s
;
-moz-transition-delay
:
0.4s
,
0.4s
,
0.4s
;
max-height
:
200px
;
opacity
:
1
;
visibility
:
visible
;
}
sathieu/cisco-xml/browser/static/dynamic.js
0 → 100644
浏览文件 @
855b7802
function
bodyLoaded
()
{
//nothing yet
}
sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php
浏览文件 @
855b7802
...
...
@@ -23,6 +23,12 @@ This file is part of XML services for Cisco IP Phones.
/**
* @author Mathieu Parent
*/
class
CiscoIPPhone
{
static
public
function
userAgentIsCiscoIPPhone
()
{
return
preg_match
(
'/^Allegro-Software-WebClient\//'
,
$_SERVER
[
'HTTP_USER_AGENT'
]);
}
}
class
CiscoXMLField
{
private
$_allowed_fields
=
NULL
;
...
...
@@ -125,7 +131,10 @@ class CiscoXMLObject {
);
$context
=
stream_context_create
(
$opts
);
return
file_get_contents
(
$url
,
false
,
$context
);
$stream
=
fopen
(
$url
,
'r'
,
false
,
$context
);
if
(
$stream
!==
false
)
{
return
stream_get_contents
(
$stream
);
}
}
}
...
...
sathieu/cisco-xml/lib/MediaBrotha/Backend.php
浏览文件 @
855b7802
...
...
@@ -26,79 +26,62 @@ This file is part of MediaBrotha.
require_once
(
'MediaBrotha/Media.php'
);
class
MediaBrotha_Backend
extends
MediaBrotha_Media
implements
Iterator
{
protected
$_buffer
=
Array
();
public
function
__construct
(
$args
=
Array
())
{
parent
::
__construct
(
$args
);
$this
->
register
();
$this
->
setMimeType
(
'application/x-mediabrotha-backend-'
.
strtolower
(
$this
->
getName
()));
MediaBrotha_Core
::
registerMimeType
(
$this
,
'application/x-mediabrotha-backend-'
.
strtolower
(
$this
->
getName
()));
$this
->
setMetadata
(
'name'
,
$this
->
getName
());
$this
->
setMetadata
(
'uri'
,
'MediaBrotha_Backend://'
.
$this
->
getName
());
}
class
MediaBrotha_Backend
{
protected
$_params
=
NULL
;
public
function
register
()
{
MediaBrotha_Core
::
registerBackend
(
$this
);
public
function
__construct
(
$params
=
NULL
)
{
$this
->
setParam
(
$params
);
$this
->
register
();
}
public
function
getName
()
{
return
preg_replace
(
'/^MediaBrotha_Backend_(.*)$/'
,
'$1'
,
get_class
(
$this
));
/* params */
public
function
getParam
(
$name
=
NULL
)
{
if
(
$name
===
NULL
)
{
return
$this
->
_params
;
}
elseif
(
isset
(
$this
->
_params
[
$name
]))
{
return
$this
->
_params
[
$name
];
}
else
{
return
NULL
;
}
}
public
function
setParam
(
$name
,
$value
=
NULL
)
{
if
(
is_array
(
$name
))
{
$this
->
_params
=
$name
;
}
else
{
$this
->
_params
[
$name
]
=
$value
;
public
function
capabilities
(
$uri
=
NULL
,
$mime_type
=
NULL
,
$mime_encoding
=
NULL
)
{
return
Array
();
}
}
public
function
isHidden
()
{
return
parent
::
isHidden
()
||
!
in_array
(
'browse'
,
$this
->
capabilities
()
);
public
function
register
()
{
MediaBrotha_Core
::
registerBackend
(
$this
);
}
// Capability browse
public
function
fetch
(
$uri
)
{
return
false
;
public
function
getBackendName
()
{
return
preg_replace
(
'/^MediaBrotha_Backend_(.*)$/'
,
'$1'
,
get_class
(
$this
));
}
public
function
rewind
()
{
reset
(
$this
->
_buffer
);
// Browsing
public
function
mediaFromBufferItem
(
$item
)
{
return
$item
;
}
public
function
current
(
)
{
return
current
(
$this
->
_buffer
)
;
public
function
fetch
(
MediaBrotha_Media
$media
)
{
return
false
;
}
public
function
key
()
{
return
key
(
$this
->
_buffer
);
// Actions
public
function
getMediaActions
(
MediaBrotha_Media
$media
)
{
return
Array
();
}
public
function
next
(
)
{
return
next
(
$this
->
_buffer
)
;
public
function
doMediaAction
(
$action
,
MediaBrotha_Media
$media
)
{
return
false
;
}
public
function
valid
()
{
$key
=
key
(
$this
->
_buffer
);
$var
=
(
$key
!==
NULL
&&
$key
!==
FALSE
);
return
$var
;
// Populate
public
function
populateMedia
(
MediaBrotha_Media
$media
)
{
}
// Capability play
public
function
play
(
$media
)
{
return
false
;
}
public
function
pause
()
{
return
false
;
}
public
function
stop
()
{
return
false
;
}
// Capability playlist
public
function
playlistEnqueue
(
$media
)
{
return
false
;
}
public
function
playlistNext
(
$media
)
{
return
false
;
}
public
function
playlistPrevious
(
$media
)
{
return
false
;
}
}
sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
浏览文件 @
855b7802
...
...
@@ -25,14 +25,10 @@ This file is part of MediaBrotha.
*/
class
MediaBrotha_Backend_FileSystem
extends
MediaBrotha_Backend
{
public
function
register
()
{
parent
::
register
();
MediaBrotha_Core
::
registerMimeType
(
$this
,
'application/x-directory'
);
}
// Helper functions
public
function
isURISafe
(
$uri
)
{
$real_path
=
realpath
(
parse_url
(
$uri
,
PHP_URL_PATH
));
$real_base_path
=
realpath
(
$this
->
get
Metadata
(
'base_path'
));
$real_base_path
=
realpath
(
$this
->
get
Param
(
'base_path'
));
do
{
if
(
$real_path
===
$real_base_path
)
{
return
true
;
...
...
@@ -41,26 +37,19 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {
return
false
;
}
public
function
fetch
(
$uri
)
{
if
((
parse_url
(
$uri
,
PHP_URL_SCHEME
)
!=
'file'
)
||
!
$this
->
isURISafe
(
$uri
))
{
$uri
=
'file://'
.
$this
->
getMetadata
(
'base_path'
);
}
$this
->
_buffer
=
new
DirectoryIterator
(
parse_url
(
$uri
,
PHP_URL_PATH
));
return
true
;
}
public
function
capabilities
(
$uri
=
NULL
,
$mime_type
=
NULL
,
$mime_encoding
=
NULL
)
{
return
Array
(
'browse'
,
);
}
// Iterator
public
function
mediaFromFile
(
$file
)
{
// Browsing
public
function
mediaFromBufferItem
(
$file
)
{
if
(
$file
)
{
$media
=
new
MediaBrotha_Media
(
Array
(
'uri'
=>
'file://'
.
realpath
(
$file
->
getPathname
()),
'name'
=>
$file
->
getFilename
(),
'hidden'
=>
!
$file
->
isReadable
()
||
preg_match
(
'/^\.([^.]|$)/'
,
$file
->
getFilename
()),
));
if
(
$file
->
getFilename
()
===
'..'
)
{
return
NULL
;
}
$media
=
new
MediaBrotha_Media
(
'file://'
.
realpath
(
$file
->
getPathname
()),
Array
(
'display_name'
=>
$file
->
getFilename
(),
'hidden'
=>
!
$file
->
isReadable
()
||
preg_match
(
'/^\.([^.]|$)/'
,
$file
->
getFilename
()),
)
);
if
(
$file
->
isDir
())
{
$media
->
setMimeType
(
'application/x-directory'
);
}
else
{
...
...
@@ -72,16 +61,50 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {
}
}
public
function
current
()
{
return
$this
->
mediaFromFile
(
$this
->
_buffer
->
current
());
public
function
fetch
(
MediaBrotha_Media
$media
)
{
$uri
=
$media
->
getURI
();
if
((
parse_url
(
$uri
,
PHP_URL_SCHEME
)
!=
'file'
)
||
!
$this
->
isURISafe
(
$uri
))
{
$uri
=
'file://'
.
$this
->
getParam
(
'base_path'
);
}
$path
=
parse_url
(
$uri
,
PHP_URL_PATH
);
if
(
is_dir
(
$path
))
{
return
new
MediaBrotha_MediaIterator
(
$this
,
$media
,
new
DirectoryIterator
(
$path
));
}
else
{
return
false
;
}
}
// Actions
protected
function
_isHandled
(
MediaBrotha_Media
$media
)
{
return
(
$media
->
getMimeType
()
===
'application/x-directory'
)
||
(
substr
(
$media
->
getURI
(),
0
,
7
)
===
'file://'
);
}
public
function
next
()
{
return
$this
->
mediaFromFile
(
$this
->
_buffer
->
next
());
public
function
getMediaActions
(
MediaBrotha_Media
$media
)
{
if
(
$this
->
_isHandled
(
$media
))
{
return
Array
(
'browse'
,
);
}
else
{
return
parent
::
getMediaActions
(
$media
);
}
}
public
function
valid
()
{
return
$this
->
_buffer
->
valid
();
// Populate
public
function
populateMedia
(
MediaBrotha_Media
$media
)
{
if
(
$this
->
_isHandled
(
$media
))
{
$parent_path
=
'file://'
.
dirname
(
parse_url
(
$media
->
getURI
(),
PHP_URL_PATH
));
if
(
$this
->
isURISafe
(
$parent_path
))
{
$media
->
setParent
(
new
MediaBrotha_Media
(
$parent_path
,
Array
(
'display_name'
=>
'..'
,
)
)
);
}
}
}
}
sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
0 → 100644
浏览文件 @
855b7802
<?php
/*
Copyright 2011 Mathieu Parent <math.parent@gmail.com>
This file is part of MediaBrotha.
MediaBrotha is free software: you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
MediaBrotha is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MediaBrotha. If not, see
<http://www.gnu.org/licenses/>.
*/
require_once
(
'Net/LDAP2.php'
);
/**
* @author Mathieu Parent
*/
class
MediaBrotha_Backend_LDAP
extends
MediaBrotha_Backend
{
private
$_ldap
;
public
function
__construct
(
array
$args
=
Array
())
{
parent
::
__construct
(
$args
);
$this
->
_ldap
=
Net_LDAP2
::
connect
(
$this
->
getParam
(
'ldap_connect_config'
));
if
(
Net_LDAP2
::
isError
(
$this
->
_ldap
))
{
die
(
'Could not fetch entry: '
.
$this
->
_ldap
->
getMessage
());
}
}
// Helper functions
public
function
isURISafe
(
$uri
)
{
return
true
;
}
public
static
function
parseLDAPURI
(
$uri
,
$component
=
NULL
)
{
$uri
=
preg_replace
(
'@^ldap:///@'
,
'ldap://fake_host/'
,
$uri
);
$components
=
parse_url
(
$uri
,
$component
);
if
(
is_array
(
$components
)
&&
(
$components
[
'host'
]
===
'fake_host'
))
{
$components
[
'host'
]
=
NULL
;
}
return
$components
;
}
// Browsing
public
function
mediaFromBufferItem
(
$entry
)
{
if
(
$entry
)
{
$media
=
new
MediaBrotha_Media
(
'ldap:///'
.
$entry
->
dn
(),
Array
(
'display_name'
=>
$entry
->
dn
(),
//$entry->getValue('sn', 'single'),
),
'text/directory'
//$finfo->file($file->getPathname(), FILEINFO_MIME_ENCODING);
);
return
$media
;
}
}
public
function
fetch
(
MediaBrotha_Media
$media
)
{
$uri
=
$media
->
getURI
();
if
((
$this
::
parseLDAPURI
(
$uri
,
PHP_URL_SCHEME
)
!=
'ldap'
)
||
!
$this
->
isURISafe
(
$uri
))
{
$ldap_connect_config
=
$this
->
getParam
(
'ldap_connect_config'
);
$uri
=
'ldap:///'
.
$ldap_connect_config
[
'basedn'
];
}
$basedn
=
$this
::
parseLDAPURI
(
$uri
,
PHP_URL_PATH
);
if
(
$basedn
&&
(
$basedn
{
0
}
=
'/'
))
{
$basedn
=
substr
(
$basedn
,
1
);
}
$ldap_search
=
$this
->
_ldap
->
search
(
$basedn
,
NULL
,
Array
());
return
new
MediaBrotha_MediaIterator
(
$this
,
$media
,
$ldap_search
);
return
true
;
}
// Actions
protected
function
_isHandled
(
MediaBrotha_Media
$media
)
{
return
(
$media
->
getMimeType
()
===
'text/directory'
)
||
(
substr
(
$media
->
getURI
(),
0
,
7
)
===
'ldap://'
);
}
public
function
getMediaActions
(
MediaBrotha_Media
$media
)
{
if
(
$this
->
_isHandled
(
$media
))
{
return
Array
(
'browse'
,
);
}
else
{
return
parent
::
getMediaActions
(
$media
);
}
}
}
sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
浏览文件 @
855b7802
...
...
@@ -25,20 +25,29 @@ This file is part of MediaBrotha.
*/
class
MediaBrotha_Backend_Root
extends
MediaBrotha_Backend
{
public
function
fetch
(
$uri
)
{
$this
->
_buffer
=
Array
();
foreach
(
MediaBrotha_Core
::
getBackends
()
as
$id
=>
$backend
)
{
$this
->
_buffer
[]
=
$backend
;
}
return
true
;
}
public
function
capabilities
(
$uri
=
NULL
,
$mime_type
=
NULL
,
$mime_encoding
=
NULL
)
{
return
Array
(
'browse'
,
private
$_media
=
NULL
;
private
$_media_iterator
=
NULL
;
public
function
__construct
(
$params
=
NULL
)
{
parent
::
__construct
(
$params
);
$this
->
_media
=
new
MediaBrotha_Media
(
'MediaBrotha:///'
,
Array
(
'display_name'
=>
'Root'
,
)
);
$this
->
_media_iterator
=
new
MediaBrotha_MediaIterator
(
$this
,
$this
->
_media
);
}
public
function
addRootMedia
(
$URI
,
array
$metadata
=
Array
(),
$mime_type
=
NULL
,
$mime_encoding
=
NULL
)
{
$this
->
addRootMediaObj
(
new
MediaBrotha_Media
(
$URI
,
$metadata
,
$mime_type
,
$mime_encoding
));
}
public
function
isHidden
()
{
return
true
;
public
function
addRootMediaObj
(
$media
)
{
$this
->
_media_iterator
->
bufferAdd
(
$media
);
}
// Browsing
public
function
fetch
(
MediaBrotha_Media
$media
)
{
return
$this
->
_media_iterator
;
}
}
...
...
sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
浏览文件 @
855b7802
...
...
@@ -25,51 +25,67 @@ This file is part of MediaBrotha.
*/
class
MediaBrotha_Backend_VLC
extends
MediaBrotha_Backend
{
public
function
register
()
{
parent
::
register
();
MediaBrotha_Core
::
registerMimeType
(
$this
,
'audio/mpeg'
);
MediaBrotha_Core
::
registerMimeType
(
$this
,
'video/x-msvideo'
);
}
static
protected
$_supported_mime_types
=
Array
(
'audio/mpeg'
,
'video/x-msvideo'
,
);
public
function
fetch
(
$uri
)
{
$this
->
_buffer
[]
=
new
MediaBrotha_Media
();
return
true
;
}
public
function
capabilities
(
$uri
=
NULL
,
$mime_type
=
NULL
,
$mime_encoding
=
NULL
)
{
return
Array
(
'play'
,
'playlist'
,
);
}
private
function
send_command
(
$command
,
$args
=
Array
())
{
$url
=
$this
->
getMetadata
(
'http_intf'
)
.
// Helper functions
private
function
send_command
(
$command
,
array
$args
=
Array
())
{
$url
=
$this
->
getParam
(
'http_intf'
)
.
'/requests/status.xml'
.
'?command='
.
$command
;
foreach
(
$args
as
$k
=>
$v
)
{
$url
.=
'&'
.
$k
.
'='
.
rawurlencode
(
$v
);
}
return
fopen
(
$url
,
'r'
);
$output
=
file_get_contents
(
$url
);
Header
(
'Content-Type: text/xml'
);
print
$output
.
'<!--'
.
$url
.
"-->
\n
"
;
}
// Capability play
public
function
play
(
$media
)
{
return
$this
->
send_command
(
'in_play'
,
Array
(
'input'
=>
$media
->
getURI
()));
}
public
function
pause
()
{
return
$this
->
send_command
(
'pl_pause'
);
}
public
function
stop
()
{
return
$this
->
send_command
(
'pl_stop'
);
// Browsing
public
function
fetch
(
MediaBrotha_Media
$media
)
{
$this
->
_buffer
[]
=
$media
;
return
true
;
}
// Capability playlist
public
function
playlistEnqueue
(
$media
)
{
return
$this
->
send_command
(
'in_enqueue'
,
Array
(
'input'
=>
$media
->
getURI
()));
// Actions
protected
function
_isHandled
(
MediaBrotha_Media
$media
)
{
return
in_array
(
$media
->
getMimeType
(),
Array
(
$this
::
$_supported_mime_types
))
||
(
substr
(
$media
->
getURI
(),
0
,
7
)
===
'file://'
);
}
public
function
playlistNext
(
$media
)
{
return
$this
->
send_command
(
'pl_next'
);
public
function
getMediaActions
(
MediaBrotha_Media
$media
)
{
if
(
$this
->
_isHandled
(
$media
))
{
return
Array
(
'play_media'
,
'pause_media'
,
'stop_media'
,
'enqueue_media'
,
'next_media'
,
'previous_media'
,
);
}
else
{
return
parent
::
getMediaActions
(
$media
);
}
}
public
function
playlistPrevious
(
$media
)
{
return
$this
->
send_command
(
'pl_previous'
);
public
function
doMediaAction
(
$action
,
MediaBrotha_Media
$media
)
{
switch
(
$action
)
{
case
'play_media'
:
return
$this
->
send_command
(
'in_play'
,
Array
(
'input'
=>
$media
->
getURI
()));
case
'pause_media'
:
return
$this
->
send_command
(
'pl_pause'
);
case
'stop_media'
:
return
$this
->
send_command
(
'pl_stop'
);
case
'enqueue_media'
:
return
$this
->
send_command
(
'in_enqueue'
,
Array
(
'input'
=>
$media
->
getURI
()));
case
'next_media'
:
return
$this
->
send_command
(
'pl_next'
);
case
'previous_media'
:
return
$this
->
send_command
(
'pl_previous'
);
default
:
return
parent
::
doMediaAction
(
$action
,
$media
);
}
}
}
...
...
sathieu/cisco-xml/lib/MediaBrotha/Core.php
浏览文件 @
855b7802
...
...
@@ -27,52 +27,49 @@ This file is part of MediaBrotha.
require_once
(
'MediaBrotha/Backend.php'
);
require_once
(
'MediaBrotha/Frontend.php'
);
require_once
(
'MediaBrotha/Media.php'
);
require_once
(
'MediaBrotha/MediaIterator.php'
);
class
MediaBrotha_Core
{
private
static
$_frontend
=
NULL
;
private
static
$_backends
=
Array
();
private
static
$_mime_types
=
Array
();
private
static
$_media
=
NULL
;
/*
* Core
*/
public
static
function
init
()
{
if
(
!
session_start
())
{
die
(
'Unable to start session'
);
}
MediaBrotha_Core
::
_unhashRequest
();
MediaBrotha_Core
::
loadBackend
(
'Root'
);
}
public
static
function
go
()
{
$current_backend
=
MediaBrotha_Core
::
getCurrentBackend
();
switch
(
MediaBrotha_Core
::
getAction
())
{
case
'play'
:
$current_backend
->
play
(
MediaBrotha_Core
::
getCurrentMedia
());
break
;
case
'pause'
:
$current_backend
->
pause
(
MediaBrotha_Core
::
getCurrentMedia
());
break
;
case
'stop'
:
$current_backend
->
stop
(
MediaBrotha_Core
::
getCurrentMedia
());
break
;
case
'pl_enqueue'
:
$current_backend
->
playlistEnqueue
(
MediaBrotha_Core
::
getCurrentMedia
());
break
;
case
'pl_next'
:
$current_backend
->
playlistNext
(
MediaBrotha_Core
::
getCurrentMedia
());
break
;
case
'pl_previous'
:
$current_backend
->
playlistPrevious
(
MediaBrotha_Core
::
getCurrentMedia
());
break
;
case
'browse'
:
default
:
$current_backend
->
fetch
(
MediaBrotha_Core
::
getCurrentURI
());
MediaBrotha_Core
::
$_frontend
->
begin
(
$current_backend
);
foreach
(
$current_backend
as
$item
)
{
if
(
$item
->
isHidden
())
{
$current_media
=
MediaBrotha_Core
::
getCurrentMedia
();
if
(
MediaBrotha_Core
::
getAction
()
==
'browse'
)
{
if
(
$media_iterator
=
$current_backend
->
fetch
(
$current_media
))
{
MediaBrotha_Core
::
$_frontend
->
begin
(
$current_media
);
foreach
(
$media_iterator
as
$item
)
{
if
((
$item
===
NULL
)
||
$item
->
isHidden
())
{
continue
;
}
MediaBrotha_Core
::
$_frontend
->
addItem
(
$item
);
}
MediaBrotha_Core
::
$_frontend
->
finish
(
$current_backend
);
MediaBrotha_Core
::
$_frontend
->
render
();
MediaBrotha_Core
::
$_frontend
->
finish
(
$current_media
);
MediaBrotha_Core
::
$_frontend
->
render
(
$current_media
);
}
else
{
}
}
else
{
$current_backend
->
doMediaAction
(
MediaBrotha_Core
::
getAction
(),
$current_media
);
}
}
public
function
addRootMedia
(
$URI
,
array
$metadata
=
Array
(),
$mime_type
=
NULL
,
$mime_encoding
=
NULL
)
{
MediaBrotha_Core
::
$_backends
[
'Root'
]
->
addRootMedia
(
$URI
,
$metadata
,
$mime_type
,
$mime_encoding
);
}
/*
* Backends
*/
...
...
@@ -84,21 +81,15 @@ class MediaBrotha_Core {
return
new
$class_name
(
$args
);
}
public
static
function
registerBackend
(
$backend
)
{
MediaBrotha_Core
::
$_backends
[]
=
$backend
;
MediaBrotha_Core
::
$_backends
[
$backend
->
getBackendName
()
]
=
$backend
;
}
public
static
function
registerMimeType
(
$backend
,
$mime_typ
e
)
{
MediaBrotha_Core
::
$_mime_types
[
$mime_type
][]
=
$backend
;
public
static
function
getBackend
(
$nam
e
)
{
return
MediaBrotha_Core
::
$_backends
[
$name
]
;
}
public
static
function
getBackends
()
{
return
MediaBrotha_Core
::
$_backends
;
}
public
static
function
getCurrentBackend
()
{
if
(
!
empty
(
$_GET
[
'mime_type'
])
&&
!
empty
(
MediaBrotha_Core
::
$_mime_types
[
$_GET
[
'mime_type'
]]))
{
return
MediaBrotha_Core
::
$_mime_types
[
$_GET
[
'mime_type'
]][
0
];
}
else
{
return
MediaBrotha_Core
::
$_backends
[
0
];
}
}
/*
* Frontend
*/
...
...
@@ -114,8 +105,26 @@ class MediaBrotha_Core {
MediaBrotha_Core
::
$_frontend
=
new
$class_name
(
$args
);
}
/*
*
...
*
Current *
*/
public
static
function
getCurrentBackend
()
{
if
(
!
empty
(
$_GET
[
'backend'
])
&&
!
empty
(
MediaBrotha_Core
::
$_backends
[
$_GET
[
'backend'
]]))
{
return
MediaBrotha_Core
::
$_backends
[
$_GET
[
'backend'
]];
}
$current_media
=
MediaBrotha_Core
::
getCurrentMedia
();
foreach
(
MediaBrotha_Core
::
getBackends
()
as
$backend
)
{
foreach
(
$backend
->
getMediaActions
(
$current_media
)
as
$action
)
{
if
(
$backend
->
getBackendName
()
==
'Root'
)
{
continue
;
}
if
(
$action
===
MediaBrotha_Core
::
getAction
())
{
return
$backend
;
}
}
}
return
MediaBrotha_Core
::
$_backends
[
'Root'
];
}
public
static
function
getAction
()
{
if
(
!
empty
(
$_GET
[
'action'
]))
{
return
$_GET
[
'action'
];
...
...
@@ -124,17 +133,63 @@ class MediaBrotha_Core {
}
}
public
static
function
getCurrentURI
()
{
if
(
!
empty
(
$_GET
[
'uri'
]))
{
return
$_GET
[
'uri'
];
}
}
public
static
function
getCurrentMedia
()
{
if
(
empty
(
MediaBrotha_Core
::
$_media
))
{
MediaBrotha_Core
::
$_media
=
new
MediaBrotha_Media
();
MediaBrotha_Core
::
$_media
->
setURI
(
MediaBrotha_Core
::
getCurrentURI
());
if
(
!
empty
(
$_GET
[
'uri'
]))
{
MediaBrotha_Core
::
$_media
=
new
MediaBrotha_Media
(
$_GET
[
'uri'
]);
}
else
{
MediaBrotha_Core
::
$_media
=
new
MediaBrotha_Media
(
'MediaBrotha:///'
);
}
foreach
(
MediaBrotha_Core
::
getBackends
()
as
$backend
)
{
$backend
->
populateMedia
(
MediaBrotha_Core
::
$_media
);
}
}
return
MediaBrotha_Core
::
$_media
;
}
/*
* helper functions
*/
/* hashes */
public
static
function
hash2value
(
$h
)
{
if
(
isset
(
$_SESSION
[
'HASHES'
][
$h
]))
{
return
$_SESSION
[
'HASHES'
][
$h
];
}
else
{
return
NULL
;
}
}
public
static
function
value2hash
(
$v
)
{
for
(
$hash_length
=
1
;
$hash_length
<=
41
;
$hash_length
++
)
{
$h
=
substr
(
sha1
(
$v
),
0
,
$hash_length
);
if
(
!
isset
(
$_SESSION
[
'HASHES'
][
$h
])
||
(
$_SESSION
[
'HASHES'
][
$h
]
===
$v
))
{
break
;
}
}
$_SESSION
[
'HASHES'
][
$h
]
=
$v
;
return
$h
;
}
public
static
function
hash2array
(
$h
)
{
if
(
$v
=
MediaBrotha_Core
::
hash2value
(
$h
))
{
parse_str
(
$v
,
$output
);
return
$output
;
}
}
private
static
function
_unhashRequest
()
{
if
(
!
isset
(
$_SESSION
[
'HASHES'
]))
{
$_SESSION
[
'HASHES'
]
=
Array
();
}
if
(
isset
(
$_SERVER
[
"QUERY_STRING"
]))
{
$tmp
=
explode
(
'&'
,
$_SERVER
[
"QUERY_STRING"
]);
foreach
(
$tmp
as
$h
)
{
if
(
preg_match
(
'/^[a-z0-9]+$/'
,
$h
))
{
$_GET
=
array_merge
(
$_GET
,
MediaBrotha_Core
::
hash2array
(
$h
));
}
}
}
}
}
sathieu/cisco-xml/lib/MediaBrotha/Frontend.php
浏览文件 @
855b7802
...
...
@@ -25,12 +25,10 @@ This file is part of MediaBrotha.
*/
class
MediaBrotha_Frontend
{
protected
$_browser
=
NULL
;
protected
$_infos
=
NULL
;
public
function
__construct
(
$browser
,
$args
=
Array
())
{
$this
->
_browser
=
$browser
;
public
function
__construct
(
array
$args
=
Array
())
{
$this
->
_infos
=
$args
;
}
}
sathieu/cisco-xml/lib/MediaBrotha/Frontend/CiscoXML.php
浏览文件 @
855b7802
...
...
@@ -24,44 +24,51 @@ This file is part of MediaBrotha.
* @author Mathieu Parent
*/
class
MediaBrotha_Frontend_CiscoXML
extends
MediaBrotha_Frontend
{
require_once
(
'HTTP.php'
);
class
MediaBrotha_Frontend_CiscoXML
extends
MediaBrotha_Frontend_HTTP
{
private
$_xml
=
NULL
;
public
function
begin
(
$item
)
{
$this
->
_xml
=
new
CiscoIPPhoneMenu
();
$this
->
_xml
->
setCiscoElement
(
'Title'
,
$item
->
getDisplayName
());
//$this->_xml->setCiscoElement('Prompt', 'kk');
$this
->
_xml
->
setCiscoElement
(
'Title'
,
$item
->
getDisplayName
(
32
));
$this
->
_xml
->
setCiscoElement
(
'Prompt'
,
substr
(
$item
->
getURI
(),
-
32
));
if
(
$parent
=
$item
->
getParent
())
{
$this
->
addItem
(
$parent
);
}
}
public
function
addItem
(
$item
)
{
$url
=
'http://'
.
$_SERVER
[
'SERVER_NAME'
]
.
$_SERVER
[
'SCRIPT_NAME'
]
.
'?'
.
'mime_type='
.
urlencode
(
$item
->
getMimeType
())
.
'&'
.
(
$item
->
getMimeEncoding
()
?
(
'mime_encoding='
.
urlencode
(
$item
->
getMimeEncoding
())
.
'&'
)
:
''
)
.
'uri='
.
urlencode
(
$item
->
getURI
());
//$url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']
;
$url
=
$this
->
rootURL
()
.
'?'
.
MediaBrotha_Core
::
value2hash
(
'mime_type='
.
urlencode
(
$item
->
getMimeType
())
.
'&'
.
(
$item
->
getMimeEncoding
()
?
(
'mime_encoding='
.
urlencode
(
$item
->
getMimeEncoding
())
.
'&'
)
:
''
)
.
'uri='
.
urlencode
(
$item
->
getURI
()))
;
$this
->
_xml
->
setCiscoElement
(
'MenuItem'
,
Array
(
'Name'
=>
$item
->
getDisplayName
(),
'URL'
=>
$url
));
}
public
function
finish
()
{
$this
->
_xml
->
setCiscoElement
(
'SoftKeyItem'
,
Array
(
'Name'
=>
'Select'
,
'URL'
=>
'SoftKey:Select'
,
'Position'
=>
'1'
));
$this
->
_xml
->
setCiscoElement
(
'SoftKeyItem'
,
Array
(
'Name'
=>
'Play'
,
'URL'
=>
'QueryStringParam:action=play'
,
'Position'
=>
'2'
));
$this
->
_xml
->
setCiscoElement
(
'SoftKeyItem'
,
Array
(
'Name'
=>
'Pause'
,
'URL'
=>
'QueryStringParam:action=pause'
,
'Position'
=>
'3'
));
$this
->
_xml
->
setCiscoElement
(
'SoftKeyItem'
,
Array
(
'Name'
=>
'Stop'
,
'URL'
=>
'QueryStringParam:action=stop'
,
'Position'
=>
'4'
));
$this
->
_xml
->
setCiscoElement
(
'SoftKeyItem'
,
Array
(
'Name'
=>
'Enqueue'
,
'URL'
=>
'QueryStringParam:action=pl_enqueue'
,
'Position'
=>
'5'
));
$this
->
_xml
->
setCiscoElement
(
'SoftKeyItem'
,
Array
(
'Name'
=>
'Next'
,
'URL'
=>
'QueryStringParam:action=pl_next'
,
'Position'
=>
'6'
));
$this
->
_xml
->
setCiscoElement
(
'SoftKeyItem'
,
Array
(
'Name'
=>
'Previous'
,
'URL'
=>
'QueryStringParam:action=pl_previous'
,
'Position'
=>
'7'
));
public
function
finish
(
$item
)
{
$pos
=
1
;
$this
->
_xml
->
setCiscoElement
(
'SoftKeyItem'
,
Array
(
'Name'
=>
'Quit'
,
'URL'
=>
'SoftKey:Exit'
,
'Position'
=>
'8'
));
Array
(
'Name'
=>
'Select'
,
'URL'
=>
'SoftKey:Select'
,
'Position'
=>
$pos
++
));
foreach
(
MediaBrotha_Core
::
getBackends
()
as
$backend
)
{
foreach
(
$backend
->
getMediaActions
(
MediaBrotha_Core
::
getCurrentMedia
())
as
$action
)
{
$this
->
_xml
->
setCiscoElement
(
'SoftKeyItem'
,
Array
(
'Name'
=>
$action
,
'URL'
=>
'QueryStringParam:'
.
MediaBrotha_Core
::
value2hash
(
'action='
.
$action
.
'&backend='
.
$backend
->
getBackendName
()),
'Position'
=>
$pos
++
));
}
}
}
public
function
render
()
{
CiscoXMLObject
::
HttpHeader
();
print
$this
->
_xml
;
//$this->_xml->execute($this->_infos['push_url']);
if
(
true
)
{
CiscoXMLObject
::
HttpHeader
();
print
$this
->
_xml
;
//print "\n<!--".strlen($this->_xml).'-->';
}
else
{
print
strlen
(
$this
->
_xml
)
.
"
\n
"
;
print
$this
->
_xml
->
execute
(
$this
->
_infos
[
'push_url'
]);
}
}
}
sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTML.php
0 → 100644
浏览文件 @
855b7802
<?php
/*
Copyright 2011 Mathieu Parent <math.parent@gmail.com>
This file is part of MediaBrotha.
MediaBrotha is free software: you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
MediaBrotha is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MediaBrotha. If not, see
<http://www.gnu.org/licenses/>.
*/
/**
* @author Mathieu Parent
*/
require_once
(
'HTTP.php'
);
class
MediaBrotha_Frontend_HTML
extends
MediaBrotha_Frontend_HTTP
{
private
$_xml
=
NULL
;
private
$_body
=
NULL
;
private
$_mediaListElement
=
NULL
;
private
$_actionsListElement
=
NULL
;
private
function
_mediaActionLinks
(
$parent
,
$media
,
$tag_name
)
{
$url
=
$this
->
rootURL
()
.
'?'
.
MediaBrotha_Core
::
value2hash
(
'mime_type='
.
urlencode
(
$media
->
getMimeType
())
.
'&'
.
(
$media
->
getMimeEncoding
()
?
(
'mime_encoding='
.
urlencode
(
$media
->
getMimeEncoding
())
.
'&'
)
:
''
)
.
'uri='
.
urlencode
(
$media
->
getURI
()));
foreach
(
MediaBrotha_Core
::
getBackends
()
as
$backend
)
{
foreach
(
$backend
->
getMediaActions
(
$media
)
as
$action
)
{
$tag
=
$this
->
_xml
->
createElement
(
$tag_name
);
$tag
=
$parent
->
appendChild
(
$tag
);
$a
=
$this
->
_xml
->
createElement
(
'a'
);
$a
=
$tag
->
appendChild
(
$a
);
$a
->
setAttribute
(
'href'
,
"
$url
&"
.
MediaBrotha_Core
::
value2hash
(
'action='
.
$action
.
'&backend='
.
$backend
->
getBackendName
()));
$text
=
$this
->
_xml
->
createTextNode
(
$action
);
$text
=
$a
->
appendChild
(
$text
);
}
}
}
public
function
begin
(
$item
)
{
$this
->
_xml
=
new
DOMDocument
(
'1.0'
);
$root
=
$this
->
_xml
->
createElement
(
'html'
);
$root
=
$this
->
_xml
->
appendChild
(
$root
);
$head
=
$this
->
_xml
->
createElement
(
'head'
);
$head
=
$root
->
appendChild
(
$head
);
$title
=
$this
->
_xml
->
createElement
(
'title'
);
$title
=
$head
->
appendChild
(
$title
);
$text
=
$this
->
_xml
->
createTextNode
(
$item
->
getDisplayName
());
$text
=
$title
->
appendChild
(
$text
);
$style
=
$this
->
_xml
->
createElement
(
'link'
);
$style
=
$head
->
appendChild
(
$style
);
$style
->
setAttribute
(
'type'
,
'text/css'
);
$style
->
setAttribute
(
'rel'
,
'stylesheet'
);
$style
->
setAttribute
(
'href'
,
$this
->
rootURL
()
.
'static/default.css'
);
$script
=
$this
->
_xml
->
createElement
(
'script'
);
$script
=
$head
->
appendChild
(
$script
);
$script
->
setAttribute
(
'type'
,
'text/javascript'
);
$script
->
setAttribute
(
'src'
,
$this
->
rootURL
()
.
'static/dynamic.js'
);
$this
->
_body
=
$this
->
_xml
->
createElement
(
'body'
);
$this
->
_body
=
$root
->
appendChild
(
$this
->
_body
);
$this
->
_body
->
setAttribute
(
'onload'
,
'bodyLoaded();'
);
$this
->
_mediaListElement
=
$this
->
_xml
->
createElement
(
'ul'
);
$this
->
_mediaListElement
=
$this
->
_body
->
appendChild
(
$this
->
_mediaListElement
);
$this
->
_mediaListElement
->
setAttribute
(
'id'
,
'mediaListElement'
);
if
(
$parent
=
$item
->
getParent
())
{
$this
->
addItem
(
$parent
);
}
}
public
function
addItem
(
$item
)
{
$url
=
$this
->
rootURL
()
.
'?'
.
MediaBrotha_Core
::
value2hash
(
'mime_type='
.
urlencode
(
$item
->
getMimeType
())
.
'&'
.
(
$item
->
getMimeEncoding
()
?
(
'mime_encoding='
.
urlencode
(
$item
->
getMimeEncoding
())
.
'&'
)
:
''
)
.
'uri='
.
urlencode
(
$item
->
getURI
()));
$li
=
$this
->
_xml
->
createElement
(
'li'
);
$li
=
$this
->
_mediaListElement
->
appendChild
(
$li
);
$li
->
setAttribute
(
'class'
,
'mediaElement'
);
$a
=
$this
->
_xml
->
createElement
(
'a'
);
$a
=
$li
->
appendChild
(
$a
);
$a
->
setAttribute
(
'href'
,
$url
);
$text
=
$this
->
_xml
->
createTextNode
(
$item
->
getDisplayName
());
$text
=
$a
->
appendChild
(
$text
);
$ul
=
$this
->
_xml
->
createElement
(
'ul'
);
$ul
=
$li
->
appendChild
(
$ul
);
$ul
->
setAttribute
(
'class'
,
'mediaActionsListElement'
);
$this
->
_mediaActionLinks
(
$ul
,
$item
,
'li'
);
}
public
function
finish
(
$item
)
{
$this
->
_actionsListElement
=
$this
->
_xml
->
createElement
(
'ul'
);
$this
->
_actionsListElement
=
$this
->
_body
->
appendChild
(
$this
->
_actionsListElement
);
$this
->
_actionsListElement
->
setAttribute
(
'id'
,
'actionsListElement'
);
$this
->
_mediaActionLinks
(
$this
->
_actionsListElement
,
$item
,
'li'
);
}
public
function
render
()
{
print
$this
->
_xml
->
saveHTML
();
}
}
sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTTP.php
0 → 100644
浏览文件 @
855b7802
<?php
/*
Copyright 2011 Mathieu Parent <math.parent@gmail.com>
This file is part of MediaBrotha.
MediaBrotha is free software: you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
MediaBrotha is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MediaBrotha. If not, see
<http://www.gnu.org/licenses/>.
*/
/**
* @author Mathieu Parent
*/
class
MediaBrotha_Frontend_HTTP
extends
MediaBrotha_Frontend
{
public
function
rootURL
()
{
$url
=
'http://'
.
$_SERVER
[
'SERVER_NAME'
]
.
$_SERVER
[
'SCRIPT_NAME'
];
$url
=
preg_replace
(
'/index\.php$/'
,
''
,
$url
);
return
$url
;
}
}
sathieu/cisco-xml/lib/MediaBrotha/Media.php
浏览文件 @
855b7802
...
...
@@ -25,68 +25,100 @@ This file is part of MediaBrotha.
*/
class
MediaBrotha_Media
{
private
$_URI
=
NULL
;
private
$_metadata
=
Array
();
private
$_mimeType
=
NULL
;
private
$_mimeEncoding
=
NULL
;
public
function
__construct
(
$metadata
=
Array
())
{
$this
->
_metadata
=
$metadata
;
}
public
function
setMimeType
(
$mime_type
)
{
$this
->
_mimeType
=
$mime_type
;
}
public
function
getMimeType
()
{
// TODO
return
$this
->
_mimeType
;
}
public
function
setMimeEncoding
(
$mime_encoding
)
{
$this
->
_mimeEncoding
=
$mime_encoding
;
private
$_parent
=
NULL
;
public
function
__construct
(
$URI
,
array
$metadata
=
Array
(),
$mime_type
=
NULL
,
$mime_encoding
=
NULL
)
{
$this
->
_URI
=
$URI
;
$this
->
setMetadata
(
$metadata
);
$this
->
setMimeType
(
$mime_type
);
$this
->
setMimeEncoding
(
$mime_encoding
);
}
public
function
getMimeEncoding
()
{
// TODO
return
$this
->
_mimeEncoding
;
/* URI */
public
function
getURI
()
{
return
$this
->
_URI
;
}
public
function
getMetadata
(
$name
=
NULL
)
{
/* metadata */
public
function
getMetadata
(
$name
=
NULL
,
$max_length
=
NULL
)
{
if
(
$name
===
NULL
)
{
return
$this
->
_metadata
;
}
elseif
(
isset
(
$this
->
_metadata
[
$name
]))
{
return
$this
->
_metadata
[
$name
];
if
(
$max_length
)
{
return
substr
(
$this
->
_metadata
[
$name
],
0
,
$max_length
);
}
else
{
return
$this
->
_metadata
[
$name
];
}
}
else
{
return
NULL
;
}
}
public
function
setMetadata
(
$name
,
$value
)
{
public
function
setMetadata
(
$name
,
$value
=
NULL
)
{
if
(
is_array
(
$name
))
{
$this
->
_metadata
=
$name
;
}
else
{
switch
(
$name
)
{
case
'hidden'
:
case
'display_name'
:
case
'Array'
:
//music
case
'artist'
:
case
'album'
:
break
;
default
:
print
"Unusual metadata '
$name
'.
\n
"
;
}
$this
->
_metadata
[
$name
]
=
$value
;
}
}
/* Most used metadata */
public
function
getDisplayName
()
{
return
$this
->
getMetadata
(
'name'
);
/* mimeType */
public
function
getMimeType
()
{
return
$this
->
_mimeType
;
}
public
function
getURI
()
{
return
$this
->
getMetadata
(
'uri'
);
public
function
setMimeType
(
$mime_type
)
{
$this
->
_mimeType
=
$mime_type
;
}
/* mimeEncoding */
public
function
getMimeEncoding
()
{
return
$this
->
_mimeEncoding
;
}
public
function
setMimeEncoding
(
$mime_encoding
)
{
$this
->
_mimeEncoding
=
$mime_encoding
;
}
/* parent */
public
function
getParent
()
{
return
$this
->
_parent
;
}
public
function
setParent
(
$parent
)
{
$this
->
_parent
=
$parent
;
}
public
function
setURI
(
$value
)
{
return
$this
->
setMetadata
(
'uri'
,
$value
);
/* Most used metadata */
public
function
getDisplayName
(
$max_length
=
NULL
)
{
if
(
$name
=
$this
->
getMetadata
(
'display_name'
))
{
if
(
$max_length
)
{
return
substr
(
$name
,
0
,
$max_length
);
}
else
{
return
$name
;
}
}
else
{
return
'?'
;
}
}
public
function
getURIComponent
(
$component
)
{
return
parse_url
(
$this
->
getURI
(
$component
));
}
public
function
isHidden
()
{
return
isset
(
$this
->
_metadata
[
'hidden'
])
&&
$this
->
_metadata
[
'hidden'
]
;
return
(
bool
)
$this
->
getMetadata
(
'hidden'
)
;
}
}
/*
Mandatory metadata:
uri
name
Usual metadata:
artist
album
*/
sathieu/cisco-xml/lib/MediaBrotha/MediaIterator.php
0 → 100644
浏览文件 @
855b7802
<?php
/*
Copyright 2011 Mathieu Parent <math.parent@gmail.com>
This file is part of MediaBrotha.
MediaBrotha is free software: you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
MediaBrotha is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MediaBrotha. If not, see
<http://www.gnu.org/licenses/>.
*/
/**
* @author Mathieu Parent
*/
require_once
(
'MediaBrotha/Media.php'
);
class
MediaBrotha_MediaIterator
implements
Iterator
{
private
$_backend
=
NULL
;
private
$_media
=
NULL
;
private
$_handle
=
NULL
;
protected
$_buffer
=
NULL
;
public
function
__construct
(
MediaBrotha_Backend
$backend
,
MediaBrotha_Media
$media
,
$buffer
=
NULL
)
{
$this
->
_backend
=
$backend
;
$this
->
_media
=
$media
;
if
(
$buffer
)
{
$this
->
_buffer
=
$buffer
;
}
else
{
$this
->
_buffer
=
new
ArrayIterator
();
}
}
/* buffer */
public
function
bufferAdd
(
$media
)
{
$this
->
_buffer
[]
=
$media
;
}
/* iterator */
public
function
rewind
()
{
$this
->
_buffer
->
rewind
();
}
public
function
current
()
{
return
$this
->
_backend
->
mediaFromBufferItem
(
$this
->
_buffer
->
current
());
}
public
function
key
()
{
return
$this
->
_buffer
->
key
();
}
public
function
next
()
{
return
$this
->
_backend
->
mediaFromBufferItem
(
$this
->
_buffer
->
next
());
}
public
function
valid
()
{
return
$this
->
_buffer
->
valid
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论