PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_hwdmediashare/controllers/addmedia.php

https://gitlab.com/ppapadatis/Videolearn
PHP | 188 lines | 131 code | 18 blank | 39 comment | 13 complexity | f59a343750f2696583d98560985b03d2 MD5 | raw file
  1. <?php
  2. /**
  3. * @version SVN $Id: addmedia.php 1014 2013-01-30 14:36:00Z dhorsfall $
  4. * @package hwdMediaShare
  5. * @copyright Copyright (C) 2012 Highwood Design Limited. All rights reserved.
  6. * @license GNU General Public License http://www.gnu.org/copyleft/gpl.html
  7. * @author Dave Horsfall
  8. * @since 19-Jan-2012 13:32:50
  9. */
  10. // No direct access to this file
  11. defined('_JEXEC') or die('Restricted access');
  12. // Import Joomla controllerform library
  13. jimport('joomla.application.component.controllerform');
  14. /**
  15. * hwdMediaShare Controller
  16. */
  17. class hwdMediaShareControllerAddMedia extends JControllerForm
  18. {
  19. /**
  20. * Method to process file upload
  21. * @since 0.1
  22. */
  23. function upload()
  24. {
  25. $app = & JFactory::getApplication();
  26. $user = JFactory::getUser();
  27. // Get hwdMediaShare config
  28. $hwdms = hwdMediaShareFactory::getInstance();
  29. $config = $hwdms->getConfig();
  30. $upload = new stdClass();
  31. $upload->input = 'Filedata';
  32. hwdMediaShareFactory::load('upload');
  33. $model = hwdMediaShareUpload::getInstance();
  34. // Add embed code
  35. if (!$model->process($upload))
  36. {
  37. JError::raiseWarning(500, $model->getError());
  38. $this->setRedirect(hwdMediaShareHelperRoute::getUploadRoute());
  39. }
  40. else
  41. {
  42. if ($user->id)
  43. {
  44. if ($config->get('approve_new_media'))
  45. {
  46. JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_HWDMS_SUCCESSFULLY_UPLOADED_X', $model->_title));
  47. $this->setRedirect(hwdMediaShareHelperRoute::getMyMediaRoute());
  48. }
  49. else
  50. {
  51. JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_HWDMS_SUCCESSFULLY_UPLOADED_X', $model->_title).' (<a href="index.php?option=com_hwdmediashare&task=mediaform.edit&id='.$model->_id.'&return='.base64_encode(hwdMediaShareHelperRoute::getMediaItemRoute($model->_id)).'">'.JText::_('COM_HWDMS_EDIT_MEDIA').'</a>)');
  52. $this->setRedirect(hwdMediaShareHelperRoute::getMediaItemRoute($model->_id));
  53. }
  54. }
  55. else
  56. {
  57. if ($config->get('approve_new_media'))
  58. {
  59. JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_HWDMS_SUCCESSFULLY_UPLOADED_X', $model->_title));
  60. $this->setRedirect(hwdMediaShareHelperRoute::getMediaRoute());
  61. }
  62. else
  63. {
  64. JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_HWDMS_SUCCESSFULLY_UPLOADED_X', $model->_title));
  65. $this->setRedirect(hwdMediaShareHelperRoute::getMediaItemRoute($model->_id));
  66. }
  67. }
  68. }
  69. }
  70. /**
  71. * Method to process uber upload
  72. * @since 0.1
  73. */
  74. function uber()
  75. {
  76. $app = & JFactory::getApplication();
  77. $user = JFactory::getUser();
  78. $upload = new stdClass();
  79. $upload->input = 'Filedata';
  80. hwdMediaShareFactory::load('upload');
  81. $model = hwdMediaShareUpload::getInstance();
  82. // Add embed code
  83. if (!$model->uber($upload))
  84. {
  85. JError::raiseWarning(500, $model->getError());
  86. $this->setRedirect(hwdMediaShareHelperRoute::getUploadRoute());
  87. }
  88. else
  89. {
  90. if ($user->id)
  91. {
  92. JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_HWDMS_SUCCESSFULLY_UPLOADED_X', $model->_title).' (<a href="index.php?option=com_hwdmediashare&task=mediaform.edit&id='.$model->_id.'">'.JText::_('COM_HWDMS_EDIT_MEDIA').'</a>)');
  93. $this->setRedirect(hwdMediaShareHelperRoute::getMyMediaRoute());
  94. }
  95. else
  96. {
  97. JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_HWDMS_SUCCESSFULLY_UPLOADED_X', $model->_title));
  98. $this->setRedirect(hwdMediaShareHelperRoute::getMediaItemRoute($model->_id));
  99. }
  100. }
  101. }
  102. /**
  103. * Method to process embed code import
  104. * @since 0.1
  105. */
  106. function remote()
  107. {
  108. $app = & JFactory::getApplication();
  109. $user = JFactory::getUser();
  110. // Get hwdMediaShare config
  111. $hwdms = hwdMediaShareFactory::getInstance();
  112. $config = $hwdms->getConfig();
  113. hwdMediaShareFactory::load('remote');
  114. $model = hwdMediaShareRemote::getInstance();
  115. // Add embed code
  116. if (!$model->addRemote())
  117. {
  118. JError::raiseWarning(500, $model->getError());
  119. $this->setRedirect(hwdMediaShareHelperRoute::getUploadRoute());
  120. }
  121. else
  122. {
  123. if ($user->id)
  124. {
  125. if ($model->_count > 1 || $config->get('approve_new_media'))
  126. {
  127. JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_HWDMS_SUCCESSFULLY_ADDED_X_REMOTES', $model->_count));
  128. $this->setRedirect(hwdMediaShareHelperRoute::getMyMediaRoute());
  129. }
  130. else
  131. {
  132. JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_HWDMS_SUCCESSFULLY_ADDED_X', $model->_title).' (<a href="index.php?option=com_hwdmediashare&task=mediaform.edit&id='.$model->_id.'&return='.base64_encode(hwdMediaShareHelperRoute::getMediaItemRoute($model->_id)).'">'.JText::_('COM_HWDMS_EDIT_MEDIA').'</a>)');
  133. $this->setRedirect(hwdMediaShareHelperRoute::getMediaItemRoute($model->_id));
  134. }
  135. }
  136. else
  137. {
  138. if ($model->_count > 1 || $config->get('approve_new_media'))
  139. {
  140. JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_HWDMS_SUCCESSFULLY_ADDED_X_REMOTES', $model->_count));
  141. $this->setRedirect(hwdMediaShareHelperRoute::getMediaRoute());
  142. }
  143. else
  144. {
  145. JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_HWDMS_SUCCESSFULLY_ADDED_X', $model->_title));
  146. $this->setRedirect(hwdMediaShareHelperRoute::getMediaItemRoute($model->_id));
  147. }
  148. }
  149. }
  150. }
  151. /**
  152. * Method to report a media item
  153. *
  154. * @param int Optional primary key of the article to increment.
  155. *
  156. * @return boolean True if successful; false otherwise and internal error set.
  157. */
  158. public function terms()
  159. {
  160. // Check for request forgeries
  161. JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  162. // Get the model.
  163. $model = $this->getModel('Upload', 'hwdMediaShareModel');
  164. if (!$model->terms())
  165. {
  166. JFactory::getApplication()->enqueueMessage( $model->getError() );
  167. }
  168. JFactory::getApplication()->redirect( base64_decode(JRequest::getVar('return', '')) );
  169. }
  170. }