Cheetah
ChWsbXMLRPCMedia.php
Go to the documentation of this file.
1 <?php
2 
9 {
10  // ----------------- albums list
11 
12  function _getMediaAlbums ($sType, $iIdProfile, $iIdProfileViewer, $isShowEmptyAlbums = false)
13  {
14  $aAlbums = (new ChWsbXMLRPCMedia)->_getMediaAlbumsArray ($sType, $iIdProfile, $iIdProfileViewer, $isShowEmptyAlbums);
15 
16  $aXmlRpc = array ();
17 
18  foreach ($aAlbums as $r) {
19  $a = array (
20  'Id' => new xmlrpcval($r['Id']),
21  'Title' => new xmlrpcval($r['Title']),
22  'Num' => new xmlrpcval($r['Num']),
23  'DefaultAlbum' => new xmlrpcval($r['DefaultAlbum']),
24  );
25  $aXmlRpc[] = new xmlrpcval($a, 'struct');
26  }
27 
28  return new xmlrpcval ($aXmlRpc, "array");
29  }
30 
31  function _getMediaCount ($sType, $iIdProfile, $iIdProfileViewer)
32  {
33  $a = (new ChWsbXMLRPCMedia)->_getMediaAlbumsArray ($sType, $iIdProfile, $iIdProfileViewer);
34  $iNum = 0;
35  foreach ($a as $r)
36  $iNum += $r['Num'];
37  return $iNum;
38  }
39 
40  function _getMediaAlbumsArray ($sType, $iIdProfile, $iIdProfileViewer, $isShowEmptyAlbums = false)
41  {
42  switch ($sType) {
43  case 'photo':
44  $sModuleName = 'photos';
45  $sType = 'ch_photos';
46  $sMemAction = 'CH_PHOTOS_VIEW';
47  break;
48  case 'video':
49  $sModuleName = 'videos';
50  $sType = 'ch_videos';
51  $sMemAction = 'CH_VIDEOS_VIEW';
52  break;
53  case 'music':
54  $sModuleName = 'sounds';
55  $sType = 'ch_sounds';
56  $sMemAction = 'CH_SOUNDS_VIEW';
57  break;
58  default:
59  return array();
60  }
61 
62  if (!ChWsbXMLRPCMedia::_isMembershipEnabledFor($iIdProfileViewer, $sMemAction))
63  return array ();
64 
65  ch_import('ChWsbMemberInfo');
66  $oMemberInfo = ChWsbMemberInfo::getObjectInstance(getParam('sys_member_info_thumb'));
67  $isSetAvatarFromDefaultAlbumOnly = $oMemberInfo->isSetAvatarFromDefaultAlbumOnly();
68 
69  ch_import('ChWsbAlbums');
70  $o = new ChWsbAlbums ($sType, (int)$iIdProfile);
71  $aList = $o->getAlbumList (array('owner' => (int)$iIdProfile, 'show_empty' => $isShowEmptyAlbums), 1, 1000);
72  $aRet = array ();
73  foreach ($aList as $r) {
74  if (!ChWsbService::call ($sModuleName, 'get_album_privacy', array((int)$r['ID'], $iIdProfileViewer), 'Search'))
75  continue;
76 
77  if ($isSetAvatarFromDefaultAlbumOnly) {
78  ch_import('ChWsbAlbums');
79  $isDefaulAlbum = $r['Uri'] == ChWsbAlbums::getAbumUri(getParam($sType . '_profile_album_name'), $iIdProfile) ? 1 : 0;
80  }
81  else
82  $isDefaulAlbum = 1;
83 
84  $aRet[] = array (
85  'Id' => $r['ID'],
86  'Title' => $r['Caption'],
87  'Num' => $r['ObjCount'],
88  'DefaultAlbum' => $isDefaulAlbum,
89  );
90  }
91  return $aRet;
92  }
93 
94  // ----------------- file list in albums
95 
96  function _getFilesInAlbum ($sModuleName, $iIdProfile, $iIdProfileViewer, $iAlbumId, $sWidget = '', $sFuncToken = '', $sTokenUrl = '')
97  {
98  if ($sWidget && preg_match('/^[a-zA-Z0-9_]+$/', $sWidget)) {
99  require_once (CH_DIRECTORY_PATH_ROOT . "flash/modules/global/inc/db.inc.php");
100  require_once (CH_DIRECTORY_PATH_ROOT . "flash/modules/{$sWidget}/inc/header.inc.php");
101  require_once (CH_DIRECTORY_PATH_ROOT . "flash/modules/{$sWidget}/inc/constants.inc.php");
102  require_once (CH_DIRECTORY_PATH_ROOT . "flash/modules/{$sWidget}/inc/functions.inc.php");
103  }
104 
105  $a = ChWsbService::call ($sModuleName, 'get_files_in_album', array((int)$iAlbumId, $iIdProfileViewer != $iIdProfile, $iIdProfileViewer, array('per_page' => 100)), 'Search');
106  if (!$a)
107  return new xmlrpcval (array(), "array");
108  foreach ($a as $k => $aRow) {
109  if ('youtube' == $aRow['Source']) {
110  $sUrl = $aRow['Video'];
111  } else {
112  $sToken = '';
113  if ($sFuncToken)
114  $sToken = $sFuncToken($aRow['id']);
115 
116  $sUrl = $sTokenUrl && $sToken ? CH_WSB_URL_ROOT . $sTokenUrl . $aRow['id'] . '&token=' . $sToken : $aRow['file'];
117  }
118 
119  $a = array (
120  'id' => new xmlrpcval($aRow['id']),
121  'title' => new xmlrpcval($aRow['title']),
122  'desc' => new xmlrpcval(ChWsbService::call ($sModuleName, 'get_length', array($aRow['size']), 'Search')),
123  'icon' => new xmlrpcval($aRow['icon']),
124  'thumb' => new xmlrpcval($aRow['thumb']),
125  'file' => new xmlrpcval($sUrl),
126  'cat' => new xmlrpcval($sCat),
127  'rate' => new xmlrpcval($aRow['Rate']),
128  'rate_count' => new xmlrpcval((int)$aRow['RateCount']),
129  );
130  $aFiles[] = new xmlrpcval($a, 'struct');
131  }
132  return new xmlrpcval ($aFiles, "array");
133  }
134 
135  function _isMembershipEnabledFor ($iProfileId, $sMembershipActionConstant, $isPerformAction = false)
136  {
137  defineMembershipActions (array('photos add', 'photos view', 'sounds view', 'sounds add', 'videos view', 'videos add'));
138  if (!defined($sMembershipActionConstant))
139  return false;
140  $aCheck = checkAction($iProfileId ? $iProfileId : (int)$_COOKIE['memberID'], constant($sMembershipActionConstant), $isPerformAction);
142  }
143 
144  // ----------------- upload
145 
146 
147  function _uploadFile ($sType, $sUser, $sPwd, $sAlbum, $binData, $iDataLength, $sTitle, $sTags, $sDesc, $sExt)
148  {
149  $sFieldTitle = 'title';
150  $sFieldDesc = 'desc';
151  $sFieldTags = 'tags';
152  $sFieldCats = 'categories';
153  $sFieldAlbum = 'album';
154  switch ($sType) {
155  case 'photo':
156  $sModuleName = 'photos';
157  $sService = 'perform_photo_upload';
158  $sMemAction = 'CH_PHOTOS_ADD';
159  $sFieldTitle = 'medTitle';
160  $sFieldDesc = 'medDesc';
161  $sFieldTags = 'medTags';
162  $sFieldCats = 'Categories';
163  $sFieldAlbum = 'album';
164  $sModuleUnit = 'ch_photos';
165  break;
166  case 'video':
167  $sModuleName = 'videos';
168  $sService = 'perform_video_upload';
169  $sMemAction = 'CH_VIDEOS_ADD';
170  $sModuleUnit = 'ch_videos';
171  break;
172  case 'music':
173  $sModuleName = 'sounds';
174  $sService = 'perform_sound_upload';
175  $sMemAction = 'CH_SOUNDS_ADD';
176  $sModuleUnit = 'ch_sounds';
177  break;
178  default:
179  return array();
180  }
181 
183  return new xmlrpcresp(new xmlrpcval(array('error' => new xmlrpcval(1,"int")), "struct"));
184 
185  if (!ChWsbXMLRPCMedia::_isMembershipEnabledFor($iId, $sMemAction, true))
186  return new xmlrpcval ("fail access");
187 
188  if (!ChWsbService::call($sModuleName, 'is_ext_allowed', array($sExt), 'Uploader'))
189  return new xmlrpcval ("fail wrong extension - " . $sExt);
190 
191  // write tmp file
192 
193  $sTmpFilename = CH_DIRECTORY_PATH_ROOT . "tmp/" . time() . $sType . $iId . '.' . $sExt;
194  $f = fopen($sTmpFilename, "wb");
195  if (!$f)
196  return new xmlrpcval ("fail fopen");
197  if (!fwrite ($f, $binData, (int)$iDataLength)) {
198  fclose($f);
199  return new xmlrpcval ("fail write");
200  }
201  fclose($f);
202 
203  // upload
204  $aFileInfo = array();
205  $aFileInfo[$sFieldTitle] = $sTitle;
206  $aFileInfo[$sFieldDesc] = $sDesc;
207  $aFileInfo[$sFieldTags] = $sTags;
208  $aFileInfo[$sFieldCats] = 'photo' == $sType ? array ($sAlbum) : $sAlbum;
209  $aFileInfo[$sFieldAlbum] = $sAlbum;
210 
211  if ('photo' == $sType && ChWsbService::call($sModuleName, $sService, array($sTmpFilename, $aFileInfo, 0, $iId), 'Uploader')) {
212  return new xmlrpcval ("ok");
213  } elseif ('photo' != $sType && ($iFileId = ChWsbService::call($sModuleName, $sService, array($sTmpFilename, $aFileInfo, true), 'Uploader'))) {
214  $oZ = new ChWsbAlerts($sModuleUnit, 'add', $iFileId , $iId);
215  $oZ->alert();
216  return new xmlrpcval ("ok");
217  } else {
218  return new xmlrpcval ("fail upload");
219  }
220  }
221 
222 }
$sToken
$sToken
Definition: get_file.php:13
ChWsbMemberInfo\getObjectInstance
static getObjectInstance($sObject)
Definition: ChWsbMemberInfo.php:39
$f
global $f
Definition: callback.php:13
CHECK_ACTION_RESULT_ALLOWED
const CHECK_ACTION_RESULT_ALLOWED
Definition: membership_levels.inc.php:60
ChWsbXMLRPCMedia\_isMembershipEnabledFor
_isMembershipEnabledFor($iProfileId, $sMembershipActionConstant, $isPerformAction=false)
Definition: ChWsbXMLRPCMedia.php:135
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
CHECK_ACTION_RESULT
const CHECK_ACTION_RESULT
Definition: membership_levels.inc.php:54
xmlrpcval
Definition: xmlrpc.inc:2696
$sUrl
$sUrl
Definition: cart.php:15
php
$oZ
$oZ
Definition: db.php:20
ChWsbXMLRPCMedia\_getMediaAlbums
_getMediaAlbums($sType, $iIdProfile, $iIdProfileViewer, $isShowEmptyAlbums=false)
Definition: ChWsbXMLRPCMedia.php:12
$iId
$iId
Definition: license.php:15
$sExt
$sExt
Definition: get_file.php:14
$sPwd
$sPwd
Definition: r.php:14
ChWsbXMLRPCMedia\_getMediaCount
_getMediaCount($sType, $iIdProfile, $iIdProfileViewer)
Definition: ChWsbXMLRPCMedia.php:31
ChWsbXMLRPCMedia\_getMediaAlbumsArray
_getMediaAlbumsArray($sType, $iIdProfile, $iIdProfileViewer, $isShowEmptyAlbums=false)
Definition: ChWsbXMLRPCMedia.php:40
ChWsbXMLRPCMedia\_uploadFile
_uploadFile($sType, $sUser, $sPwd, $sAlbum, $binData, $iDataLength, $sTitle, $sTags, $sDesc, $sExt)
Definition: ChWsbXMLRPCMedia.php:147
$sWidget
$sWidget
Definition: actions.inc.php:18
ChWsbAlerts
Definition: ChWsbAlerts.php:39
$sType
$sType
Definition: actions.inc.php:11
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
$sTitle
$sTitle
Definition: actions.inc.php:13
ChWsbAlbums
Definition: ChWsbAlbums.php:9
$sTags
$sTags
Definition: actions.inc.php:12
ChWsbXMLRPCMedia
Definition: ChWsbXMLRPCMedia.php:9
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
checkAction
checkAction($iMemberId, $actionID, $performAction=false, $iForcedProfID=0, $isCheckMemberStatus=true)
Definition: membership_levels.inc.php:313
defineMembershipActions
defineMembershipActions($aActionsAll, $sPrefix='CH_')
Definition: membership_levels.inc.php:744
$iFileId
$iFileId
Definition: embed.php:12
ChWsbXMLRPCMedia\_getFilesInAlbum
_getFilesInAlbum($sModuleName, $iIdProfile, $iIdProfileViewer, $iAlbumId, $sWidget='', $sFuncToken='', $sTokenUrl='')
Definition: ChWsbXMLRPCMedia.php:96
xmlrpcresp
Definition: xmlrpc.inc:1911
ChWsbXMLRPCUtil\checkLogin
static checkLogin($sUser, $sPwd)
Definition: ChWsbXMLRPCUtil.php:239
$o
$o
Definition: cmd.php:193
ChWsbService\call
static call($mixed, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbService.php:32
$sDesc
$sDesc
Definition: actions.inc.php:21
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$iProfileId
if( $sMembersList) $iProfileId
Definition: communicator.php:29
ChWsbAlbums\getAbumUri
static getAbumUri($sName, $iUserId)
Definition: ChWsbAlbums.php:50
$sUser
$sUser
Definition: r.php:13