PageRenderTime 27ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/community/media/media.php

https://gitlab.com/ppapadatis/Videolearn
PHP | 309 lines | 220 code | 54 blank | 35 comment | 25 complexity | 807198719d20704d46f62156cc436d65 MD5 | raw file
  1. <?php
  2. /**
  3. * @version SVN $Id: media.php 1011 2013-01-30 14:12:52Z 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 27-Feb-2012 16:29:22
  9. */
  10. // No direct access to this file
  11. defined('_JEXEC') or die('Restricted access');
  12. if (file_exists(JPATH_BASE.'/components/com_community/libraries/core.php'))
  13. {
  14. require_once( JPATH_BASE.'/components/com_community/libraries/core.php');
  15. }
  16. else
  17. {
  18. return true;
  19. }
  20. class plgCommunityMedia extends CApplications
  21. {
  22. var $name = 'hwdMediaShare';
  23. var $_name = 'hwdmediashare';
  24. function plgCommunityMedia(& $subject, $config)
  25. {
  26. parent::__construct($subject, $config);
  27. }
  28. function onProfileDisplay()
  29. {
  30. $config =& CFactory::getConfig();
  31. $this->loadUserParams();
  32. $uri = JURI::base();
  33. $my =& JFactory::getUser();
  34. $user =& CFactory::getActiveProfile();
  35. $doc =& JFactory::getDocument();
  36. JLoader::register('hwdMediaShareFactory', JPATH_ROOT.'/components/com_hwdmediashare/libraries/factory.php');
  37. JLoader::register('hwdMediaShareHelperRoute', JPATH_ROOT.'/components/com_hwdmediashare/helpers/route.php');
  38. // Download links
  39. hwdMediaShareFactory::load('files');
  40. hwdMediaShareFactory::load('downloads');
  41. hwdMediaShareFactory::load('media');
  42. hwdMediaShareFactory::load('utilities');
  43. JLoader::register('JHtmlHwdIcon', JPATH_ROOT.'/components/com_hwdmediashare/helpers/icon.php');
  44. JLoader::register('JHtmlString', JPATH_LIBRARIES.'/joomla/html/html/string.php');
  45. // Load the HWDMediaShare language file
  46. $lang =& JFactory::getLanguage();
  47. $lang->load('com_hwdmediashare', JPATH_SITE.'/components/com_hwdmediashare', $lang->getTag());
  48. $doc->addStyleSheet(JURI::base( true ).'/media/com_hwdmediashare/assets/css/lite.css');
  49. $doc->addScript(JURI::base( true ).'/media/com_hwdmediashare/assets/javascript/hwd.min.js');
  50. $cache =& JFactory::getCache('community');
  51. $callback = array($this, '_getMediaHTML');
  52. $content = $cache->call($callback, $this->params, $user);
  53. return $content;
  54. }
  55. function _getMediaHTML($params, $user)
  56. {
  57. $app = & JFactory::getApplication();
  58. $doc = & JFactory::getDocument();
  59. // Get an instance of the generic articles model
  60. JModel::addIncludePath(JPATH_ROOT.'/components/com_hwdmediashare/models');
  61. $model =& JModel::getInstance('User', 'hwdMediaShareModel', array('ignore_request' => true));
  62. $model->setState('user.id', $user->id);
  63. // Set application parameters in model
  64. $app = JFactory::getApplication();
  65. $appParams = $app->getParams();
  66. $hwdms = hwdMediaShareFactory::getInstance();
  67. $this->config = $hwdms->getConfig();
  68. $this->config->merge( $params );
  69. // Check if we need to load the Joomla styles
  70. if ($this->config->get('load_joomla_css') != 0) $doc->addStyleSheet(JURI::base( true ).'/media/com_hwdmediashare/assets/css/joomla.css');
  71. $model->params = $this->config;
  72. $model->setState('params', $appParams);
  73. // Get data from the model
  74. $channel = $model->getChannel();
  75. $media = $model->getMedia();
  76. $activities = $model->getActivities();
  77. $favourites = $model->getFavourites();
  78. $groups = $model->getGroups();
  79. $playlists = $model->getPlaylists();
  80. $albums = $model->getAlbums();
  81. $subscribers = $model->getSubscribers();
  82. $state = $model->getState();
  83. // Check for errors.
  84. if (count($errors = $model->get('Errors')))
  85. {
  86. JError::raiseError(500, implode('<br />', $errors));
  87. return false;
  88. }
  89. $this->columns= $params->get('list_columns', 3);
  90. $this->display= 'details';
  91. $this->return= base64_encode(JFactory::getURI()->toString());
  92. $this->utilities = hwdMediaShareUtilities::getInstance();
  93. $this->channel= $channel;
  94. $this->media= $media;
  95. $this->activities= $activities;
  96. $this->favourites= $favourites;
  97. $this->groups= $groups;
  98. $this->playlists= $playlists;
  99. $this->albums= $albums;
  100. $this->subscribers= $subscribers;
  101. $this->state= $state;
  102. $this->params= $this->config;
  103. // Setup the modal display
  104. if ($this->params->get('display') == 'modal')
  105. {
  106. $this->params->set('modal', 1);
  107. }
  108. ob_start();
  109. require 'assets/tmpl/default.php';
  110. $html = ob_get_contents();
  111. ob_end_clean();
  112. return $html;
  113. }
  114. function loadTemplate($template)
  115. {
  116. // Build the template and base path for the layout
  117. $path = JPATH_ROOT.'/plugins/community/media/assets/tmpl/'.$template.'.php';
  118. // If the template has a layout override use it
  119. if (file_exists($path))
  120. {
  121. ob_start();
  122. require $path;
  123. $html = ob_get_contents();
  124. ob_end_clean();
  125. return $html;
  126. }
  127. return false;
  128. }
  129. /**
  130. * Method to get the publish status HTML
  131. *
  132. * @param object Field object
  133. * @param string Type of the field
  134. * @param string The ajax task that it should call
  135. * @return string HTML source
  136. **/
  137. public function getActivities( &$item, $parent = true )
  138. {
  139. hwdMediaShareFactory::load('activities');
  140. return hwdMediaShareActivities::getActivities($item, $parent);
  141. }
  142. function onSystemStart()
  143. {
  144. $plugin =& JPluginHelper::getPlugin('community', 'media');
  145. $params = new JRegistry( $plugin->params );
  146. $user =& CFactory::getActiveProfile();
  147. JLoader::register('hwdMediaShareFactory', JPATH_ROOT.'/components/com_hwdmediashare/libraries/factory.php');
  148. JLoader::register('hwdMediaShareHelperRoute', JPATH_ROOT.'/components/com_hwdmediashare/helpers/route.php');
  149. if(!class_exists('CFactory'))
  150. {
  151. require_once( JPATH_BASE . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php');
  152. }
  153. // Load the HWDMediaShare language file
  154. $lang =& JFactory::getLanguage();
  155. $lang->load('plg_community_media', JPATH_ADMINISTRATOR, $lang->getTag());
  156. // Initialize the toolbar object
  157. $toolbar =& CFactory::getToolbar();
  158. // Adding new 'tab' in JomSocial toolbar
  159. if ($params->get('toolbar_media_menu') == "show") $toolbar->addGroup('HWDMS', JText::_('PLG_COMMUNITY_MENU_MEDIA'), JRoute::_(hwdMediaShareHelperRoute::getMediaRoute()));
  160. if ($params->get('toolbar_mymedia_menu') == "show") $toolbar->addItem('HWDMS', 'HWDVS_ALL', JText::_('PLG_COMMUNITY_MENU_MYMEDIA'), JRoute::_(hwdMediaShareHelperRoute::getMyMediaRoute()));
  161. if ($params->get('toolbar_upload_menu') == "show") $toolbar->addItem('HWDMS', 'HWDVS_UPLOAD', JText::_('PLG_COMMUNITY_MENU_UPLOAD'), JRoute::_(hwdMediaShareHelperRoute::getUploadRoute()));
  162. }
  163. function onActivityContentDisplay($act)
  164. {
  165. $plugin =& JPluginHelper::getPlugin('community', 'media');
  166. $params = new JRegistry( $plugin->params );
  167. JLoader::register('hwdMediaShareFactory', JPATH_ROOT.'/components/com_hwdmediashare/libraries/factory.php');
  168. JLoader::register('hwdMediaShareHelperRoute', JPATH_ROOT.'/components/com_hwdmediashare/helpers/route.php');
  169. hwdMediaShareFactory::load('media');
  170. hwdMediaShareFactory::load('downloads');
  171. JLoader::register('JHtmlHwdIcon', JPATH_SITE.'/components/com_hwdmediashare/helpers/icon.php');
  172. $doc = JFactory::getDocument();
  173. $doc->addStyleSheet(JURI::base( true ).'/media/com_hwdmediashare/assets/css/lite.css');
  174. $doc->addScript(JURI::base( true ).'/media/com_hwdmediashare/assets/javascript/hwd.min.js');
  175. switch (@$act->cmd)
  176. {
  177. case "media.add":
  178. default:
  179. JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_hwdmediashare/tables');
  180. $table =& JTable::getInstance('Media', 'hwdMediaShareTable');
  181. $table->load( $act->cid );
  182. $properties = $table->getProperties(1);
  183. $item = JArrayHelper::toObject($properties, 'JObject');
  184. $item->media_type = hwdMediaShareMedia::loadMediaType($item);;
  185. ob_start();
  186. ?>
  187. <div class="media-item">
  188. <!-- Media Type -->
  189. <?php if ($this->params->get('list_meta_thumbnail') != 'hide') :?>
  190. <?php if ($this->params->get('list_meta_type_icon') != 'hide') :?>
  191. <div class="media-item-format-1-<?php echo $item->media_type; ?>">
  192. <img src="<?php echo JHtml::_('hwdicon.overlay', '1-'.$item->media_type, $item); ?>" alt="<?php echo JText::_('COM_HWDMS_MEDIA_TYPE'); ?>" />
  193. </div>
  194. <?php endif; ?>
  195. <?php if ($item->duration > 0) :?>
  196. <div class="media-duration">
  197. <?php echo hwdMediaShareMedia::secondsToTime($item->duration); ?>
  198. </div>
  199. <?php endif; ?>
  200. <a href="<?php echo JRoute::_(hwdMediaShareHelperRoute::getMediaItemRoute($item->id)); ?>">
  201. <img src="<?php echo JRoute::_(hwdMediaShareDownloads::thumbnail($item)); ?>" border="0" alt="" style="max-width:120px;" />
  202. </a>
  203. <?php endif; ?>
  204. <?php
  205. $html = ob_get_contents();
  206. ob_end_clean();
  207. break;
  208. }
  209. return $html;
  210. }
  211. function onAfterMediaAdd($media)
  212. {
  213. $plugin =& JPluginHelper::getPlugin('community', 'media');
  214. $params = new JRegistry( $plugin->params );
  215. hwdMediaShareFactory::load('utilities');
  216. $utilities = hwdMediaShareUtilities::getInstance();
  217. if (file_exists(JPATH_SITE.'/components/com_community/libraries/core.php'))
  218. {
  219. require_once(JPATH_SITE.'/components/com_community/libraries/core.php');
  220. require_once(JPATH_SITE.'/components/com_community/libraries/error.php');
  221. if ($params->get('activity_new_media') == 1)
  222. {
  223. // Why on earth do I need to do this?
  224. JTable::addIncludePath( JPATH_SITE.'/administrator/components/com_community/tables/' );
  225. JTable::getInstance( 'Configuration' , 'CommunityTable' );
  226. // Load the HWDMediaShare language file
  227. $lang =& JFactory::getLanguage();
  228. $lang->load('plg_community_media', JPATH_ADMINISTRATOR, $lang->getTag());
  229. $act = new stdClass();
  230. $act->cmd = 'media.add';
  231. $act->actor = $media['created_user_id'];
  232. $act->target = 0; // No target
  233. $act->title = JText::sprintf('COM_HWDMS_X_UPLOADED_A_NEW_MEDIA', '{actor}', '<a href="'.JRoute::_(hwdMediaShareHelperRoute::getMediaItemRoute($media['id'])).'">'.$media['title'].'</a>');
  234. $act->content = '';
  235. $act->app = 'media';
  236. $act->cid = $media['id'];
  237. $act->params = '';
  238. // Adding support for LIKE and COMMENT in stream
  239. $act->comment_type = $act->cmd;
  240. $act->comment_id = CActivities::COMMENT_SELF;
  241. $act->like_type = $act->cmd;
  242. $act->like_id = CActivities::LIKE_SELF;
  243. // Insert into activity stream
  244. CFactory::load('libraries', 'activities');
  245. CActivityStream::add($act);
  246. }
  247. if ($params->get('points_new_media') == 1)
  248. {
  249. include_once( JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'userpoints.php');
  250. //CuserPoints::assignPoint('com_hwdvideoshare.onAfterVideoApproval', $my->id);
  251. }
  252. }
  253. return true;
  254. }
  255. }