Cheetah
ChWsbFormMedia.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import ('ChTemplFormView');
9 
14 {
15  var $_aMedia = array();
16 
17  function __construct ($aCustomForm)
18  {
19  if (isset($aCustomForm['inputs']['allow_post_in_forum_to']['type'])) {
20  $oModuleDb = new ChWsbModuleDb();
21  if (!$oModuleDb->getModuleByUri('forum'))
22  $aCustomForm['inputs']['allow_post_in_forum_to']['type'] = 'hidden';
23  }
24 
25  parent::__construct ($aCustomForm);
26  }
27 
37  function uploadPhotos ($sTag, $sCat, $sName = 'images', $sTitle = 'images_titles', $sTitleAlt = 'title')
38  {
39  $aRet = array ();
40  $aTitles = $this->getCleanValue($sTitle);
41 
42  foreach ($_FILES[$sName]['tmp_name'] as $i => $sUploadedFile) {
43  $aFileInfo = array (
44  'medTitle' => is_array($aTitles) && isset($aTitles[$i]) && $aTitles[$i] ? stripslashes($aTitles[$i]) : stripslashes($this->getCleanValue($sTitleAlt)),
45  'medDesc' => is_array($aTitles) && isset($aTitles[$i]) && $aTitles[$i] ? stripslashes($aTitles[$i]) : stripslashes($this->getCleanValue($sTitleAlt)),
46  'medTags' => $sTag,
47  'Categories' => array($sCat),
48  );
49  $aPathInfo = pathinfo ($_FILES[$sName]['name'][$i]);
50  $sTmpFile = CH_DIRECTORY_PATH_ROOT . 'tmp/i' . time() . $i . getLoggedId() . '.' . $aPathInfo['extension'];
51  if (move_uploaded_file($sUploadedFile, $sTmpFile)) {
52  $iRet = ChWsbService::call('photos', 'perform_photo_upload', array($sTmpFile, $aFileInfo, false), 'Uploader');
53  @unlink ($sTmpFile);
54  if ($iRet)
55  $aRet[] = $iRet;
56  }
57  }
58  return $aRet;
59  }
60 
70  function uploadVideos ($sTag, $sCat, $sName = 'videos', $sTitle = 'videos_titles', $sTitleAlt = 'title')
71  {
72  $aRet = array ();
73  $aTitles = $this->getCleanValue($sTitle);
74 
75  foreach ($_FILES[$sName]['tmp_name'] as $i => $sUploadedFile) {
76  $aFileInfo = array (
77  'title' => is_array($aTitles) && isset($aTitles[$i]) && $aTitles[$i] ? stripslashes($aTitles[$i]) : stripslashes($this->getCleanValue($sTitleAlt)),
78  'desc' => is_array($aTitles) && isset($aTitles[$i]) && $aTitles[$i] ? stripslashes($aTitles[$i]) : stripslashes($this->getCleanValue($sTitleAlt)),
79  'tags' => $sTag,
80  'categories' => $sCat,
81  );
82  $aPathInfo = pathinfo ($_FILES[$sName]['name'][$i]);
83  $sTmpFile = CH_DIRECTORY_PATH_ROOT . 'tmp/v' . time() . $i . getLoggedId() . '.' . $aPathInfo['extension'];
84  if (move_uploaded_file($sUploadedFile, $sTmpFile)) {
85  $iRet = ChWsbService::call('videos', 'perform_video_upload', array($sTmpFile, $aFileInfo, false), 'Uploader');
86  @unlink ($sTmpFile);
87  if ($iRet)
88  $aRet[] = $iRet;
89  }
90  }
91  return $aRet;
92  }
93 
103  function uploadSounds ($sTag, $sCat, $sName = 'sounds', $sTitle = 'sounds_titles', $sTitleAlt = 'title')
104  {
105  $aRet = array ();
106  $aTitles = $this->getCleanValue($sTitle);
107 
108  foreach ($_FILES[$sName]['tmp_name'] as $i => $sUploadedFile) {
109  $aFileInfo = array (
110  'title' => is_array($aTitles) && isset($aTitles[$i]) && $aTitles[$i] ? stripslashes($aTitles[$i]) : stripslashes($this->getCleanValue($sTitleAlt)),
111  'desc' => is_array($aTitles) && isset($aTitles[$i]) && $aTitles[$i] ? stripslashes($aTitles[$i]) : stripslashes($this->getCleanValue($sTitleAlt)),
112  'tags' => $sTag,
113  'categories' => $sCat,
114  );
115  $aPathInfo = pathinfo ($_FILES[$sName]['name'][$i]);
116  $sTmpFile = CH_DIRECTORY_PATH_ROOT . 'tmp/s' . time() . $i . getLoggedId() . '.' . $aPathInfo['extension'];
117  if (move_uploaded_file($sUploadedFile, $sTmpFile)) {
118  $iRet = ChWsbService::call('sounds', 'perform_music_upload', array($sTmpFile, $aFileInfo, false), 'Uploader');
119  @unlink ($sTmpFile);
120  if ($iRet)
121  $aRet[] = $iRet;
122  }
123  }
124  return $aRet;
125  }
126 
136  function uploadFiles ($sTag, $sCat, $sName = 'files', $sTitle = 'files_titles', $sTitleAlt = 'title')
137  {
138  $aRet = array ();
139  $aTitles = $this->getCleanValue($sTitle);
140 
141  foreach ($_FILES[$sName]['tmp_name'] as $i => $sUploadedFile) {
142  $aFileInfo = array (
143  'medTitle' => is_array($aTitles) && isset($aTitles[$i]) && $aTitles[$i] ? stripslashes($aTitles[$i]) : stripslashes($this->getCleanValue($sTitleAlt)),
144  'medDesc' => is_array($aTitles) && isset($aTitles[$i]) && $aTitles[$i] ? stripslashes($aTitles[$i]) : stripslashes($this->getCleanValue($sTitleAlt)),
145  'medTags' => $sTag,
146  'Categories' => array($sCat),
147  'Type' => $_FILES[$sName]['type'][$i],
148  );
149  $aPathInfo = pathinfo ($_FILES[$sName]['name'][$i]);
150  $sTmpFile = CH_DIRECTORY_PATH_ROOT . 'tmp/v' . time() . getLoggedId() . $i . '.' . $aPathInfo['extension'];
151  if (move_uploaded_file($sUploadedFile, $sTmpFile)) {
152  $iRet = ChWsbService::call('files', 'perform_file_upload', array($sTmpFile, $aFileInfo), 'Uploader');
153  @unlink ($sTmpFile);
154  if ($iRet)
155  $aRet[] = $iRet;
156  }
157  }
158  return $aRet;
159  }
160 
167  function insertMedia ($iEntryId, $aMedia, $sMediaType)
168  {
169  $aMediaValidated = $this->_validateMediaIds ($aMedia);
170  $this->_oDb->insertMedia ($iEntryId, $aMediaValidated, $sMediaType);
171  }
172 
181  function updateMedia ($iEntryId, $aMediaAdd, $aMediaDelete, $sMediaType)
182  {
183  $aMediaValidated = $this->_validateMediaIds ($aMediaAdd);
184  $this->_oDb->updateMedia ($iEntryId, $aMediaValidated, $aMediaDelete, $sMediaType);
185  }
186 
193  function deleteMedia ($iEntryId, $aMedia, $sMediaType)
194  {
195  $aMediaValidated = $this->_validateMediaIds ($aMedia);
196  $this->_oDb->deleteMedia ($iEntryId, $aMediaValidated, $sMediaType);
197  }
198 
202  function _validateMediaIds ($aMedia)
203  {
204  if (is_array ($aMedia)) {
205  $aMediaValidated = array ();
206  foreach ($aMedia as $iId) {
207  $iId = (int)$iId;
208  $aMediaValidated[$iId] = $iId;
209  }
210  return $aMediaValidated;
211  } else {
212  return (int)$aMedia;
213  }
214  }
215 
219  function _getFilesInEntry ($sModuleName, $sServiceMethod, $sName, $sMediaType, $iIdProfile, $iEntryId)
220  {
221 
222  $aReadyMedia = array ();
223  if ($iEntryId)
224  $aReadyMedia = $this->_oDb->getMediaIds($iEntryId, $sMediaType);
225 
226  if (!$aReadyMedia)
227  return array();
228 
229  $aDataEntry = $this->_oDb->getEntryById($iEntryId);
230 
231  $aFiles = array ();
232  foreach ($aReadyMedia as $iMediaId) {
233  switch ($sModuleName) {
234  case 'photos':
235  $aRow = ChWsbService::call($sModuleName, $sServiceMethod, array($iMediaId, 'icon'), 'Search');
236  break;
237  case 'sounds':
238  $aRow = ChWsbService::call($sModuleName, $sServiceMethod, array($iMediaId, 'browse'), 'Search');
239  break;
240  default:
241  $aRow = ChWsbService::call($sModuleName, $sServiceMethod, array($iMediaId), 'Search');
242  }
243 
244  if (!$this->_oMain->isEntryAdmin($aDataEntry, $iIdProfile) && $aRow['owner'] != $iIdProfile)
245  continue;
246 
247  $aFiles[] = array (
248  'name' => $sName,
249  'id' => $iMediaId,
250  'title' => $aRow['title'],
251  'icon' => $aRow['file'],
252  'owner' => $aRow['owner'],
253  'checked' => 'checked',
254  );
255  }
256  return $aFiles;
257  }
258 
265  function processMedia ($iEntryId, $iProfileId)
266  {
267  $aDataEntry = $this->_oDb->getEntryById($iEntryId);
268 
269  foreach ($this->_aMedia as $sName => $a) {
270 
271  $aFiles2Delete = array ();
272  $aFiles = $this->_getFilesInEntry ($a['module'], $a['service_method'], $a['post'], $sName, (int)$iProfileId, $iEntryId);
273  foreach ($aFiles as $aRow)
274  $aFiles2Delete[$aRow['id']] = $aRow['id'];
275 
276  if (is_array($_REQUEST[$a['post']]) && $_REQUEST[$a['post']] && $_REQUEST[$a['post']][0]) {
277  $this->updateMedia ($iEntryId, $_REQUEST[$a['post']], $aFiles2Delete, $sName);
278  } else {
279  $this->deleteMedia ($iEntryId, $aFiles2Delete, $sName);
280  }
281 
282  $sUploadFunc = $a['upload_func'];
283  if ($aMedia = $this->$sUploadFunc($a['tag'], $a['cat'])) {
284  $this->_oDb->insertMedia ($iEntryId, $aMedia, $sName);
285  if ($a['thumb'] && !$aDataEntry[$a['thumb']] && !$_REQUEST[$a['thumb']])
286  $this->_oDb->setThumbnail ($iEntryId, 0);
287  }
288 
289  $aMediaIds = $this->_oDb->getMediaIds($iEntryId, $sName);
290 
291  if ($a['thumb']) { // set thumbnail to another one if current thumbnail is deleted
292  $sThumbFieldName = $a['thumb'];
293  if ($aDataEntry[$sThumbFieldName] && !isset($aMediaIds[$aDataEntry[$sThumbFieldName]])) {
294  $this->_oDb->setThumbnail ($iEntryId, 0);
295  }
296  }
297 
298  // process all deleted media - delete actual file
299  $aDeletedMedia = array_diff ($aFiles2Delete, $aMediaIds);
300  if ($aDeletedMedia) {
301  foreach ($aDeletedMedia as $iMediaId) {
302  if (!$this->_oDb->isMediaInUse($iMediaId, $sName))
303  ChWsbService::call($a['module'], 'remove_object', array($iMediaId));
304  }
305  }
306  }
307 
308  }
309 
316  function generateCustomMediaTemplates ($iProfileId, $iEntryId, $iThumb = 0)
317  {
318  $aTemplates = array ();
319  foreach ($this->_aMedia as $sName => $a) {
320 
321  $aFiles = $this->_getFilesInEntry ($a['module'], $a['service_method'], $a['post'], $sName, (int)$iProfileId, $iEntryId);
322 
323  // files choice / check boxes
324  $aVarsChoice = array (
325  'ch_if:empty' => array(
326  'condition' => empty($aFiles),
327  'content' => array ()
328  ),
329  'ch_repeat:files' => $aFiles,
330  );
331  $aTemplates[$sName]['choice'] = $aFiles ? $this->_oMain->_oTemplate->parseHtmlByName('form_field_files_choice', $aVarsChoice) : '';
332 
333  // thumb choice / radio buttons
334  if ($a['thumb']) {
335  foreach ($aFiles as $k => $r) {
336  $aFiles[$k]['checked'] = ($iThumb == $r['id'] ? 'checked' : '');
337  $aFiles[$k]['name'] = $a['thumb'];
338  }
339  $aVarsThumbsChoice = array (
340  'ch_if:empty' => array (
341  'condition' => empty($aFiles),
342  'content' => array ()
343  ),
344  'ch_repeat:files' => $aFiles,
345  );
346  $aTemplates[$sName]['thumb_choice'] = $aFiles ? $this->_oMain->_oTemplate->parseHtmlByName('form_field_thumb_choice', $aVarsThumbsChoice) : '';
347  }
348 
349  // upload form
350  $aVarsUpload = array (
351  'file' => $sName,
352  'title' => $a['title_upload_post'],
353  'file_upload_title' => $a['title_upload'],
354  'ch_if:price' => array (
355  'condition' => false, 'content' => array('price' => '', 'file_price_title' => '')
356  ),
357  'ch_if:privacy' => array (
358  'condition' => false, 'content' => array('select' => '', 'file_permission_title' => '')
359  ),
360  );
361  $aTemplates[$sName]['upload'] = $this->_oMain->_oTemplate->parseHtmlByName('form_field_files_upload', $aVarsUpload);
362  }
363  return $aTemplates;
364  }
365 
367  {
368  $isAdmin = $GLOBALS['logged']['admin'] && isProfileActive($this->_iProfileId);
369 
370  defineMembershipActions (array('photos add', 'sounds add', 'videos add', 'files add'));
371 
372  if (defined('CH_PHOTOS_ADD'))
373  $aCheck = checkAction(getLoggedId(), CH_PHOTOS_ADD);
374  if (!defined('CH_PHOTOS_ADD') || ($aCheck[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED && !$isAdmin)) {
375  unset($aInputs['thumb']);
376  }
377 
378  $a = array ('images' => 'PHOTOS', 'videos' => 'VIDEOS', 'sounds' => 'SOUNDS', 'files' => 'FILES');
379  foreach ($a as $k => $v) {
380  if (defined("CH_{$v}_ADD"))
381  $aCheck = checkAction(getLoggedId(), constant("CH_{$v}_ADD"));
382  if ((!defined("CH_{$v}_ADD") || $aCheck[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED) && !$isAdmin) {
383  unset($this->_aMedia[$k]);
384  unset($aInputs['header_'.$k]);
385  unset($aInputs[$k.'_choice']);
386  unset($aInputs[$k.'_upload']);
387  }
388  }
389  }
390 }
ChTemplFormView
Definition: ChTemplFormView.php:11
isProfileActive
isProfileActive($iId=0)
Definition: profiles.inc.php:236
$aPathInfo
$aPathInfo
Definition: cmd.php:12
ChWsbForm\getCleanValue
getCleanValue($sName)
Definition: ChWsbForm.php:232
ChWsbFormMedia\_validateMediaIds
_validateMediaIds($aMedia)
Definition: ChWsbFormMedia.php:202
CHECK_ACTION_RESULT_ALLOWED
const CHECK_ACTION_RESULT_ALLOWED
Definition: membership_levels.inc.php:60
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
ChWsbFormMedia\_getFilesInEntry
_getFilesInEntry($sModuleName, $sServiceMethod, $sName, $sMediaType, $iIdProfile, $iEntryId)
Definition: ChWsbFormMedia.php:219
php
ChWsbModuleDb
Definition: ChWsbModuleDb.php:12
$iId
$iId
Definition: license.php:15
ChWsbFormMedia\insertMedia
insertMedia($iEntryId, $aMedia, $sMediaType)
Definition: ChWsbFormMedia.php:167
ChWsbFormMedia\uploadFiles
uploadFiles($sTag, $sCat, $sName='files', $sTitle='files_titles', $sTitleAlt='title')
Definition: ChWsbFormMedia.php:136
ChWsbFormMedia\deleteMedia
deleteMedia($iEntryId, $aMedia, $sMediaType)
Definition: ChWsbFormMedia.php:193
ChWsbFormMedia\processMedia
processMedia($iEntryId, $iProfileId)
Definition: ChWsbFormMedia.php:265
ChWsbFormMedia\uploadSounds
uploadSounds($sTag, $sCat, $sName='sounds', $sTitle='sounds_titles', $sTitleAlt='title')
Definition: ChWsbFormMedia.php:103
ChWsbFormMedia
Definition: ChWsbFormMedia.php:14
$oModuleDb
$oModuleDb
Definition: classifieds.php:20
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
$sTitle
$sTitle
Definition: actions.inc.php:13
ChWsbForm\$aInputs
$aInputs
Definition: ChWsbForm.php:109
$_REQUEST
$_REQUEST['action']
Definition: cmd.php:11
ChWsbFormMedia\uploadVideos
uploadVideos($sTag, $sCat, $sName='videos', $sTitle='videos_titles', $sTitleAlt='title')
Definition: ChWsbFormMedia.php:70
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
ChWsbFormMedia\$_aMedia
$_aMedia
Definition: ChWsbFormMedia.php:15
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
ChWsbFormMedia\processMembershipChecksForMediaUploads
processMembershipChecksForMediaUploads(&$aInputs)
Definition: ChWsbFormMedia.php:366
ChWsbFormMedia\uploadPhotos
uploadPhotos($sTag, $sCat, $sName='images', $sTitle='images_titles', $sTitleAlt='title')
Definition: ChWsbFormMedia.php:37
ChWsbFormMedia\updateMedia
updateMedia($iEntryId, $aMediaAdd, $aMediaDelete, $sMediaType)
Definition: ChWsbFormMedia.php:181
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChWsbService\call
static call($mixed, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbService.php:32
ChWsbFormMedia\generateCustomMediaTemplates
generateCustomMediaTemplates($iProfileId, $iEntryId, $iThumb=0)
Definition: ChWsbFormMedia.php:316
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbFormMedia\__construct
__construct($aCustomForm)
Definition: ChWsbFormMedia.php:17
$sName
$sName
Definition: ChWsbAdminTools.php:853
$iProfileId
if( $sMembersList) $iProfileId
Definition: communicator.php:29
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10