HomeHelpTrac

source: trunk/xmlrpc/BxDolXMLRPCMedia.php @ 15557

Revision 15557, 6.7 KB checked in by Alexander Trofimov, 4 months ago (diff)

Ticket #2642

Line 
1<?php
2
3class BxDolXMLRPCMedia
4{
5    // ----------------- albums list
6
7    function getAudioAlbums ($sUser, $sPwd, $sNick)
8    {
9        $iIdProfile = BxDolXMLRPCUtil::getIdByNickname ($sNick);
10        if (!$iIdProfile || !($iId = BxDolXMLRPCUtil::checkLogin ($sUser, $sPwd)))
11            return new xmlrpcresp(new xmlrpcval(array('error' => new xmlrpcval(1,"int")), "struct"));
12
13        return BxDolXMLRPCMedia::_getMediaAlbums ('music', $iIdProfile, $iId);
14    }
15
16    function getVideoAlbums ($sUser, $sPwd, $sNick)
17    {
18        $iIdProfile = BxDolXMLRPCUtil::getIdByNickname ($sNick);
19        if (!$iIdProfile || !($iId = BxDolXMLRPCUtil::checkLogin ($sUser, $sPwd)))
20            return new xmlrpcresp(new xmlrpcval(array('error' => new xmlrpcval(1,"int")), "struct"));
21
22        return BxDolXMLRPCMedia::_getMediaAlbums ('video', $iIdProfile, $iId);
23    }
24
25    function _getMediaAlbums ($sType, $iIdProfile, $iIdProfileViewer, $isShowEmptyAlbums = false)
26    {
27        $aAlbums = BxDolXMLRPCMedia::_getMediaAlbumsArray ($sType, $iIdProfile, $iIdProfileViewer, $isShowEmptyAlbums);
28
29        $aXmlRpc = array ();
30
31        foreach ($aAlbums as $r)
32        {
33            $a = array (
34                'Id' => new xmlrpcval($r['Id']),
35                'Title' => new xmlrpcval($r['Title']),
36                'Num' =>new xmlrpcval($r['Num']),
37            );
38            $aXmlRpc[] = new xmlrpcval($a, 'struct');
39        }
40
41        return new xmlrpcval ($aXmlRpc, "array");
42    }
43
44    function _getMediaCount ($sType, $iIdProfile, $iIdProfileViewer) {
45        $a = BxDolXMLRPCMedia::_getMediaAlbumsArray ($sType, $iIdProfile, $iIdProfileViewer);
46        $iNum = 0;
47        foreach ($a as $r)
48            $iNum += $r['Num'];
49        return $iNum;
50    }
51
52    function _getMediaAlbumsArray ($sType, $iIdProfile, $iIdProfileViewer, $isShowEmptyAlbums = false)
53    {
54        switch ($sType) {
55            case 'photo':
56                $sModuleName = 'photos';
57                $sType = 'bx_photos';
58                $sMemAction = 'BX_PHOTOS_VIEW';
59                break;
60            case 'video':
61                $sModuleName = 'videos';
62                $sType = 'bx_videos';
63                $sMemAction = 'BX_VIDEOS_VIEW';
64                break;
65            case 'music':
66                $sModuleName = 'sounds';
67                $sType = 'bx_sounds';
68                $sMemAction = 'BX_SOUNDS_VIEW';
69                break;
70            default:
71                return array();
72        }
73
74        if (!BxDolXMLRPCMedia::_isMembershipEnabledFor($iIdProfileViewer, $sMemAction))
75            return array ();
76
77        bx_import('BxDolAlbums');
78        $o = new BxDolAlbums ($sType, (int)$iIdProfile);
79        $aList = $o->getAlbumList (array('owner' => (int)$iIdProfile, 'show_empty' => $isShowEmptyAlbums), 1, 1000);
80        $aRet = array ();
81        foreach ($aList as $r)
82        {
83            if ($iIdProfile != $iIdProfileViewer && !BxDolService::call ($sModuleName, 'get_album_privacy', array((int)$r['ID'], $iIdProfileViewer), 'Search'))
84                continue;
85
86            $aRet[] = array (
87                'Id' => $r['ID'],
88                'Title' => $r['Caption'],
89                'Num' => $r['ObjCount'],
90            );
91        }
92        return $aRet;
93    }
94
95    // ----------------- file list in albums
96
97    function getVideoInAlbum($sUser, $sPwd, $sNick, $iAlbumId)
98    {
99        $iIdProfile = BxDolXMLRPCUtil::getIdByNickname ($sNick);
100        if (!$iIdProfile || !($iId = BxDolXMLRPCUtil::checkLogin ($sUser, $sPwd)))
101            return new xmlrpcresp(new xmlrpcval(array('error' => new xmlrpcval(1,"int")), "struct"));
102
103        return BxDolXMLRPCMedia::_getFilesInAlbum ('videos', $iIdProfile, $iId, $iAlbumId, 'video', 'getToken', 'flash/modules/video/get_mobile.php?id=');
104    }
105
106    function getAudioInAlbum($sUser, $sPwd, $sNick, $iAlbumId)
107    {
108        $iIdProfile = BxDolXMLRPCUtil::getIdByNickname ($sNick);
109        if (!$iIdProfile || !($iId = BxDolXMLRPCUtil::checkLogin ($sUser, $sPwd)))
110            return new xmlrpcresp(new xmlrpcval(array('error' => new xmlrpcval(1,"int")), "struct"));
111
112        return BxDolXMLRPCMedia::_getFilesInAlbum ('sounds', $iIdProfile, $iId, $iAlbumId, 'mp3', 'getMp3Token', 'flash/modules/mp3/get_file.php?id=');
113    }
114
115    function _getFilesInAlbum ($sModuleName, $iIdProfile, $iIdProfileViewer, $iAlbumId, $sWidget = '', $sFuncToken = '', $sTokenUrl = '')
116    {
117        if ($sWidget && preg_match('/^[a-zA-Z0-9_]+$/', $sWidget)) {
118            require_once (BX_DIRECTORY_PATH_ROOT . "flash/modules/global/inc/db.inc.php");
119            require_once (BX_DIRECTORY_PATH_ROOT . "flash/modules/{$sWidget}/inc/header.inc.php");
120            require_once (BX_DIRECTORY_PATH_ROOT . "flash/modules/{$sWidget}/inc/constants.inc.php");
121            require_once (BX_DIRECTORY_PATH_ROOT . "flash/modules/{$sWidget}/inc/functions.inc.php");
122        }
123
124        $a = BxDolService::call ($sModuleName, 'get_files_in_album', array((int)$iAlbumId, $iIdProfileViewer != $iIdProfile, $iIdProfileViewer, array('per_page' => 100)), 'Search');
125        if (!$a)
126            return new xmlrpcval (array(), "array");
127        foreach ($a as $k => $aRow)
128        {
129            if ('youtube' == $aRow['Source'])
130            {
131                $sUrl = $aRow['Video'];
132            }
133            else
134            {
135                $sToken = '';
136                if ($sFuncToken)
137                    $sToken = $sFuncToken($aRow['id']);
138
139                $sUrl = $sTokenUrl && $sToken ? BX_DOL_URL_ROOT . $sTokenUrl . $aRow['id'] . '&token=' . $sToken : $aRow['file'];
140            }
141
142            $a = array (
143                'id' => new xmlrpcval($aRow['id']),
144                'title' => new xmlrpcval($aRow['title']),
145                'desc' => new xmlrpcval(BxDolService::call ($sModuleName, 'get_length', array($aRow['size']), 'Search')),
146                'icon' => new xmlrpcval($aRow['icon']),
147                'thumb' => new xmlrpcval($aRow['thumb']),
148                'file' => new xmlrpcval($sUrl),
149                'cat' => new xmlrpcval($sCat),
150                'rate' => new xmlrpcval($aRow['Rate']),
151                'rate_count' => new xmlrpcval((int)$aRow['RateCount']),
152            );
153            $aFiles[] = new xmlrpcval($a, 'struct');
154        }
155        return new xmlrpcval ($aFiles, "array");
156    }
157
158    function _isMembershipEnabledFor ($iProfileId, $sMembershipActionConstant, $isPerformAction = false) {
159        defineMembershipActions (array('photos add', 'photos view', 'sounds view', 'videos view'));
160        if (!defined($sMembershipActionConstant))
161            return false;
162        $aCheck = checkAction($iProfileId ? $iProfileId : $_COOKIE['memberID'], constant($sMembershipActionConstant), $isPerformAction);
163        return $aCheck[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
164    }
165}
166
167?>
Note: See TracBrowser for help on using the repository browser.