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

/components/com_phocadownload/views/user/view.html.php

https://github.com/wiktorm/projekt-awr
PHP | 321 lines | 206 code | 63 blank | 52 comment | 50 complexity | 06c801601e0f1b69f89bdcb3ab91f6a3 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. * @package Joomla 1.5
  4. * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
  5. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  6. *
  7. * @component Phoca Component
  8. * @copyright Copyright (C) Jan Pavelka www.phoca.cz
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  10. */
  11. defined( '_JEXEC' ) or die();
  12. jimport( 'joomla.client.helper' );
  13. jimport( 'joomla.application.component.view' );
  14. jimport( 'joomla.html.pane' );
  15. class PhocaDownloadViewUser extends JView
  16. {
  17. var $_context_files = 'com_phocadownload.phocadownloaduserfiles';
  18. function display($tpl = null) {
  19. global $mainframe;
  20. $document = &JFactory::getDocument();
  21. $uri = &JFactory::getURI();
  22. $menus = &JSite::getMenu();
  23. $menu = $menus->getActive();
  24. $params = &$mainframe->getParams();
  25. $user = &JFactory::getUser();
  26. $db = & JFactory::getDBO();
  27. $tmpl['pi'] = 'components/com_phocadownload/assets/images/';
  28. $tmpl['pp'] = 'index.php?option=com_phocadownload&view=user&controller=user';
  29. $tmpl['pl'] = 'index.php?option=com_user&view=login&return='.base64_encode($tmpl['pp'].'&Itemid='. JRequest::getVar('Itemid', 0, '', 'int'));
  30. // Only registered users
  31. if ($user->aid == 0) {
  32. $mainframe->redirect(JRoute::_($tmpl['pl'], false), JText::_("ALERTNOTAUTH"));
  33. exit;
  34. }
  35. // CSS, JS
  36. $css = $params->get( 'theme', 'phocadownload-grey' );
  37. $document->addStyleSheet(JURI::base(true).'/components/com_phocadownload/assets/'.$css.'.css');
  38. // = = = = = = = = = = =
  39. // PANE
  40. // = = = = = = = = = = =
  41. // - - - - - - - - - -
  42. // ALL TABS
  43. // - - - - - - - - - -
  44. // UCP is disabled (security reasons)
  45. if ((int)$params->get( 'enable_user_cp', 0 ) == 0) {
  46. $mainframe->redirect(JURI::base(true), JText::_("PHOCADOWNLOAD_USER_UPLOAD_DISABLED"));
  47. exit;
  48. }
  49. $tmpl['tab'] = JRequest::getVar('tab', 0, '', 'string');
  50. $tmpl['maxuploadchar'] = $params->get( 'max_upload_char', 1000 );
  51. $tmpl['enableuseruploadapprove']= $params->get( 'enable_user_upload_approve', 0 );
  52. $tmpl['showpagetitle'] = $params->get( 'show_page_title', 1 );
  53. $tmpl['uploadmaxsize'] = $params->get( 'user_file_upload_size', 3145728 );
  54. $tmpl['uploadmaxsizeread'] = PhocaDownloadHelper::getFileSizeReadable($tmpl['uploadmaxsize']);
  55. $tmpl['userfilesmaxcount'] = $params->get( 'user_files_max_count', 5 );
  56. $tmpl['userfilesmaxsize'] = $params->get( 'user_files_max_size', 20971520 );
  57. $tmpl['iepx'] = '<div style="font-size:1px;height:1px;margin:0px;padding:0px;">&nbsp;</div>';
  58. $tmpl['send_mail_upload'] = $params->get( 'send_mail_upload', 0 );
  59. //Subcateogry
  60. //$tmpl['parentid'] = JRequest::getVar('parentcategoryid', 0, 'post', 'int');
  61. $document->addScript(JURI::base(true).'/components/com_phocagallery/assets/js/comments.js');
  62. $document->addCustomTag(PhocaDownloadHelperFront::renderOnUploadJS());
  63. $document->addCustomTag(PhocaDownloadHelperFront::renderDescriptionUploadJS((int)$tmpl['maxuploadchar']));
  64. $tmpl['pdl'] = PhocaDownloadHelper::renderPhocaDownload();
  65. $document->addCustomTag(PhocaDownloadHelperFront::userTabOrdering());
  66. $model = $this->getModel('user');
  67. // Upload Form - - - - - - - - - - - - - - -
  68. $ftp = !JClientHelper::hasCredentials('ftp');// Set FTP form
  69. $this->assignRef('session', JFactory::getSession());
  70. // END Upload Form - - - - - - - - - - - - -
  71. $tmpl['displayupload'] = 1;
  72. // - - - - - - - - - -
  73. // FORM
  74. // - - - - - - - - - -
  75. // No Controller because of returning back the values in case some form field is not OK
  76. // Set default for returning back
  77. $formData = new JObject();
  78. $formData->set('title', '');
  79. $formData->set('description','');
  80. $formData->set('author','');
  81. $formData->set('email','');
  82. $formData->set('license','');
  83. $formData->set('website','');
  84. $formData->set('version','');
  85. $tmpl['errorcatid'] = '';
  86. $tmpl['erroremail'] = '';
  87. $tmpl['errorwebsite'] = '';
  88. $tmpl['errorfile'] = '';
  89. $task = JRequest::getVar( 'task', '', 'post', 'string' );
  90. if($task == 'upload') {
  91. $post['title'] = JRequest::getVar( 'phocadownloaduploadtitle', '', 'post', 'string' );
  92. $post['description'] = JRequest::getVar( 'phocadownloaduploaddescription', '', 'post', 'string' );
  93. $post['catidfiles'] = JRequest::getVar( 'catidfiles', 0, 'post', 'int' );
  94. $post['description'] = substr($post['description'], 0, (int)$tmpl['maxuploadchar']);
  95. $post['approved'] = 0;
  96. $post['published'] = 1;
  97. $post['owner_id'] = $user->id;
  98. if ($tmpl['enableuseruploadapprove'] == 0) {
  99. $post['approved'] = 1;
  100. }
  101. $post['author'] = JRequest::getVar( 'phocadownloaduploadauthor', '', 'post', 'string' );
  102. $post['email'] = JRequest::getVar( 'phocadownloaduploademail', '', 'post', 'string' );
  103. $post['website'] = JRequest::getVar( 'phocadownloaduploadwebsite', '', 'post', 'string' );
  104. $post['license'] = JRequest::getVar( 'phocadownloaduploadlicense', '', 'post', 'string' );
  105. $post['version'] = JRequest::getVar( 'phocadownloaduploadversion', '', 'post', 'string' );
  106. if ($post['title'] != '') {$formData->set('title', $post['title']);}
  107. if ($post['description'] != '') {$formData->set('description', $post['description']);}
  108. if ($post['author'] != '') {$formData->set('author', $post['author']);}
  109. if ($post['email'] != '') {$formData->set('email', $post['email']);}
  110. if ($post['website'] != '') {$formData->set('website', $post['website']);}
  111. if ($post['license'] != '') {$formData->set('license', $post['license']);}
  112. if ($post['version'] != '') {$formData->set('version', $post['version']);}
  113. // CHECK
  114. //catid
  115. $returnForm = 0;
  116. if ($post['catidfiles'] < 1) {
  117. $tmpl['errorcatid'] = JText::_('PHOCADOWNLOAD_PLEASE_SELECT_CATEGORY');
  118. $returnForm = 1;
  119. }
  120. jimport('joomla.mail.helper');
  121. if ($post['email'] != '' && !JMailHelper::isEmailAddress($post['email']) ) {
  122. $tmpl['erroremail'] = JText::_('PHOCADOWNLOAD_PLEASE_ENTER_VALID_EMAIL_ADDRESS');
  123. $returnForm = 1;
  124. }
  125. if ($post['website'] != '' && !PhocaDownloadHelper::isURLAddress($post['website']) ) {
  126. $tmpl['errorwebsite'] = JText::_('PHOCADOWNLOAD_PLEASE_ENTER_VALID_WEBSITE');
  127. $returnForm = 1;
  128. }
  129. // Upload
  130. $errUploadMsg = '';
  131. $redirectUrl = '';
  132. $fileArray = JRequest::getVar( 'Filedata', '', 'files', 'array' );
  133. if(empty($fileArray) || (isset($fileArray['name']) && $fileArray['name'] == '')) {
  134. $tmpl['errorfile'] = JText::_('PHOCADOWNLOAD_PLEASE_ADD_FILE');
  135. $returnForm = 1;
  136. }
  137. if ($post['title'] == '') {
  138. $post['title'] = PhocaDownloadHelper::removeExtension($fileArray['name']);
  139. }
  140. $post['alias'] = PhocaDownloadHelper::getAliasName($post['title']);
  141. if ($returnForm == 0) {
  142. $errorUploadMsg = '';
  143. if($model->singleFileUpload($errorUploadMsg, $fileArray, $post)) {
  144. if ($tmpl['send_mail_upload'] > 0) {
  145. PhocaDownloadHelper::sendPhocaDownloadMail((int)$tmpl['send_mail_upload'], $post['title'], 2);
  146. }
  147. $Itemid = JRequest::getVar( 'Itemid', 0, '', 'int');
  148. $limitStart = JRequest::getVar( 'limitstart', 0, '', 'int');
  149. if ($limitStart > 0) {
  150. $limitStartUrl = '&limitstart='.$limitStart;
  151. } else {
  152. $limitStartUrl = '';
  153. }
  154. $link = 'index.php?option=com_phocadownload&view=user&Itemid='. $Itemid . $limitStartUrl;
  155. $mainframe->redirect(JRoute::_($link, false), JText::_("PHOCADOWNLOAD_FILE_UPLOADED"));
  156. exit;
  157. } else {
  158. $tmpl['errorfile'] = JText::_('PHOCADOWNLOAD_FILE_NOT_UPLOADED');
  159. if ($errorUploadMsg != '') {
  160. $tmpl['errorfile'] .= '<br />' . $errorUploadMsg;
  161. }
  162. }
  163. }
  164. }
  165. // - - - - - - - - - - -
  166. // FILES
  167. // - - - - - - - - - - -
  168. $tmpl['filesitems'] = $model->getDataFiles($user->id);
  169. $tmpl['filestotal'] = $model->getTotalFiles($user->id);
  170. $tmpl['filespagination'] = $model->getPaginationFiles($user->id);
  171. $filter_state_files = $mainframe->getUserStateFromRequest( $this->_context_files.'.filter_state','filter_state', '','word');
  172. $filter_catid_files = $mainframe->getUserStateFromRequest( $this->_context_files.'.filter_catid','filter_catid',0, 'int' );
  173. $catid_files = $mainframe->getUserStateFromRequest( $this->_context_files. '.catid', 'catid', 0, 'int');
  174. $filter_sectionid_files = $mainframe->getUserStateFromRequest( $this->_context_files.'.filter_sectionid', 'filter_sectionid', 0, 'int' );
  175. $filter_order_files = $mainframe->getUserStateFromRequest( $this->_context_files.'.filter_order','filter_order','a.ordering', 'cmd' );
  176. $filter_order_Dir_files = $mainframe->getUserStateFromRequest( $this->_context_files.'.filter_order_Dir','filter_order_Dir', '', 'word' );
  177. $search_files = $mainframe->getUserStateFromRequest( $this->_context_files.'.search', 'search', '', 'string' );
  178. $search_files = JString::strtolower( $search_files );
  179. // build list of categories
  180. $javascript = 'class="inputbox" size="1" onchange="document.phocadownloadfilesform.submit();"';
  181. // get list of categories for dropdown filter
  182. $whereC = array();
  183. if ($filter_sectionid_files > 0) {
  184. $whereC[] = ' cc.section = '.$db->Quote($filter_sectionid_files);
  185. }
  186. //$whereC[] = "(cc.uploaduserid LIKE '%-1%' OR cc.uploaduserid LIKE '%".(int)$user->id."%')";
  187. //$whereC[] = "(cc.uploaduserid LIKE '%-1%' OR cc.uploaduserid LIKE '%,{".(int)$user->id."}' OR cc.uploaduserid LIKE '{".(int)$user->id."},%' OR cc.uploaduserid LIKE '%,{".(int)$user->id."},%' OR cc.uploaduserid ={".(int)$user->id."} )";
  188. $whereC[] = "(cc.uploaduserid LIKE '%-1%' OR cc.uploaduserid LIKE '%,".(int)$user->id."' OR cc.uploaduserid LIKE '".(int)$user->id.",%' OR cc.uploaduserid LIKE '%,".(int)$user->id.",%' OR cc.uploaduserid =".(int)$user->id." )";
  189. $whereC = ( count( $whereC ) ? ' WHERE '. implode( ' AND ', $whereC ) : '' );
  190. // get list of categories for dropdown filter
  191. $query = 'SELECT cc.id AS value, cc.title AS text' .
  192. ' FROM #__phocadownload_categories AS cc' .
  193. ' LEFT JOIN #__phocadownload_sections AS s ON s.id = cc.section' .
  194. $whereC.
  195. ' ORDER BY s.ordering, cc.ordering';
  196. $lists_files['catid'] = PhocaDownloadHelper::filterCategory($query, $catid_files, TRUE);
  197. $whereS = array();
  198. //$whereS[] = "(cc.uploaduserid LIKE '%-1%' OR cc.uploaduserid LIKE '%".(int)$user->id."%')";
  199. $whereS[] = "(cc.uploaduserid LIKE '%-1%' OR cc.uploaduserid LIKE '%,".(int)$user->id."' OR cc.uploaduserid LIKE '".(int)$user->id.",%' OR cc.uploaduserid LIKE '%,".(int)$user->id.",%' OR cc.uploaduserid =".(int)$user->id." )";
  200. $whereS[] = 's.published = 1';
  201. $whereS = ( count( $whereS ) ? ' WHERE '. implode( ' AND ', $whereS ) : '' );
  202. // sectionid
  203. $query = 'SELECT s.title AS text, s.id AS value'
  204. . ' FROM #__phocadownload_sections AS s'
  205. . ' LEFT JOIN #__phocadownload_categories AS cc ON cc.section = s.id'
  206. . $whereS
  207. . ' GROUP BY s.id'
  208. . ' ORDER BY s.ordering';
  209. // state filter
  210. /* $state_files[] = JHTML::_('select.option', '', '- '. JText::_( 'Select State' ) .' -' );
  211. $state_files[] = JHTML::_('select.option', 'P', JText::_( 'Published' ) );
  212. $state_files[] = JHTML::_('select.option', 'U', JText::_( 'Unpublished') );
  213. $lists_image['state'] = JHTML::_('select.genericlist', $state_files, 'filter_state', 'class="inputbox" size="1" onchange="document.phocadownloadfilesform.submit();"', 'value', 'text', $filter_state );*/
  214. $lists_files['sectionid'] = PhocaDownloadHelper::filterSection($query, $filter_sectionid_files, TRUE);
  215. // state filter
  216. $lists_files['state'] = JHTML::_('grid.state', $filter_state_files );
  217. // table ordering
  218. $lists_files['order_Dir'] = $filter_order_Dir_files;
  219. $lists_files['order'] = $filter_order_files;
  220. // search filter
  221. $lists_files['search']= $search_files;
  222. $tmpl['catidfiles'] = $catid_files;
  223. $tmpl['filestab'] = 1;
  224. // Tabs
  225. $displayTabs = 0;
  226. if ((int)$tmpl['filestab'] == 0) {
  227. $currentTab['files'] = -1;
  228. } else {
  229. $currentTab['files'] = $displayTabs;
  230. $displayTabs++;
  231. }
  232. $tmpl['displaytabs'] = $displayTabs;
  233. $tmpl['currenttab'] = $currentTab;
  234. // ACTION
  235. $tmpl['action'] = $uri->toString();
  236. // SEF problem
  237. $isThereQM = false;
  238. $isThereQM = preg_match("/\?/i", $tmpl['action']);
  239. if ($isThereQM) {
  240. $amp = '&amp;';
  241. } else {
  242. $amp = '?';
  243. }
  244. $tmpl['actionamp'] = $tmpl['action'] . $amp;
  245. $tmpl['istheretab'] = false;
  246. $tmpl['istheretab'] = preg_match("/tab=/i", $tmpl['action']);
  247. $tmpl['ps'] = '&tab='. $tmpl['currenttab']['files']
  248. . '&limitstart='.$tmpl['filespagination']->limitstart;
  249. // ASIGN
  250. $this->assignRef( 'listsfiles', $lists_files);
  251. $this->assignRef( 'formdata', $formData);
  252. $this->assignRef( 'tmpl', $tmpl);
  253. $this->assignRef( 'params', $params);
  254. $this->assignRef( 'session', JFactory::getSession());
  255. parent::display($tpl);
  256. }
  257. }
  258. ?>