Ejemplo n.º 1
0
	public static function renderAllCSS($noBootStrap = 0) {
		$app	= JFactory::getApplication();
		$itemid	= $app->input->get('Itemid', 0, 'int');
		$db 	= JFactory::getDBO();
		$query = 'SELECT a.filename as filename, a.type as type, a.menulink as menulink'
				.' FROM #__phocadownload_styles AS a'
				.' WHERE a.published = 1'
			    .' ORDER BY a.type, a.ordering ASC';
		$db->setQuery($query);
		$filenames = $db->loadObjectList();
		if (!empty($filenames)) {
			foreach ($filenames as $fk => $fv) {
				
				$path = PhocaDownloadFile::getCSSPath($fv->type, 1);
			
				if ($fv->menulink != '' && (int)$fv->menulink > 1) {
	
					$menuLinks 	= explode(',', $fv->menulink);
					$isIncluded	= in_array((int)$itemid, $menuLinks);
					if ($isIncluded) {
						JHtml::stylesheet($path . $fv->filename );
					} 
				} else {
					JHtml::stylesheet($path . $fv->filename );
				}
			}
		}
	}
Ejemplo n.º 2
0
 public static function getMultipleUploadSizeFormat($size)
 {
     $readableSize = PhocaDownloadFile::getFileSizeReadable($size, '%01.0f %s', 1);
     $readableSize = str_replace(' ', '', $readableSize);
     $readableSize = strtolower($readableSize);
     return $readableSize;
 }
Ejemplo n.º 3
0
 function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $params = $app->getParams();
     $this->t = array();
     $this->t['user'] = JFactory::getUser();
     $uri = JFactory::getURI();
     $model = $this->getModel();
     $document = JFactory::getDocument();
     $fileId = $app->input->get('id', 0, 'int');
     $file = $model->getFile($fileId);
     $fileExt = '';
     $filePath = PhocaDownloadPath::getPathSet('fileplay');
     $filePath = str_replace('../', JURI::base(false) . '', $filePath['orig_rel_ds']);
     if (isset($file[0]->filename_play) && $file[0]->filename_play != '') {
         $fileExt = PhocaDownloadFile::getExtension($file[0]->filename_play);
         $canPlay = PhocaDownloadFile::canPlay($file[0]->filename_play);
         if ($canPlay) {
             $this->t['playfilewithpath'] = $filePath . $file[0]->filename_play;
             //$this->t['playerpath']		= JURI::base().'components/com_phocadownload/assets/jwplayer/';
             $this->t['playerpath'] = JURI::base() . 'components/com_phocadownload/assets/flowplayer/';
             $this->t['playerwidth'] = $params->get('player_width', 328);
             $this->t['playerheight'] = $params->get('player_height', 200);
             $this->t['html5_play'] = $params->get('html5_play', 0);
         } else {
             echo JText::_('COM_PHOCADOWNLOAD_ERROR_NO_CORRECT_FILE_TO_PLAY_FOUND');
             exit;
         }
     } else {
         echo JText::_('COM_PHOCADOWNLOAD_ERROR_NO_FILE_TO_PLAY_FOUND');
         exit;
     }
     $this->t['filetype'] = $fileExt;
     if ($fileExt == 'mp3') {
         $this->t['filetype'] = 'mp3';
         $this->t['playerheight'] = $params->get('player_mp3_height', 30);
     } else {
         if ($fileExt == 'ogg') {
             $this->t['filetype'] = 'ogg';
             $this->t['playerheight'] = $params->get('player_mp3_height', 30);
         }
     }
     $this->assignRef('file', $file);
     $this->assignRef('tmpl', $this->t);
     $this->assignRef('params', $params);
     $uriT = $uri->toString();
     $this->assignRef('request_url', $uriT);
     parent::display($tpl);
 }
Ejemplo n.º 4
0
 function check()
 {
     // check for valid name but not by text
     if ((int) $this->textonly == 1) {
     } else {
         if (trim($this->filename) == '') {
             $this->setError(JText::_('FILE MUST HAVE A FILENAME'));
             return false;
         }
     }
     if (empty($this->title)) {
         $this->title = PhocaDownloadFile::getTitleFromFilenameWithoutExt($this->filename);
     }
     if (empty($this->alias)) {
         $this->alias = $this->title;
     }
     $this->alias = PhocaDownloadUtils::getAliasName($this->alias);
     return true;
 }
Ejemplo n.º 5
0
	public static function canUpload( $file, &$err, $manager = '', $frontEnd = 0, $chunkEnabled = 0, $realSize = 0) {
		
		$paramsC 	= JComponentHelper::getParams( 'com_phocadownload' );
		
		if ($frontEnd == 1) {
			$aft = $paramsC->get( 'allowed_file_types_upload', PhocaDownloadSettings::getDefaultAllowedMimeTypesUpload() );
			$dft = $paramsC->get( 'disallowed_file_types_upload', '' );
			$allowedMimeType 	= PhocaDownloadFile::getMimeTypeString($aft);
			$disallowedMimeType = PhocaDownloadFile::getMimeTypeString($dft);
			
			$ignoreUploadCh = 0;
			$ignoreUploadCheck = $params->get( 'ignore_file_types_check', 2 );
			if ($ignoreUploadCheck == 1 || $ignoreUploadCheck == 4 ) {
				$ignoreUploadCh = 1;
			}
			
		} else {
		
			$aft = $paramsC->get( 'allowed_file_types_download', PhocaDownloadSettings::getDefaultAllowedMimeTypesDownload() );
			$dft = $paramsC->get( 'disallowed_file_types_download', '' );
			$allowedMimeType 	= PhocaDownloadFile::getMimeTypeString($aft);
			$disallowedMimeType = PhocaDownloadFile::getMimeTypeString($dft);
			
			$ignoreUploadCh = 0;
			$ignoreUploadCheck = $paramsC->get( 'ignore_file_types_check', 2 );
			if ($ignoreUploadCheck == 5 || $ignoreUploadCheck == 5 ) {
				$ignoreUploadCh = 1;
			}
		}
		
		
		
		$paramsL = array();
		$group = PhocaDownloadSettings::getManagerGroup($manager);
		if ($group['f'] == 2) {
			$paramsL['upload_extensions'] 	= 'gif,jpg,png,jpeg';
			$paramsL['image_extensions'] 	= 'gif,jpg,png,jpeg';
			$paramsL['upload_mime']			= 'image/jpeg,image/gif,image/png';
			$paramsL['upload_mime_illegal']	='application/x-shockwave-flash,application/msword,application/excel,application/pdf,application/powerpoint,text/plain,application/x-zip,text/html';
			$paramsL['upload_ext_illegal']	= $disallowedMimeType['ext'];
		} else {
			$paramsL['upload_extensions'] 	= $allowedMimeType['ext'];
			$paramsL['image_extensions'] 	= 'bmp,gif,jpg,png,jpeg';
			$paramsL['upload_mime']			= $allowedMimeType['mime'];
			$paramsL['upload_mime_illegal']	= $disallowedMimeType['mime'];
			$paramsL['upload_ext_illegal']	= $disallowedMimeType['ext'];
		}
		

		// The file doesn't exist
		if(empty($file['name'])) {
			$err = 'COM_PHOCADOWNLOAD_WARNING_INPUT_FILE_UPLOAD';
			return false;
		}
		// Not safe file
		jimport('joomla.filesystem.file');
		if ($file['name'] !== JFile::makesafe($file['name'])) {
			$err = 'COM_PHOCADOWNLOAD_WARNFILENAME';
			return false;
		}

		$format 		= strtolower(JFile::getExt($file['name']));
		if ($ignoreUploadCh == 1) {
		
		} else {
		
			$allowable 		= explode( ',', $paramsL['upload_extensions']);
			$notAllowable 	= explode( ',', $paramsL['upload_ext_illegal']);
			if(in_array($format, $notAllowable)) {
				$err = 'COM_PHOCADOWNLOAD_WARNFILETYPE_DISALLOWED';
				return false;
			}
			
			
			//if (!in_array($format, $allowable)) {
			if ($format == '' || $format == false || (!in_array($format, $allowable))) {
				$err = 'COM_PHOCADOWNLOAD_WARNFILETYPE_NOT_ALLOWED';
				return false;
			}
		}

		
		// Max size of image
		// If chunk method is used, we need to get computed size
		$maxSize = $paramsC->get( 'upload_maxsize', 3145728 );
		if ((int)$frontEnd > 0) {
			$maxSize = $paramsC->get( 'user_file_upload_size', 3145728 );
		} else {
			$maxSize = $paramsC->get( 'upload_maxsize', 3145728 );
		}
		
		if ($chunkEnabled == 1) {
			if ((int)$maxSize > 0 && (int)$realSize > (int)$maxSize) {
				$err = 'COM_PHOCADOWNLOAD_WARNFILETOOLARGE';
				
				return false;
			}
		} else {
			if ((int)$maxSize > 0 && (int)$file['size'] > (int)$maxSize) {
				$err = 'COM_PHOCADOWNLOAD_WARNFILETOOLARGE';
				
				return false;
			}
		}
		
		
		// User (only in ucp) - Check the size of all files by users
		if ($frontEnd == 2) {
			$user 				= JFactory::getUser();
			$maxUserUploadSize 	= (int)$paramsC->get( 'user_files_max_size', 20971520 );
			$maxUserUploadCount	= (int)$paramsC->get( 'user_files_max_count', 5 );
			$allFile	= PhocaDownloadUser:: getUserFileInfo($file, $user->id);
			
			if ($chunkEnabled == 1) {
				$fileSize = $realSize;
			} else {
				$fileSize = $file['size'];
			}
			
			if ((int)$maxUserUploadSize > 0 && (int) $allFile['size'] > $maxUserUploadSize) {
				$err = JText::_('COM_PHOCADOWNLOAD_WARNUSERFILESTOOLARGE');	
				return false;
			}
				
			if ((int) $allFile['count'] > $maxUserUploadCount) {
				$err = JText::_('COM_PHOCADOWNLOAD_WARNUSERFILESTOOMUCH');	
				return false;
			}
		}
		
		
		

		// Image check
		$imginfo	= null;
		$images		= explode( ',', $paramsL['image_extensions']);
		
		if(in_array($format, $images)) { // if its an image run it through getimagesize
			
			$group = PhocaDownloadSettings::getManagerGroup($manager);
			if($group['i'] == 1) {
				if ($chunkEnabled != 1) {
					if(($imginfo = getimagesize($file['tmp_name'])) === FALSE) {
						$err = 'COM_PHOCADOWNLOAD_WARNINVALIDIMG';
						$err = $imginfo[0];
						return false;
					}
				}
			}
		} else if(!in_array($format, $images)) { // if its not an image...and we're not ignoring it
			$allowed_mime = explode(',', $paramsL['upload_mime']);
			$illegal_mime = explode(',', $paramsL['upload_mime_illegal']);
			if(function_exists('finfo_open')) {// We have fileinfo
				$finfo	= finfo_open(FILEINFO_MIME);
				$type	= finfo_file($finfo, $file['tmp_name']);
				if(strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) {
					$err = 'COM_PHOCADOWNLOAD_WARNINVALIDMIME';
					return false;
				}
				finfo_close($finfo);
			} else if(function_exists('mime_content_type')) { // we have mime magic
				$type = mime_content_type($file['tmp_name']);
				if(strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) {
					$err = 'COM_PHOCADOWNLOAD_WARNINVALIDMIME';
					return false;
				}
			}
		}
			
		// XSS Check
		$xss_check =  JFile::read($file['tmp_name'],false,256);
		$html_tags = PhocaDownloadSettings::getHTMLTagsUpload();
		foreach($html_tags as $tag) { // A tag is '<tagname ', so we need to add < and a space or '<tagname>'
			if(stristr($xss_check, '<'.$tag.' ') || stristr($xss_check, '<'.$tag.'>')) {
				$err = 'COM_PHOCADOWNLOAD_WARNIEXSS';
				return false;
			}
		}
		
		return true;
	}
Ejemplo n.º 6
0
 function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $document = JFactory::getDocument();
     $uri = JFactory::getURI();
     $menus = $app->getMenu();
     $menu = $menus->getActive();
     $this->t['p'] = $app->getParams();
     $user = JFactory::getUser();
     $db = JFactory::getDBO();
     $user = JFactory::getUser();
     $userLevels = implode(',', $user->getAuthorisedViewLevels());
     $this->t['pi'] = 'media/com_phocadownload/images/';
     $this->t['pp'] = 'index.php?option=com_phocadownload&view=user&controller=user';
     $this->t['pl'] = 'index.php?option=com_users&view=login&return=' . base64_encode($this->t['pp'] . '&Itemid=' . $app->input->get('Itemid', 0, 'int'));
     $neededAccessLevels = PhocaDownloadAccess::getNeededAccessLevels();
     $access = PhocaDownloadAccess::isAccess($user->getAuthorisedViewLevels(), $neededAccessLevels);
     if (!$access) {
         $app->redirect(JRoute::_($this->t['pl'], false), JText::_("COM_PHOCADOWNLOAD_NOT_AUTHORISED_ACTION"));
         return;
     }
     PhocaDownloadRenderFront::renderAllCSS();
     // = = = = = = = = = = =
     // PANE
     // = = = = = = = = = = =
     // - - - - - - - - - -
     // ALL TABS
     // - - - - - - - - - -
     // UCP is disabled (security reasons)
     if ((int) $this->t['p']->get('enable_user_cp', 0) == 0) {
         $app->redirect(JURI::base(false), JText::_("COM_PHOCADOWNLOAD_USER_UPLOAD_DISABLED"));
         exit;
     }
     $this->t['tab'] = $app->input->get('tab', 0, 'string');
     $this->t['maxuploadchar'] = $this->t['p']->get('max_upload_char', 1000);
     $this->t['enableuseruploadapprove'] = $this->t['p']->get('enable_user_upload_approve', 0);
     $this->t['showpageheading'] = $this->t['p']->get('show_page_heading', 1);
     $this->t['uploadmaxsize'] = $this->t['p']->get('user_file_upload_size', 3145728);
     $this->t['uploadmaxsizeread'] = PhocaDownloadFile::getFileSizeReadable($this->t['uploadmaxsize']);
     $this->t['userfilesmaxcount'] = $this->t['p']->get('user_files_max_count', 5);
     $this->t['userfilesmaxsize'] = $this->t['p']->get('user_files_max_size', 20971520);
     $this->t['send_mail_upload'] = $this->t['p']->get('send_mail_upload', 0);
     $this->t['pw'] = PhocaDownloadRenderFront::renderPhocaDownload();
     //Subcateogry
     //$this->t['parentid']			= $app->input->get('parentcategoryid', 0, 'int');
     //$document->addScript(JURI::base(true).'/components/com_phocadownload/assets/js/comments.js');
     $document->addCustomTag(PhocaDownloadRenderFront::renderOnUploadJS());
     $document->addCustomTag(PhocaDownloadRenderFront::renderDescriptionUploadJS((int) $this->t['maxuploadchar']));
     $document->addCustomTag(PhocaDownloadRenderFront::userTabOrdering());
     $model = $this->getModel('user');
     // Upload Form - - - - - - - - - - - - - - -
     $ftp = !JClientHelper::hasCredentials('ftp');
     // Set FTP form
     $session = JFactory::getSession();
     $this->assignRef('session', $session);
     // END Upload Form - - - - - - - - - - - - -
     $this->t['displayupload'] = 1;
     // - - - - - - - - - -
     // FORM
     // - - - - - - - - - -
     // No Controller because of returning back the values in case some form field is not OK
     // Set default for returning back
     $formData = new JObject();
     $formData->set('title', '');
     $formData->set('description', '');
     $formData->set('author', '');
     $formData->set('email', '');
     $formData->set('license', '');
     $formData->set('website', '');
     $formData->set('version', '');
     $this->t['errorcatid'] = '';
     $this->t['erroremail'] = '';
     $this->t['errorwebsite'] = '';
     $this->t['errorfile'] = '';
     $task = $app->input->get('task', '', 'string');
     if ($task == 'upload') {
         $post['title'] = $app->input->get('phocadownloaduploadtitle', '', 'string');
         $post['description'] = $app->input->get('phocadownloaduploaddescription', '', 'string');
         $post['catidfiles'] = $app->input->get('catidfiles', 0, 'int');
         $post['description'] = substr($post['description'], 0, (int) $this->t['maxuploadchar']);
         $post['approved'] = 0;
         $post['published'] = 1;
         $post['owner_id'] = $user->id;
         if ($this->t['enableuseruploadapprove'] == 0) {
             $post['approved'] = 1;
         }
         $post['author'] = $app->input->get('phocadownloaduploadauthor', '', 'string');
         $post['email'] = $app->input->get('phocadownloaduploademail', '', 'string');
         $post['website'] = $app->input->get('phocadownloaduploadwebsite', '', 'string');
         $post['license'] = $app->input->get('phocadownloaduploadlicense', '', 'string');
         $post['version'] = $app->input->get('phocadownloaduploadversion', '', 'string');
         if ($post['title'] != '') {
             $formData->set('title', $post['title']);
         }
         if ($post['description'] != '') {
             $formData->set('description', $post['description']);
         }
         if ($post['author'] != '') {
             $formData->set('author', $post['author']);
         }
         if ($post['email'] != '') {
             $formData->set('email', $post['email']);
         }
         if ($post['website'] != '') {
             $formData->set('website', $post['website']);
         }
         if ($post['license'] != '') {
             $formData->set('license', $post['license']);
         }
         if ($post['version'] != '') {
             $formData->set('version', $post['version']);
         }
         //catid
         $returnForm = 0;
         if ($post['catidfiles'] < 1) {
             $this->t['errorcatid'] = JText::_('COM_PHOCADOWNLOAD_PLEASE_SELECT_CATEGORY');
             $returnForm = 1;
         }
         jimport('joomla.mail.helper');
         if ($post['email'] != '' && !JMailHelper::isEmailAddress($post['email'])) {
             $this->t['erroremail'] = JText::_('COM_PHOCADOWNLOAD_PLEASE_ENTER_VALID_EMAIL_ADDRESS');
             $returnForm = 1;
         }
         if ($post['website'] != '' && !PhocaDownloadUtils::isURLAddress($post['website'])) {
             $this->t['errorwebsite'] = JText::_('COM_PHOCADOWNLOAD_PLEASE_ENTER_VALID_WEBSITE');
             $returnForm = 1;
         }
         // Upload
         $errUploadMsg = '';
         $redirectUrl = '';
         $fileArray = JRequest::getVar('Filedata', '', 'files', 'array');
         if (empty($fileArray) || isset($fileArray['name']) && $fileArray['name'] == '') {
             $this->t['errorfile'] = JText::_('COM_PHOCADOWNLOAD_PLEASE_ADD_FILE');
             $returnForm = 1;
         }
         if ($post['title'] == '') {
             $post['title'] = PhocaDownloadFile::removeExtension($fileArray['name']);
         }
         $post['alias'] = PhocaDownloadUtils::getAliasName($post['title']);
         if ($returnForm == 0) {
             $errorUploadMsg = '';
             if ($model->singleFileUpload($errorUploadMsg, $fileArray, $post)) {
                 if ($this->t['send_mail_upload'] > 0) {
                     PhocaDownloadMail::sendMail((int) $this->t['send_mail_upload'], $post['title'], 2);
                 }
                 $Itemid = $app->input->get('Itemid', 0, 'int');
                 $limitStart = $app->input->get('limitstart', 0, 'int');
                 if ($limitStart > 0) {
                     $limitStartUrl = '&limitstart=' . $limitStart;
                 } else {
                     $limitStartUrl = '';
                 }
                 $link = 'index.php?option=com_phocadownload&view=user&Itemid=' . $Itemid . $limitStartUrl;
                 $app->redirect(JRoute::_($link, false), JText::_("COM_PHOCADOWNLOAD_SUCCESS_FILE_UPLOADED"));
                 exit;
             } else {
                 $this->t['errorfile'] = JText::_('COM_PHOCADOWNLOAD_ERROR_FILE_UPLOADED');
                 if ($errorUploadMsg != '') {
                     $this->t['errorfile'] .= '<br />' . $errorUploadMsg;
                 }
             }
         }
     }
     // - - - - - - - - - - -
     // FILES
     // - - - - - - - - - - -
     $this->t['filesitems'] = $model->getDataFiles($user->id);
     $this->t['filestotal'] = $model->getTotalFiles($user->id);
     $this->t['filespagination'] = $model->getPaginationFiles($user->id);
     $filter_state_files = $app->getUserStateFromRequest($this->_context_files . '.filter_state', 'filter_state', '', 'word');
     $filter_catid_files = $app->getUserStateFromRequest($this->_context_files . '.filter_catid', 'filter_catid', 0, 'int');
     $catid_files = $app->getUserStateFromRequest($this->_context_files . '.catid', 'catid', 0, 'int');
     //$filter_sectionid_files	= $app->getUserStateFromRequest( $this->_context_files.'.filter_sectionid',	'filter_sectionid',	0,	'int' );
     $filter_order_files = $app->getUserStateFromRequest($this->_context_files . '.filter_order', 'filter_order', 'a.ordering', 'cmd');
     $filter_order_Dir_files = $app->getUserStateFromRequest($this->_context_files . '.filter_order_Dir', 'filter_order_Dir', '', 'word');
     $search_files = $app->getUserStateFromRequest($this->_context_files . '.search', 'search', '', 'string');
     $search_files = JString::strtolower($search_files);
     // build list of categories
     $javascript = 'class="inputbox" size="1" onchange="document.phocadownloadfilesform.submit();"';
     // get list of categories for dropdown filter
     $whereC = array();
     //if ($filter_sectionid_files > 0) {
     //	$whereC[] = ' cc.section = '.$db->Quote($filter_sectionid_files);
     //}
     //$whereC[]	= "(cc.uploaduserid LIKE '%-1%' OR cc.uploaduserid LIKE '%".(int)$user->id."%')";
     //$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."} )";
     $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 . " )";
     $whereC = count($whereC) ? ' WHERE ' . implode(' AND ', $whereC) : '';
     // get list of categories for dropdown filter
     $query = 'SELECT cc.id AS value, cc.title AS text, cc.parent_id as parentid' . ' FROM #__phocadownload_categories AS cc' . $whereC . ' ORDER BY cc.ordering';
     $lists_files['catid'] = PhocaDownloadCategory::filterCategory($query, $catid_files, TRUE, TRUE, TRUE);
     /*$whereS		= array();
     		//$whereS[]	= "(cc.uploaduserid LIKE '%-1%' OR cc.uploaduserid LIKE '%".(int)$user->id."%')";
     		$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." )";
     		$whereS[]	= 's.published = 1';
     		$whereS 		= ( count( $whereS ) ? ' WHERE '. implode( ' AND ', $whereS ) : '' );
     		// sectionid
     		$query = 'SELECT s.title AS text, s.id AS value'
     		. ' FROM #__phocadownload_sections AS s'
     		. ' LEFT JOIN #__phocadownload_categories AS cc ON cc.section = s.id'
     		. $whereS
     		. ' GROUP BY s.id'
     		. ' ORDER BY s.ordering';
     		
     
     		
     		// state filter
     	/*	$state_files[] 		= JHTML::_('select.option',  '', '- '. JText::_( 'Select State' ) .' -' );
     		$state_files[] 		= JHTML::_('select.option',  'P', JText::_( 'Published' ) );
     		$state_files[] 		= JHTML::_('select.option',  'U', JText::_( 'Unpublished') );
     		$lists_image['state']	= JHTML::_('select.genericlist',   $state_files, 'filter_state', 'class="inputbox" size="1" onchange="document.phocadownloadfilesform.submit();"', 'value', 'text', $filter_state );*/
     //$lists_files['sectionid'] = PhocaDownloadCategory::filterSection($query, $filter_sectionid_files, TRUE);
     // state filter
     $lists_files['state'] = JHTML::_('grid.state', $filter_state_files);
     // table ordering
     $lists_files['order_Dir'] = $filter_order_Dir_files;
     $lists_files['order'] = $filter_order_files;
     // search filter
     $lists_files['search'] = $search_files;
     $this->t['catidfiles'] = $catid_files;
     $this->t['filestab'] = 1;
     // Tabs
     $displayTabs = 0;
     if ((int) $this->t['filestab'] == 0) {
         $currentTab['files'] = -1;
     } else {
         $currentTab['files'] = $displayTabs;
         $displayTabs++;
     }
     $this->t['displaytabs'] = $displayTabs;
     $this->t['currenttab'] = $currentTab;
     // ACTION
     $this->t['action'] = $uri->toString();
     // SEF problem
     $isThereQM = false;
     $isThereQM = preg_match("/\\?/i", $this->t['action']);
     if ($isThereQM) {
         $amp = '&amp;';
     } else {
         $amp = '?';
     }
     $this->t['actionamp'] = htmlspecialchars($this->t['action']) . $amp;
     $this->t['istheretab'] = false;
     $this->t['istheretab'] = preg_match("/tab=/i", $this->t['action']);
     $this->t['ps'] = '&tab=' . $this->t['currenttab']['files'] . '&limitstart=' . $this->t['filespagination']->limitstart;
     // ASIGN
     $this->assignRef('listsfiles', $lists_files);
     $this->assignRef('formdata', $formData);
     $this->assignRef('tmpl', $this->t);
     $this->assignRef('params', $this->t['p']);
     $session = JFactory::getSession();
     $this->assignRef('session', $session);
     parent::display($tpl);
 }
Ejemplo n.º 7
0
 public function getFileDate($filename, $date)
 {
     $dateO = '';
     $ddt = $this->params->get('display_date_type', 0);
     if ((int) $ddt > 0) {
         if ($filename != '') {
             $dateO = PhocaDownloadFile::getFileTime($filename, $ddt);
         }
     } else {
         $dateO = JHTML::Date($date, JText::_('DATE_FORMAT_LC3'));
     }
     return $dateO;
 }
Ejemplo n.º 8
0
	public function delete(&$pks)
	{
		$dispatcher = JEventDispatcher::getInstance();
		$pks = (array) $pks;
		$table = $this->getTable();

		// Include the content plugins for the on delete events.
		JPluginHelper::importPlugin('content');

		// Iterate the items to delete each one.
		foreach ($pks as $i => $pk)
		{

			if ($table->load($pk))
			{

				if ($this->canDelete($table))
				{

					$context = $this->option . '.' . $this->name;

					// Trigger the onContentBeforeDelete event.
					$result = $dispatcher->trigger($this->event_before_delete, array($context, $table));
					if (in_array(false, $result, true))
					{
						$this->setError($table->getError());
						return false;
					}
					
					//PHOCAEDIT
					$filePath = PhocaDownloadFile::getCSSFile($pk, true);
					//END PHOCAEDIT
					
					if (!$table->delete($pk))
					{
						$this->setError($table->getError());
						return false;
					}

					//PHOCAEDIT
					if (file_exists($filePath)) {
						JFile::delete($filePath);
					}
					//END PHOCAEDIT
					
					// Trigger the onContentAfterDelete event.
					$dispatcher->trigger($this->event_after_delete, array($context, $table));

				}
				else
				{

					// Prune items that you can't change.
					unset($pks[$i]);
					$error = $this->getError();
					if ($error)
					{
						JLog::add($error, JLog::WARNING, 'jerror');
						return false;
					}
					else
					{
						JLog::add(JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), JLog::WARNING, 'jerror');
						return false;
					}
				}

			}
			else
			{
				$this->setError($table->getError());
				return false;
			}
		}

		// Clear the component's cache
		$this->cleanCache();

		return true;
	}
Ejemplo n.º 9
0
if (!empty($this->t['mostvieweddocs']) && $this->t['displaymostdownload'] == 1) {
    $l = new PhocaDownloadLayout();
    foreach ($this->t['mostvieweddocs'] as $value) {
        // USER RIGHT - Access of categories (if file is included in some not accessed category) - - - - -
        // ACCESS is handled in SQL query, ACCESS USER ID is handled here (specific users)
        $rightDisplay = 0;
        if (!empty($value)) {
            $rightDisplay = PhocaDownloadAccess::getUserRight('accessuserid', $value->cataccessuserid, $value->cataccess, $this->t['user']->getAuthorisedViewLevels(), $this->t['user']->get('id', 0), 0);
        }
        // - - - - - - - - - - - - - - - - - - - - - -
        if ($rightDisplay == 1) {
            // FILESIZE
            if ($value->filename != '') {
                $absFile = str_replace('/', DS, JPath::clean($this->t['absfilepath'] . $value->filename));
                if (JFile::exists($absFile)) {
                    $fileSize = PhocaDownloadFile::getFileSizeReadable(filesize($absFile));
                } else {
                    $fileSize = '';
                }
            }
            // IMAGE FILENAME
            //$imageFileName = '';
            //if ($value->image_filename !='') {
            $imageFileName = $l->getImageFileName($value->image_filename, $value->filename, 2);
            /*$thumbnail = false;
            		$thumbnail = preg_match("/phocathumbnail/i", $value->image_filename);
            		if ($thumbnail) {
            			$imageFileName 	= '';
            		} else {
            			$imageFileName = 'style="background: url(\''.$this->t['cssimgpath'].$value->image_filename.'\') 0 center no-repeat;"';
            		}*/
Ejemplo n.º 10
0
 public function onContentPrepare($context, &$article, &$params, $page = 0)
 {
     $document = JFactory::getDocument();
     $db = JFactory::getDBO();
     $iSize = $this->params->get('icon_size', 32);
     $iMime = $this->params->get('file_icon_mime', 0);
     $component = 'com_phocadownload';
     $paramsC = JComponentHelper::getParams($component);
     $ordering = $paramsC->get('file_ordering', 1);
     // Start Plugin
     $regex_one = '/({phocadownload\\s*)(.*?)(})/si';
     $regex_all = '/{phocadownload\\s*.*?}/si';
     $matches = array();
     $count_matches = preg_match_all($regex_all, $article->text, $matches, PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER);
     JHTML::stylesheet('media/com_phocadownload/css/main/phocadownload.css');
     JHTML::stylesheet('media/plg_content_phocadownload/css/phocadownload.css');
     // Start if count_matches
     if ($count_matches != 0) {
         $l = new PhocaDownloadLayout();
         // Start CSS
         for ($i = 0; $i < $count_matches; $i++) {
             $view = '';
             $id = '';
             $text = '';
             $target = '';
             $playerwidth = $paramsC->get('player_width', 328);
             $playerheight = $paramsC->get('player_height', 200);
             $previewwidth = $paramsC->get('preview_width', 640);
             $previewheight = $paramsC->get('preview_height', 480);
             $playerheightmp3 = $paramsC->get('player_mp3_height', 30);
             $url = '';
             $youtubewidth = 448;
             $youtubeheight = 336;
             $fileView = $paramsC->get('display_file_view', 0);
             $previewWindow = $paramsC->get('preview_popup_window', 0);
             $playWindow = $paramsC->get('play_popup_window', 0);
             $limit = 5;
             // Get plugin parameters
             $phocadownload = $matches[0][$i][0];
             preg_match($regex_one, $phocadownload, $phocadownload_parts);
             $parts = explode("|", $phocadownload_parts[2]);
             $values_replace = array("/^'/", "/'\$/", "/^&#39;/", "/&#39;\$/", "/<br \\/>/");
             foreach ($parts as $key => $value) {
                 $values = explode("=", $value, 2);
                 foreach ($values_replace as $key2 => $values2) {
                     $values = preg_replace($values2, '', $values);
                 }
                 // Get plugin parameters from article
                 if ($values[0] == 'view') {
                     $view = $values[1];
                 } else {
                     if ($values[0] == 'id') {
                         $id = $values[1];
                     } else {
                         if ($values[0] == 'text') {
                             $text = $values[1];
                         } else {
                             if ($values[0] == 'target') {
                                 $target = $values[1];
                             } else {
                                 if ($values[0] == 'playerwidth') {
                                     $playerwidth = (int) $values[1];
                                 } else {
                                     if ($values[0] == 'playerheight') {
                                         $playerheight = (int) $values[1];
                                     } else {
                                         if ($values[0] == 'playerheightmp3') {
                                             $playerheightmp3 = (int) $values[1];
                                         } else {
                                             if ($values[0] == 'previewwidth') {
                                                 $previewwidth = (int) $values[1];
                                             } else {
                                                 if ($values[0] == 'previewheight') {
                                                     $previewheight = (int) $values[1];
                                                 } else {
                                                     if ($values[0] == 'youtubewidth') {
                                                         $youtubewidth = (int) $values[1];
                                                     } else {
                                                         if ($values[0] == 'youtubeheight') {
                                                             $youtubeheight = (int) $values[1];
                                                         } else {
                                                             if ($values[0] == 'previewwindow') {
                                                                 $previewWindow = (int) $values[1];
                                                             } else {
                                                                 if ($values[0] == 'playwindow') {
                                                                     $playWindow = (int) $values[1];
                                                                 } else {
                                                                     if ($values[0] == 'limit') {
                                                                         $limit = (int) $values[1];
                                                                     } else {
                                                                         if ($values[0] == 'url') {
                                                                             $url = $values[1];
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             switch ($target) {
                 case 'b':
                     $targetOutput = 'target="_blank" ';
                     break;
                 case 't':
                     $targetOutput = 'target="_top" ';
                     break;
                 case 'p':
                     $targetOutput = 'target="_parent" ';
                     break;
                 case 's':
                     $targetOutput = 'target="_self" ';
                     break;
                 default:
                     $targetOutput = '';
                     break;
             }
             $output = '';
             /*
             //Itemid
             $menu 		=& JSite::getMenu();
             $itemSection= $menu->getItems('link', 'index.php?option=com_phocadownload&view=sections');
             if(isset($itemSection[0])) {
             	$itemId = $itemSection[0]->id;
             } else {
             	$itemId = JRequest::getVar('Itemid', 1, 'get', 'int');
             }
             */
             switch ($view) {
                 /*
                 // - - - - - - - - - - - - - - - -
                 // SECTIONS
                 // - - - - - - - - - - - - - - - -
                 case 'sections':						
                 	if ($text !='') {
                 		$textOutput = $text;
                 	} else {
                 		$textOutput = JText::_('PLG_CONTENT_PHOCADOWNLOAD_DOWNLOAD_SECTIONS');
                 	}
                 	
                 	$link = PhocaDownloadRoute::getSectionsRoute();
                 	
                 	$output .= '<div class="phocadownloadsections'.(int)$iSize.'"><a href="'. JRoute::_($link).'" '.$targetOutput.'>'. $textOutput.'</a></div>';
                 break;
                 
                 // - - - - - - - - - - - - - - - -
                 // SECTION
                 // - - - - - - - - - - - - - - - -
                 case 'section':
                 	if ((int)$id > 0) {
                 		$query = 'SELECT a.id, a.title, a.alias,'
                 		. ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug'
                 		. ' FROM #__phocadownload_sections AS a'
                 		. ' WHERE a.id = '.(int)$id;
                 		
                 		$db->setQuery($query);
                 		$item = $db->loadObject();
                 		
                 		if (isset($item->id) && isset($item->slug)) {
                 			
                 			if ($text !='') {
                 				$textOutput = $text;
                 			} else if (isset($item->title) && $item->title != '') {
                 				$textOutput = $item->title;
                 			} else {
                 				$textOutput = JText::_('PLG_CONTENT_PHOCADOWNLOAD_DOWNLOAD_SECTION');
                 			}
                 			$link = PhocaDownloadRoute::getSectionRoute($item->id, $item->alias);
                 			// 'index.php?option=com_phocadownload&view=section&id='.$item->slug.'&Itemid='. $itemId
                 			
                 			$output .= '<div class="phocadownloadsection'.(int)$iSize.'"><a href="'. JRoute::_($link).'" '.$targetOutput.'>'. $textOutput.'</a></div>';
                 		}
                 	}
                 break;
                 */
                 // - - - - - - - - - - - - - - - -
                 // CATEGORIES
                 // - - - - - - - - - - - - - - - -
                 case 'categories':
                     if ($text != '') {
                         $textOutput = $text;
                     } else {
                         $textOutput = JText::_('PLG_CONTENT_PHOCADOWNLOAD_DOWNLOAD_CATEGORIES');
                     }
                     $link = PhocaDownloadRoute::getCategoriesRoute();
                     $output .= '<div class="phocadownloadcategories' . (int) $iSize . '"><a href="' . JRoute::_($link) . '" ' . $targetOutput . '>' . $textOutput . '</a></div>';
                     break;
                     // - - - - - - - - - - - - - - - -
                     // CATEGORY
                     // - - - - - - - - - - - - - - - -
                 // - - - - - - - - - - - - - - - -
                 // CATEGORY
                 // - - - - - - - - - - - - - - - -
                 case 'category':
                     if ((int) $id > 0) {
                         $query = 'SELECT a.id, a.title, a.alias,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug' . ' FROM #__phocadownload_categories AS a' . ' WHERE a.id = ' . (int) $id;
                         $db->setQuery($query);
                         $item = $db->loadObject();
                         if (isset($item->id) && isset($item->slug)) {
                             if ($text != '') {
                                 $textOutput = $text;
                             } else {
                                 if (isset($item->title) && $item->title != '') {
                                     $textOutput = $item->title;
                                 } else {
                                     $textOutput = JText::_('PLG_CONTENT_PHOCADOWNLOAD_DOWNLOAD_CATEGORY');
                                 }
                             }
                             $link = PhocaDownloadRoute::getCategoryRoute($item->id, $item->alias);
                             //'index.php?option=com_phocadownload&view=category&id='.$item->slug.'&Itemid='. $itemId
                             $output .= '<div class="phocadownloadcategory' . (int) $iSize . '"><a href="' . JRoute::_($link) . '" ' . $targetOutput . '>' . $textOutput . '</a></div>';
                         }
                     }
                     break;
                     // - - - - - - - - - - - - - - - -
                     // FILELIST
                     // - - - - - - - - - - - - - - - -
                 // - - - - - - - - - - - - - - - -
                 // FILELIST
                 // - - - - - - - - - - - - - - - -
                 case 'filelist':
                     $fileOrdering = PhocaDownloadOrdering::getOrderingText($ordering);
                     $query = 'SELECT a.id, a.title, a.alias, a.filename_play, a.filename_preview, a.link_external, a.image_filename, a.filename, c.id as catid, a.confirm_license, c.title as cattitle, c.alias as catalias,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug,' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as catslug' . ' FROM #__phocadownload AS a' . ' LEFT JOIN #__phocadownload_categories AS c ON a.catid = c.id';
                     if ((int) $id > 0) {
                         $query .= ' WHERE c.id = ' . (int) $id;
                         //$query .= ' WHERE c.id = '.(int)$id . ' AND a.published = 1 AND a.approved = 1';
                     } else {
                         //$query .= ' WHERE a.published = 1 AND a.approved = 1';
                     }
                     $query .= ' ORDER BY a.' . $fileOrdering;
                     $query .= ' LIMIT 0, ' . (int) $limit;
                     $db->setQuery($query);
                     $items = $db->loadObjectList();
                     if (!empty($items)) {
                         $output .= '<div class="phocadownloadfilelist">';
                         foreach ($items as $item) {
                             $imageFileName = $l->getImageFileName($item->image_filename, $item->filename, 3, (int) $iSize);
                             if (isset($item->id) && isset($item->slug) && isset($item->catid) && isset($item->catslug)) {
                                 if ($text != '') {
                                     $textOutput = $text;
                                 } else {
                                     if (isset($item->title) && $item->title != '') {
                                         $textOutput = $item->title;
                                     } else {
                                         $textOutput = JText::_('PLG_CONTENT_PHOCADOWNLOAD_DOWNLOAD_FILE');
                                     }
                                 }
                                 if (isset($item->confirm_license) && $item->confirm_license > 0 || $fileView == 1) {
                                     $link = PhocaDownloadRoute::getFileRoute($item->id, $item->catid, $item->alias, $item->catalias, 0, 'file');
                                     if ($iMime == 1) {
                                         $output .= '<div class="pd-filename phocadownloadfilelistitem phoca-dl-file-box-mod">' . $imageFileName['filenamethumb'] . '<div class="pd-document' . (int) $iSize . '" ' . $imageFileName['filenamestyle'] . '><a href="' . JRoute::_($link) . '" ' . $targetOutput . '>' . $textOutput . '</a></div></div>';
                                     } else {
                                         $output .= '<div class="phocadownloadfilelist' . (int) $iSize . '"><a href="' . JRoute::_($link) . '" ' . $targetOutput . '>' . $textOutput . '</a></div>';
                                     }
                                 } else {
                                     if ($item->link_external != '') {
                                         $link = $item->link_external;
                                     } else {
                                         $link = PhocaDownloadRoute::getFileRoute($item->id, $item->catid, $item->alias, $item->catalias, 0, 'download');
                                     }
                                     if ($iMime == 1) {
                                         $output .= '<div class="pd-filename phocadownloadfilelistitem phoca-dl-file-box-mod">' . $imageFileName['filenamethumb'] . '<div class="pd-document' . (int) $iSize . '" ' . $imageFileName['filenamestyle'] . '><a href="' . JRoute::_($link) . '" ' . $targetOutput . '>' . $textOutput . '</a></div></div>';
                                     } else {
                                         $output .= '<div class="phocadownloadfilelist' . (int) $iSize . '"><a href="' . JRoute::_($link) . '" ' . $targetOutput . '>' . $textOutput . '</a></div>';
                                     }
                                 }
                             }
                         }
                         $output .= '</div>';
                     }
                     break;
                     // - - - - - - - - - - - - - - - -
                     // FILE
                     // - - - - - - - - - - - - - - - -
                 // - - - - - - - - - - - - - - - -
                 // FILE
                 // - - - - - - - - - - - - - - - -
                 case 'file':
                 case 'fileplay':
                 case 'fileplaylink':
                 case 'filepreviewlink':
                     if ((int) $id > 0) {
                         $query = 'SELECT a.id, a.title, a.alias, a.filename_play, a.filename_preview, a.link_external, a.image_filename, a.filename, c.id as catid, a.confirm_license, c.title as cattitle, c.alias as catalias,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug,' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as catslug' . ' FROM #__phocadownload AS a' . ' LEFT JOIN #__phocadownload_categories AS c ON a.catid = c.id' . ' WHERE a.id = ' . (int) $id;
                         $db->setQuery($query);
                         $item = $db->loadObject();
                         if (isset($item->id) && isset($item->slug) && isset($item->catid) && isset($item->catslug)) {
                             if ($text != '') {
                                 $textOutput = $text;
                             } else {
                                 if (isset($item->title) && $item->title != '') {
                                     $textOutput = $item->title;
                                 } else {
                                     if ($view == 'fileplay') {
                                         $textOutput = JText::_('PLG_CONTENT_PHOCADOWNLOAD_PLAY_FILE');
                                     } else {
                                         $textOutput = JText::_('PLG_CONTENT_PHOCADOWNLOAD_DOWNLOAD_FILE');
                                     }
                                 }
                             }
                             $imageFileName = $l->getImageFileName($item->image_filename, $item->filename, 3, (int) $iSize);
                             // - - - - -
                             // PLAY
                             // - - - - -
                             if ($view == 'fileplay') {
                                 $play = 1;
                                 $fileExt = '';
                                 $filePath = PhocaDownloadPath::getPathSet('fileplay');
                                 $filePath = str_replace('../', JURI::base(true) . '/', $filePath['orig_rel_ds']);
                                 if (isset($item->filename_play) && $item->filename_play != '') {
                                     $fileExt = PhocaDownloadFile::getExtension($item->filename_play);
                                     $canPlay = PhocaDownloadFile::canPlay($item->filename_play);
                                     if ($canPlay) {
                                         $tmpl['playfilewithpath'] = $filePath . $item->filename_play;
                                         $tmpl['playerpath'] = JURI::base() . 'components/com_phocadownload/assets/flowplayer/';
                                     } else {
                                         $output .= JText::_('PLG_CONTENT_PHOCADOWNLOAD_NO_CORRECT_FILE_FOR_PLAYING_FOUND');
                                         $play = 0;
                                     }
                                 } else {
                                     $output .= JText::_('PLG_CONTENT_PHOCADOWNLOAD_NO_FILE_FOR_PLAYING_FOUND');
                                     $play = 0;
                                 }
                                 if ($play == 1) {
                                     //Correct MP3
                                     $tmpl['filetype'] = '';
                                     if ($fileExt == 'mp3') {
                                         $tmpl['filetype'] = 'mp3';
                                         $playerheight = $playerheightmp3;
                                     }
                                     $versionFLP = '3.2.2';
                                     $versionFLPJS = '3.2.2';
                                     //Flow Player
                                     $document->addScript($tmpl['playerpath'] . 'flowplayer-' . $versionFLPJS . '.min.js');
                                     $output .= '<div style="text-align:center;margin: 10px auto">' . "\n" . '<div style="margin: 0 auto;text-align:center; width:' . $playerwidth . 'px"><a href="' . $tmpl['playfilewithpath'] . '"  style="display:block;width:' . $playerwidth . 'px;height:' . $playerheight . 'px" id="pdplayer' . $i . '"></a>' . "\n";
                                     if ($tmpl['filetype'] == 'mp3') {
                                         $output .= '<script type="text/javascript">' . "\n" . 'window.addEvent("domready", function() {' . "\n" . 'flowplayer("pdplayer' . $i . '", "' . $tmpl['playerpath'] . 'flowplayer-' . $versionFLP . '.swf",' . '{ ' . "\n" . ' clip: { ' . "\n" . '		url: \'' . $tmpl['playfilewithpath'] . '\',' . "\n" . '		autoPlay: false' . "\n" . '	}, ' . "\n" . '	plugins: { ' . "\n" . '		controls: { ' . "\n" . '			fullscreen: false, ' . "\n" . '			height: ' . $playerheight . "\n" . '		} ' . "\n" . '	} ' . "\n" . '} ' . "\n" . ');' . "\n" . '});' . '</script>' . "\n";
                                     } else {
                                         $output .= '<script type="text/javascript">' . "\n" . 'window.addEvent("domready", function() {' . "\n" . 'flowplayer("pdplayer' . $i . '", "' . $tmpl['playerpath'] . 'flowplayer-' . $versionFLP . '.swf",' . "\n" . '{ ' . "\n" . ' clip: { ' . "\n" . '		url: \'' . $tmpl['playfilewithpath'] . '\',' . "\n" . '		autoPlay: false,' . "\n" . '		autoBuffering: true' . "\n" . '	}, ' . "\n" . '} ' . "\n" . ');' . "\n" . '});' . '</script>' . "\n";
                                     }
                                     $output .= '</div></div>' . "\n";
                                 }
                             } else {
                                 if ($view == 'fileplaylink') {
                                     // PLAY - - - - - - - - - - - -
                                     $windowWidthPl = (int) $playerwidth + 30;
                                     $windowHeightPl = (int) $playerheight + 30;
                                     $windowHeightPlMP3 = (int) $playerheightmp3 + 30;
                                     //$playWindow 	= $paramsC->get( 'play_popup_window', 0 );
                                     if ($playWindow == 1) {
                                         $buttonPl = new JObject();
                                         $buttonPl->set('methodname', 'js-button');
                                         $buttonPl->set('options', "window.open(this.href,'win2','width=" . $windowWidthPl . ",height=" . $windowHeightPl . ",scrollbars=yes,menubar=no,resizable=yes'); return false;");
                                         $buttonPl->set('optionsmp3', "window.open(this.href,'win2','width=" . $windowWidthPl . ",height=" . $windowHeightPlMP3 . ",scrollbars=yes,menubar=no,resizable=yes'); return false;");
                                     } else {
                                         JHTML::_('behavior.modal', 'a.modal-button');
                                         $document->addCustomTag("<style type=\"text/css\"> \n" . " #sbox-window.phocadownloadplaywindow   {background-color:#fff;padding:2px} \n" . " #sbox-overlay.phocadownloadplayoverlay  {background-color:#000;} \n" . " </style> \n");
                                         $buttonPl = new JObject();
                                         $buttonPl->set('name', 'image');
                                         $buttonPl->set('modal', true);
                                         $buttonPl->set('methodname', 'modal-button');
                                         $buttonPl->set('options', "{handler: 'iframe', size: {x: " . $windowWidthPl . ", y: " . $windowHeightPl . "}, overlayOpacity: 0.7, classWindow: 'phocadownloadplaywindow', classOverlay: 'phocadownloadplayoverlay'}");
                                         $buttonPl->set('optionsmp3', "{handler: 'iframe', size: {x: " . $windowWidthPl . ", y: " . $windowHeightPlMP3 . "}, overlayOpacity: 0.7, classWindow: 'phocadownloadplaywindow', classOverlay: 'phocadownloadplayoverlay'}");
                                     }
                                     // - - - - - - - - - - - - - - -
                                     $fileExt = '';
                                     $filePath = PhocaDownloadPath::getPathSet('fileplay');
                                     $filePath = str_replace('../', JURI::base(true) . '/', $filePath['orig_rel_ds']);
                                     if (isset($item->filename_play) && $item->filename_play != '') {
                                         $fileExt = PhocaDownloadFile::getExtension($item->filename_play);
                                         $canPlay = PhocaDownloadFile::canPlay($item->filename_play);
                                         if ($canPlay) {
                                             // Special height for music only
                                             $buttonPlOptions = $buttonPl->options;
                                             if ($fileExt == 'mp3') {
                                                 $buttonPlOptions = $buttonPl->optionsmp3;
                                             }
                                             /*if ($text == '') {
                                             			$text = JText::_('PLG_CONTENT_PHOCADOWNLOAD_PLAY');
                                             		}*/
                                             if ($text != '') {
                                                 $textOutput = $text;
                                                 //} else if (isset($item->title) && $item->title != '') {
                                                 //	$textOutput = $item->title;
                                             } else {
                                                 $textOutput = JText::_('PLG_CONTENT_PHOCADOWNLOAD_PLAY');
                                             }
                                             $playLink = JRoute::_(PhocaDownloadRoute::getFileRoute($item->id, $item->catid, $item->alias, $item->catalias, 0, 'play'));
                                             if ($iMime == 1) {
                                                 $output .= '<div class="pd-filename phocadownloadfile phoca-dl-file-box-mod">' . $imageFileName['filenamethumb'] . '<div class="pd-document' . (int) $iSize . '" ' . $imageFileName['filenamestyle'] . '>';
                                             } else {
                                                 $output .= '<div><div class="phocadownloadplay' . (int) $iSize . '">';
                                             }
                                             if ($playWindow == 1) {
                                                 $output .= '<a  href="' . $playLink . '" onclick="' . $buttonPlOptions . '" >' . $textOutput . '</a>';
                                             } else {
                                                 $output .= '<a class="modal-button" href="' . $playLink . '" rel="' . $buttonPlOptions . '" >' . $textOutput . '</a>';
                                             }
                                             $output .= '</div></div>';
                                         }
                                     } else {
                                         $output .= JText::_('PLG_CONTENT_PHOCADOWNLOAD_NO_FILE_FOR_PLAYING_FOUND');
                                     }
                                 } else {
                                     if ($view == 'filepreviewlink') {
                                         if (isset($item->filename_preview) && $item->filename_preview != '') {
                                             $fileExt = PhocaDownloadFile::getExtension($item->filename_preview);
                                             if ($fileExt == 'pdf' || $fileExt == 'jpeg' || $fileExt == 'jpg' || $fileExt == 'png' || $fileExt == 'gif') {
                                                 $filePath = PhocaDownloadPath::getPathSet('filepreview');
                                                 $filePath = str_replace('../', JURI::base(true) . '/', $filePath['orig_rel_ds']);
                                                 $previewLink = $filePath . $item->filename_preview;
                                                 //$previewWindow 	= $paramsC->get( 'preview_popup_window', 0 );
                                                 // PREVIEW - - - - - - - - - - - -
                                                 $windowWidthPr = (int) $previewwidth + 20;
                                                 $windowHeightPr = (int) $previewheight + 20;
                                                 if ($previewWindow == 1) {
                                                     $buttonPr = new JObject();
                                                     $buttonPr->set('methodname', 'js-button');
                                                     $buttonPr->set('options', "window.open(this.href,'win2','width=" . $windowWidthPr . ",height=" . $windowHeightPr . ",scrollbars=yes,menubar=no,resizable=yes'); return false;");
                                                 } else {
                                                     JHTML::_('behavior.modal', 'a.modal-button');
                                                     $document->addCustomTag("<style type=\"text/css\"> \n" . " #sbox-window.phocadownloadpreviewwindow   {background-color:#fff;padding:2px} \n" . " #sbox-overlay.phocadownloadpreviewoverlay  {background-color:#000;} \n" . " </style> \n");
                                                     $buttonPr = new JObject();
                                                     $buttonPr->set('name', 'image');
                                                     $buttonPr->set('modal', true);
                                                     $buttonPr->set('methodname', 'modal-button');
                                                     $buttonPr->set('options', "{handler: 'iframe', size: {x: " . $windowWidthPr . ", y: " . $windowHeightPr . "}, overlayOpacity: 0.7, classWindow: 'phocadownloadpreviewwindow', classOverlay: 'phocadownloadpreviewoverlay'}");
                                                     $buttonPr->set('optionsimg', "{handler: 'image', size: {x: 200, y: 150}, overlayOpacity: 0.7, classWindow: 'phocadownloadpreviewwindow', classOverlay: 'phocadownloadpreviewoverlay'}");
                                                 }
                                                 // - - - - - - - - - - - - - - -
                                                 /*if ($text == '') {
                                                 			$text = JText::_('PLG_CONTENT_PHOCADOWNLOAD_PREVIEW');
                                                 		}*/
                                                 if ($text != '') {
                                                     $textOutput = $text;
                                                     //} else if (isset($item->title) && $item->title != '') {
                                                     //	$textOutput = $item->title;
                                                 } else {
                                                     $textOutput = JText::_('PLG_CONTENT_PHOCADOWNLOAD_PREVIEW');
                                                 }
                                                 if ($iMime == 1) {
                                                     $output .= '<div class="pd-filename phocadownloadfile phoca-dl-file-box-mod">' . $imageFileName['filenamethumb'] . '<div class="pd-document' . (int) $iSize . '" ' . $imageFileName['filenamestyle'] . '>';
                                                 } else {
                                                     $output .= '<div><div class="phocadownloadpreview' . (int) $iSize . '">';
                                                 }
                                                 if ($previewWindow == 1) {
                                                     $output .= '<a  href="' . $previewLink . '" onclick="' . $buttonPr->options . '" >' . $text . '</a>';
                                                 } else {
                                                     if ($fileExt == 'pdf') {
                                                         // Iframe - modal
                                                         $output .= '<a class="modal-button" href="' . $previewLink . '" rel="' . $buttonPr->options . '" >' . $textOutput . '</a>';
                                                     } else {
                                                         // Image - modal
                                                         $output .= '<a class="modal-button" href="' . $previewLink . '" rel="' . $buttonPr->optionsimg . '" >' . $textOutput . '</a>';
                                                     }
                                                 }
                                                 $output .= '</div></div>';
                                             }
                                         } else {
                                             $output .= JText::_('PLG_CONTENT_PHOCADOWNLOAD_NO_FILE_FOR_PREVIEWING_FOUND');
                                         }
                                     } else {
                                         if (isset($item->confirm_license) && $item->confirm_license > 0 || $fileView == 1) {
                                             $link = PhocaDownloadRoute::getFileRoute($item->id, $item->catid, $item->alias, $item->catalias, 0, 'file');
                                             //'index.php?option=com_phocadownload&view=file&id='.$item->slug.'&Itemid='.$itemId
                                             if ($iMime == 1) {
                                                 $output .= '<div class="pd-filename phocadownloadfile phoca-dl-file-box-mod">' . $imageFileName['filenamethumb'] . '<div class="pd-document' . (int) $iSize . '" ' . $imageFileName['filenamestyle'] . '><a href="' . JRoute::_($link) . '" ' . $targetOutput . '>' . $textOutput . '</a></div></div>';
                                             } else {
                                                 $output .= '<div class="phocadownloadfile' . (int) $iSize . '"><a href="' . JRoute::_($link) . '" ' . $targetOutput . '>' . $textOutput . '</a></div>';
                                             }
                                         } else {
                                             if ($item->link_external != '') {
                                                 $link = $item->link_external;
                                             } else {
                                                 $link = PhocaDownloadRoute::getFileRoute($item->id, $item->catid, $item->alias, $item->catalias, 0, 'download');
                                             }
                                             //$link = PhocaDownloadRoute::getCategoryRoute($item->catid,$item->catalias,$item->sectionid);
                                             //'index.php?option=com_phocadownload&view=category&id='. $item->catslug. '&download='. $item->slug. '&Itemid=' . $itemId
                                             if ($iMime == 1) {
                                                 $output .= '<div class="pd-filename phocadownloadfile phoca-dl-file-box-mod">' . $imageFileName['filenamethumb'] . '<div class="pd-document' . (int) $iSize . '" ' . $imageFileName['filenamestyle'] . '><a href="' . JRoute::_($link) . '" ' . $targetOutput . '>' . $textOutput . '</a></div></div>';
                                             } else {
                                                 $output .= '<div class="phocadownloadfile' . (int) $iSize . '"><a href="' . JRoute::_($link) . '" ' . $targetOutput . '>' . $textOutput . '</a></div>';
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     break;
                     // - - - - - - - - - - - - - - - -
                     // YOUTUBE
                     // - - - - - - - - - - - - - - - -
                 // - - - - - - - - - - - - - - - -
                 // YOUTUBE
                 // - - - - - - - - - - - - - - - -
                 case 'youtube':
                     if ($url != '' && PhocaDownloadUtils::isURLAddress($url)) {
                         $l = new PhocaDownloadLayout();
                         $pdVideo = $l->displayVideo($url, 0, $youtubewidth, $youtubeheight);
                         $output .= $pdVideo;
                     } else {
                         $output .= JText::_('PLG_CONTENT_PHOCADOWNLOAD_WRONG_YOUTUBE_URL');
                     }
                     break;
             }
             $article->text = preg_replace($regex_all, $output, $article->text, 1);
         }
     }
     // end if count_matches
     return true;
 }
Ejemplo n.º 11
0
	public static function canPreview( $fileName ) {
		$fileExt 	= PhocaDownloadFile::getExtension($fileName);
		
		switch($fileExt) {
			case 'pdf':
			case 'jpeg':
			case 'jpg':
			case 'png':
			case 'gif': 
				return true;
			break;
			
			default:
				return false;
			break;
		
		}
		return false;
	}
Ejemplo n.º 12
0
	function _save($data, $filename, &$errSaveMsg, $fileExists = 0) {
	
		$user 	= JFactory::getUser();
		$fileId = false;
		if ($fileExists == 1) {
			// We not only owerwrite the file but we must update it
			if (isset($filename) && $filename != '') {
				
				$db = JFactory::getDBO();
				
				$query = 'SELECT a.id AS id'
				.' FROM #__phocadownload AS a'
			    .' WHERE a.filename = '.$db->Quote($filename);

				$db->setQuery($query, 0, 1);
				$fileId = $db->loadObject();
				
				if (!$db->query()) {
					$this->setError($db->getErrorMsg());
					return false;
				}
			}
		}

		$row = $this->getTable('phocadownload');
		
		if (isset($fileId->id) && (int)$fileId->id > 0) {
			$data['id'] = (int)$fileId->id;
		}
		
	

		$data['filesize'] 	= PhocaDownloadFile::getFileSize($filename, 0);
		
		$data['userid']			= $user->id;
		$data['author_email']	= $data['email'];
		$data['author_url']		= $data['website'];
		
		$data['token']			= PhocaDownloadUtils::getToken($data['title'].$filename);
		//$data['token']			= PhocaDownloadUtils::getToken($data['title'].$data['filename']);
		
		// Bind the form fields to the Phoca gallery table
		if (!$row->bind($data)) {
			$this->setError($this->_db->getErrorMsg());
			return false;
		}
		
		

		// Create the timestamp for the date
		//$row->date 			= gmdate('Y-m-d H:i:s');
		//$row->publish_up	= gmdate('Y-m-d H:i:s');
		//$jnow		=JFactory::getDate();
		/*$jnowU		= $jnow->toUnix();
		if (isset($jnowU)) {
			$jnowU = (int)$jnowU - 2; // to not display pending because of 1 second
		}*/
		
		$unow		= time();
		$unow		= $unow - 2;//Frontend will display pending if standard $jnow->toSql(); will be used
		$jnow		= JFactory::getDate($unow);// the class JDate construct works with unix date
		$now		= $jnow->toSql();
		
		$row->date 			= $now;
		$row->publish_up	= $now; //date('Y-m-d H:i:s', $jnowU);
		$row->publish_down	= null;
		$row->filename	= $filename;
		$row->catid		= $data['catidfiles'];
		
		// Lang
		$userLang			= PhocaDownloadUser::getUserLang();
		$row->language		= $userLang['lang'];


		// if new item, order last in appropriate group
		if (!$row->id) {
			$where = 'catid = ' . (int) $row->catid ;
			$row->ordering = $row->getNextOrder( $where );
		}

		// Make sure the Phoca gallery table is valid
		if (!$row->check()) {
			$this->setError($this->_db->getErrorMsg());
			return false;
		}

		// Store the Phoca gallery table to the database
		if (!$row->store()) {
			$this->setError($this->_db->getErrorMsg());
			return false;
		}
		
		PhocaDownloadLog::log($row->id, 2);
		
		return true;
	}
Ejemplo n.º 13
0
 public function display($tpl = null)
 {
     $this->t = PhocaDownloadUtils::setVars('manager');
     $this->field = JRequest::getVar('field');
     $this->fce = 'phocaSelectFileName_' . $this->field;
     JHTML::stylesheet($this->t['s']);
     $this->folderstate = $this->get('FolderState');
     $this->files = $this->get('Files');
     $this->folders = $this->get('Folders');
     $this->session = JFactory::getSession();
     $this->manager = JRequest::getVar('manager', '', '', 'file');
     if ($this->manager == 'filemultiple') {
         $this->form = $this->get('Form');
     }
     $params = JComponentHelper::getParams($this->t['o']);
     $this->t['multipleuploadchunk'] = $params->get('multiple_upload_chunk', 0);
     $this->t['uploadmaxsize'] = $params->get('upload_maxsize', 3145728);
     $this->t['uploadmaxsizeread'] = PhocaDownloadFile::getFileSizeReadable($this->t['uploadmaxsize']);
     $this->t['enablemultiple'] = $params->get('enable_multiple_upload_admin', 0);
     $this->t['multipleuploadmethod'] = $params->get('multiple_upload_method', 1);
     $this->currentFolder = '';
     if (isset($this->folderstate->folder) && $this->folderstate->folder != '') {
         $this->currentFolder = $this->folderstate->folder;
     }
     // - - - - - - - - - -
     //TABS
     // - - - - - - - - - -
     $this->t['tab'] = JRequest::getVar('tab', '', '', 'string');
     $this->t['displaytabs'] = 0;
     // UPLOAD
     $this->t['currenttab']['upload'] = $this->t['displaytabs'];
     $this->t['displaytabs']++;
     // MULTIPLE UPLOAD
     if ((int) $this->t['enablemultiple'] >= 0) {
         $this->t['currenttab']['multipleupload'] = $this->t['displaytabs'];
         $this->t['displaytabs']++;
     }
     $group = PhocaDownloadSettings::getManagerGroup($this->manager);
     // - - - - - - - - - - -
     // Upload
     // - - - - - - - - - - -
     $sU = new PhocaDownloadFileUploadSingle();
     $sU->returnUrl = 'index.php?option=com_phocadownload&view=phocadownloadmanager&tab=upload' . str_replace('&amp;', '&', $group['c']) . '&manager=' . $this->manager . '&field=' . $this->field . '&folder=' . $this->currentFolder;
     $sU->tab = 'upload';
     $this->t['su_output'] = $sU->getSingleUploadHTML();
     $this->t['su_url'] = JURI::base() . 'index.php?option=com_phocadownload&task=phocadownloadupload.upload&amp;' . $this->session->getName() . '=' . $this->session->getId() . '&amp;' . JSession::getFormToken() . '=1&amp;viewback=phocadownloadmanager&amp;manager=' . $this->manager . '&amp;field=' . $this->field . '&amp;' . 'folder=' . $this->currentFolder . '&amp;tab=upload';
     // - - - - - - - - - - -
     // Multiple Upload
     // - - - - - - - - - - -
     // Get infos from multiple upload
     $muFailed = JRequest::getVar('mufailed', '0', '', 'int');
     $muUploaded = JRequest::getVar('muuploaded', '0', '', 'int');
     $this->t['mu_response_msg'] = $muUploadedMsg = '';
     if ($muUploaded > 0) {
         $muUploadedMsg = JText::_('COM_PHOCADOWNLOAD_COUNT_UPLOADED_FILE') . ': ' . $muUploaded;
     }
     if ($muFailed > 0) {
         $muFailedMsg = JText::_('COM_PHOCADOWNLOAD_COUNT_NOT_UPLOADED_FILE') . ': ' . $muFailed;
     }
     if ($muFailed > 0 && $muUploaded > 0) {
         $this->t['mu_response_msg'] = '<div class="alert alert-info">' . '<button type="button" class="close" data-dismiss="alert">&times;</button>' . JText::_('COM_PHOCADOWNLOAD_COUNT_UPLOADED_FILE') . ': ' . $muUploaded . '<br />' . JText::_('COM_PHOCADOWNLOAD_COUNT_NOT_UPLOADED_FILE') . ': ' . $muFailed . '</div>';
     } else {
         if ($muFailed > 0 && $muUploaded == 0) {
             $this->t['mu_response_msg'] = '<div class="alert alert-error">' . '<button type="button" class="close" data-dismiss="alert">&times;</button>' . JText::_('COM_PHOCADOWNLOAD_COUNT_NOT_UPLOADED_FILE') . ': ' . $muFailed . '</div>';
         } else {
             if ($muFailed == 0 && $muUploaded > 0) {
                 $this->t['mu_response_msg'] = '<div class="alert alert-success">' . '<button type="button" class="close" data-dismiss="alert">&times;</button>' . JText::_('COM_PHOCADOWNLOAD_COUNT_UPLOADED_FILE') . ': ' . $muUploaded . '</div>';
             } else {
                 $this->t['mu_response_msg'] = '';
             }
         }
     }
     if ((int) $this->t['enablemultiple'] >= 0) {
         PhocadownloadFileUploadMultiple::renderMultipleUploadLibraries();
         $mU = new PhocaDownloadFileUploadMultiple();
         $mU->frontEnd = 0;
         $mU->method = $this->t['multipleuploadmethod'];
         $mU->url = JURI::base() . 'index.php?option=com_phocadownload&task=phocadownloadupload.multipleupload&amp;' . $this->session->getName() . '=' . $this->session->getId() . '&' . JSession::getFormToken() . '=1&tab=multipleupload&manager=' . $this->manager . '&field=' . $this->field . '&folder=' . $this->currentFolder;
         $mU->reload = JURI::base() . 'index.php?option=com_phocadownload&view=phocadownloadmanager' . str_replace('&amp;', '&', $group['c']) . '&' . $this->session->getName() . '=' . $this->session->getId() . '&' . JSession::getFormToken() . '=1&tab=multipleupload&' . 'manager=' . $this->manager . '&field=' . $this->field . '&folder=' . $this->currentFolder;
         $mU->maxFileSize = PhocadownloadFileUploadMultiple::getMultipleUploadSizeFormat($this->t['uploadmaxsize']);
         $mU->chunkSize = '1mb';
         $mU->renderMultipleUploadJS(0, $this->t['multipleuploadchunk']);
         $this->t['mu_output'] = $mU->getMultipleUploadHTML();
     }
     $this->t['ftp'] = !JClientHelper::hasCredentials('ftp');
     $this->t['path'] = PhocaDownloadPath::getPathSet($this->manager);
     $this->addToolbar();
     parent::display($tpl);
     echo JHTML::_('behavior.keepalive');
 }
Ejemplo n.º 14
0
<?php defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.filesystem.file' );

$ext 	= PhocaDownloadFile::getExtension( $this->_tmp_file->path_without_name_relative );
$group 	= PhocaDownloadSettings::getManagerGroup($this->manager);


if ($this->manager == 'filemultiple') {
	$checked 	= JHTML::_('grid.id', $this->filei + count($this->folders), $this->files[$this->filei]->path_with_name_relative_no );
	
	$icon		= PhocaDownloadFile::getMimeTypeIcon($this->_tmp_file->name);
	echo '<tr>'
	.' <td>'. $checked .'</td>'
	.' <td class="ph-img-table">'
	. $icon .'</a></td>'
	.' <td>' . $this->_tmp_file->name . '</td>'
	.'</tr>';
	
	
} else {
	if (($group['i'] == 1) && ($ext == 'png' || $ext == 'jpg' || $ext == 'gif' || $ext == 'jpeg') ) {
		
		echo '<tr>'
		.'<td></td>'
		.'<td>'
		.'<a href="#" onclick="if (window.parent) window.parent.'. $this->fce.'(\'' .$this->_tmp_file->path_with_name_relative_no.'\')">'
		. JHTML::_( 'image', str_replace( '../', '', $this->_tmp_file->path_without_name_relative), JText::_('COM_PHOCADOWNLOAD_INSERT'), array('title' => JText::_('COM_PHOCADOWNLOAD_INSERT_ICON')))
		.'</a>'
		.' <td>'
		.'<a href="#" onclick="if (window.parent) window.parent.'. $this->fce.'(\'' . $this->_tmp_file->path_with_name_relative_no.'\')">'
Ejemplo n.º 15
0
 protected function _copyPreviewAndPlay($filename, $storedfilename, $storedfoldername, $path, $overwriteExistingFiles)
 {
     $o['filename_play'] = '';
     $o['filename_preview'] = '';
     $canPlay = PhocaDownloadFile::canPlay($filename);
     $canPreview = PhocaDownloadFile::canPreview($filename);
     $filepathPAP = JPath::clean($path['orig_abs_pap_ds'] . $storedfilename);
     //$filepathUserFolderPAP 		= JPath::clean($path['orig_abs_pap_ds']. $storedfoldername);
     $filepath = JPath::clean($path['orig_abs_ds'] . $storedfilename);
     $filepathPAPFolder = JPath::clean($path['orig_abs_pap_ds'] . DS . PhocaDownloadFile::getFolderFromTheFile($storedfilename));
     if ($canPlay || $canPreview) {
         $uploadPAP = 1;
         // upload file for preview and play
         if (JFile::exists($filepathPAP) && $overwriteExistingFiles == 0) {
             //$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_FILE_ALREADY_EXISTS");
             //return false;
             $uploadPAP = 0;
             // don't upload if it exists, it is not main file, don't do false and exit
             if ($canPlay == 1) {
                 $o['filename_play'] = $storedfilename;
             } else {
                 if ($canPreview == 1) {
                     $o['filename_preview'] = $storedfilename;
                 }
             }
         }
         // Overwrite file and add no new item to database
         $fileExistsPAP = 0;
         if (JFile::exists($filepathPAP) && $overwriteExistingFiles == 1) {
             $fileExistsPAP = 1;
             if ($canPlay == 1) {
                 $o['filename_play'] = $storedfilename;
             } else {
                 if ($canPreview == 1) {
                     $o['filename_preview'] = $storedfilename;
                 }
             }
         }
         if ($uploadPAP == 0) {
         } else {
             // First create folder if not exists
             if (!JFolder::exists($filepathPAPFolder)) {
                 if (JFolder::create($filepathPAPFolder)) {
                     $data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>";
                     JFile::write($filepathPAPFolder . DS . "index.html", $data);
                 }
                 // else {
                 //$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_CREATE_FOLDER");
                 //return false;
                 //}
             }
             if (!JFile::copy($filepath, $filepathPAP)) {
                 //$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_UPLOAD_FILE");
                 //return false;
             } else {
                 // Saving file name into database with relative path
                 /*if (!JFile::exists($filepathUserFolderPAP . DS ."index.html")) {
                 			$data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>";
                 			JFile::write($filepathUserFolderPAP . DS ."index.html", $data);
                 		}*/
                 if ($canPlay == 1) {
                     //$image->filename_play		=  $storedfilename;
                     $o['filename_play'] = $storedfilename;
                 } else {
                     if ($canPreview == 1) {
                         //$image->filename_preview	=  $storedfilename;
                         $o['filename_preview'] = $storedfilename;
                     }
                 }
             }
         }
     }
     return $o;
 }
Ejemplo n.º 16
0
 function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $userLevels = implode(',', $user->getAuthorisedViewLevels());
     $db = JFactory::getDBO();
     $menu = $app->getMenu();
     $document = JFactory::getDocument();
     $params = $app->getParams();
     $moduleId = $app->input->get('id', 0, 'int');
     $table =& JTable::getInstance('module');
     if ((int) $moduleId > 0) {
         $db = JFactory::getDBO();
         $query = 'SELECT a.params' . ' FROM #__modules AS a' . ' WHERE a.published = 1' . ' AND a.id =' . (int) $moduleId . ' ORDER BY a.ordering';
         $db->setQuery($query);
         if (!$db->query()) {
             $this->setError($db->getErrorMsg());
             return false;
         }
         $module = $db->loadObject();
         if (isset($module->params) && $module->params != '') {
             jimport('joomla.html.parameter');
             $paramsM = new JRegistry();
             $paramsM->loadString($module->params);
             //$paramsM->loadJSON($module->params);
             // Params
             $categories = $paramsM->get('category_ids', '');
             $ordering = $paramsM->get('file_ordering', 6);
             $fileCount = $paramsM->get('file_count', 5);
             $feedTitle = $paramsM->get('feed_title', JText::_('COM_PHOCADOWNLOAD_DOWNLOAD'));
             $displayDateType = $paramsM->get('display_date_type', 1);
             $document->setTitle($this->escape(html_entity_decode($feedTitle)));
             $wheres = array();
             if (is_array($categories) && count($categories) > 0) {
                 JArrayHelper::toInteger($categories);
                 $categoriesString = implode(',', $categories);
                 $wheres[] = ' c.catid IN ( ' . $categoriesString . ' ) ';
             } else {
                 if ((int) $categories > 0) {
                     $wheres[] = ' c.catid IN ( ' . $categories . ' ) ';
                 }
             }
             $wheres[] = ' c.catid= cc.id';
             $wheres[] = '( (unaccessible_file = 1 ) OR (unaccessible_file = 0 AND c.access IN (' . $userLevels . ') ) )';
             $wheres[] = '( (unaccessible_file = 1 ) OR (unaccessible_file = 0 AND cc.access IN (' . $userLevels . ') ) )';
             $wheres[] = ' c.published = 1';
             $wheres[] = ' c.approved = 1';
             $wheres[] = ' cc.published = 1';
             $wheres[] = ' c.textonly = 0';
             // Active
             $jnow = JFactory::getDate();
             $now = $jnow->toSql();
             $nullDate = $db->getNullDate();
             $wheres[] = ' ( c.publish_up = ' . $db->Quote($nullDate) . ' OR c.publish_up <= ' . $db->Quote($now) . ' )';
             $wheres[] = ' ( c.publish_down = ' . $db->Quote($nullDate) . ' OR c.publish_down >= ' . $db->Quote($now) . ' )';
             $fileOrdering = PhocaDownloadOrdering::getOrderingText($ordering);
             $query = ' SELECT c.*, cc.id AS categoryid, cc.title AS categorytitle, cc.alias AS categoryalias, cc.access as cataccess, cc.accessuserid as cataccessuserid ' . ' FROM #__phocadownload AS c' . ' LEFT JOIN #__phocadownload_categories AS cc ON cc.id = c.catid' . ' WHERE ' . implode(' AND ', $wheres) . ' ORDER BY c.' . $fileOrdering;
             $db->setQuery($query, 0, $fileCount);
             $files = $db->loadObjectList();
             foreach ($files as $keyDoc => $valueDoc) {
                 // USER RIGHT - Access of categories (if file is included in some not accessed category) - - - - -
                 // ACCESS is handled in SQL query, ACCESS USER ID is handled here (specific users)
                 $rightDisplay = 0;
                 if (!empty($valueDoc)) {
                     $rightDisplay = PhocaDownloadAccess::getUserRight('accessuserid', $valueDoc->cataccessuserid, $valueDoc->cataccess, $user->getAuthorisedViewLevels(), $user->get('id', 0), 0);
                 }
                 // - - - - - - - - - - - - - - - - - - - - - -
                 if ($rightDisplay == 1) {
                     $item = new JFeedItem();
                     $title = $this->escape($valueDoc->title . ' (' . PhocaDownloadFile::getTitleFromFilenameWithExt($valueDoc->filename) . ')');
                     $title = html_entity_decode($title);
                     $item->title = $title;
                     $link = PhocaDownloadRoute::getCategoryRoute($valueDoc->categoryid, $valueDoc->categoryalias);
                     $item->link = JRoute::_($link);
                     // FILEDATE
                     $fileDate = '';
                     if ((int) $displayDateType > 0) {
                         if ($valueDoc->filename != '') {
                             $fileDate = PhocaDownloadFile::getFileTime($valueDoc->filename, $displayDateType, "Y-m-d H:M:S");
                         }
                     } else {
                         $fileDate = JHTML::Date($valueDoc->date, "Y-m-d H:i:s");
                     }
                     if ($fileDate != '') {
                         $item->date = $fileDate;
                     }
                     //$item->description 	= $valueDoc->description;
                     //	$item->description 	= '<div><img src="media/com_phocadownload/images/phoca-download.png" alt="" /></div><div>New file "' .$valueDoc->title . '" ('. $valueDoc->filename.') released on '. $dateDesc.' is available on <a href="http://www.phoca.cz/download">Phoca download site</a></div>'.$valueDoc->description;
                     $item->description = '<div><img src="media/com_phocadownload/images/phoca-download.png" alt="" /></div>' . $valueDoc->description;
                     $item->category = $valueDoc->categorytitle;
                     //	$item->section   	= $valueDoc->sectiontitle;
                     if ($valueDoc->author != '') {
                         $item->author = $valueDoc->author;
                     }
                     $document->addItem($item);
                 }
             }
         }
     }
 }
Ejemplo n.º 17
0
 public static function download($fileData, $downloadId, $currentLink, $type = 0)
 {
     $app = JFactory::getApplication();
     $params = $app->getParams();
     $directLink = $fileData['directlink'];
     // Direct Link 0 or 1
     $externalLink = $fileData['externallink'];
     $absOrRelFile = $fileData['file'];
     // Relative Path or Absolute Path
     // Type = 1 - Token - unique download link - cannot be direct
     if ($type == 1) {
         $directLink = 0;
     }
     // NO FILES FOUND (abs file)
     $error = false;
     $error = preg_match("/COM_PHOCADOWNLOAD_ERROR/i", $absOrRelFile);
     if ($error) {
         $msg = JText::_('COM_PHOCADOWNLOAD_ERROR_WHILE_DOWNLOADING_FILE') . ' ' . JText::_($absOrRelFile);
         $app->redirect(JRoute::_($currentLink), $msg);
     } else {
         // Get extensions
         $extension = JFile::getExt(strtolower($absOrRelFile));
         $aft = $params->get('allowed_file_types_download', PhocaDownloadSettings::getDefaultAllowedMimeTypesDownload());
         $dft = $params->get('disallowed_file_types_download', '');
         // Get Mime from params ( ext --> mime)
         $allowedMimeType = PhocaDownloadFile::getMimeType($extension, $aft);
         $disallowedMimeType = PhocaDownloadFile::getMimeType($extension, $dft);
         // NO MIME FOUND
         $errorAllowed = false;
         // !!! IF YES - Disallow Downloading
         $errorDisallowed = false;
         // !!! IF YES - Allow Downloading
         $errorAllowed = preg_match("/PhocaError/i", $allowedMimeType);
         $errorDisallowed = preg_match("/PhocaError/i", $disallowedMimeType);
         $ignoreDownloadCheck = $params->get('ignore_file_types_check', 2);
         if ($ignoreDownloadCheck == 3 || $ignoreDownloadCheck == 4 || $ignoreDownloadCheck == 5) {
             $errorAllowed = false;
             $errorDisallowed = true;
         }
         if ($errorAllowed) {
             $msg = JText::_('COM_PHOCADOWNLOAD_WARNFILETYPE_DOWNLOAD');
             $app->redirect(JRoute::_($currentLink), $msg);
         } else {
             if (!$errorDisallowed) {
                 $msg = JText::_('COM_PHOCADOWNLOAD_WARNFILETYPE_DISALLOWED_DOWNLOAD');
                 $app->redirect(JRoute::_($currentLink), $msg);
             } else {
                 if ($directLink == 1) {
                     // Direct Link on the same server
                     $fileWithoutPath = basename($absOrRelFile);
                     $addHit = self::hit($downloadId);
                     if ($type == 1) {
                         self::hitToken($downloadId);
                     }
                     if ((int) $params->get('send_mail_download', 0) > 0) {
                         PhocaDownloadMail::sendMail((int) $params->get('send_mail_download', 0), $fileWithoutPath, 1);
                     }
                     // USER Statistics
                     if ((int) $params->get('enable_user_statistics', 1) == 1) {
                         $addUserStat = PhocaDownloadStat::createUserStatEntry($downloadId);
                     }
                     PhocaDownloadLog::log($downloadId, 1);
                     $app->redirect($absOrRelFile);
                     exit;
                 } else {
                     if ($directLink == 0 && $externalLink != '') {
                         // External Link but with redirect
                         // In case there is directLink the external Link does not go this way but directly to the external URL
                         $addHit = self::hit($downloadId);
                         if ($type == 1) {
                             self::hitToken($downloadId);
                         }
                         if ((int) $params->get('send_mail_download', 0) > 0) {
                             PhocaDownloadMail::sendMail((int) $params->get('send_mail_download', 0), $externalLink, 1);
                         }
                         // USER Statistics
                         if ((int) $params->get('enable_user_statistics', 1) == 1) {
                             $addUserStat = PhocaDownloadStat::createUserStatEntry($downloadId);
                         }
                         PhocaDownloadLog::log($downloadId, 1);
                         $app->redirect($externalLink);
                         exit;
                     } else {
                         // Clears file status cache
                         clearstatcache();
                         $fileWithoutPath = basename($absOrRelFile);
                         $fileSize = filesize($absOrRelFile);
                         $mimeType = '';
                         $mimeType = $allowedMimeType;
                         // HIT Statistics
                         $addHit = self::hit($downloadId);
                         if ($type == 1) {
                             self::hitToken($downloadId);
                         }
                         if ((int) $params->get('send_mail_download', 0) > 0) {
                             PhocaDownloadMail::sendMail((int) $params->get('send_mail_download', 0), $fileWithoutPath, 1);
                         }
                         // USER Statistics
                         if ((int) $params->get('enable_user_statistics', 1) == 1) {
                             $addUserStat = PhocaDownloadStat::createUserStatEntry($downloadId);
                         }
                         PhocaDownloadLog::log($downloadId, 1);
                         if ($fileSize == 0) {
                             die(JText::_('COM_PHOCADOWNLOAD_FILE_SIZE_EMPTY'));
                             exit;
                         }
                         // Clean the output buffer
                         ob_end_clean();
                         // test for protocol and set the appropriate headers
                         jimport('joomla.environment.uri');
                         $_tmp_uri = JURI::getInstance(JURI::current());
                         $_tmp_protocol = $_tmp_uri->getScheme();
                         if ($_tmp_protocol == "https") {
                             // SSL Support
                             header('Cache-Control: private, max-age=0, must-revalidate, no-store');
                         } else {
                             header("Cache-Control: public, must-revalidate");
                             header('Cache-Control: pre-check=0, post-check=0, max-age=0');
                             header("Pragma: no-cache");
                             header("Expires: 0");
                         }
                         /* end if protocol https */
                         header("Content-Description: File Transfer");
                         header("Expires: Sat, 30 Dec 1990 07:07:07 GMT");
                         header("Accept-Ranges: bytes");
                         // HTTP Range
                         /*	$httpRange = 0;
                         			if(isset($_SERVER['HTTP_RANGE'])) {
                         				list($a, $httpRange) = explode('=', $_SERVER['HTTP_RANGE']);
                         				str_replace($httpRange, '-', $httpRange);
                         				$newFileSize	= $fileSize - 1;
                         				$newFileSizeHR	= $fileSize - $httpRange;
                         				header("HTTP/1.1 206 Partial Content");
                         				header("Content-Length: ".(string)$newFileSizeHR);
                         				header("Content-Range: bytes ".$httpRange . $newFileSize .'/'. $fileSize);
                         			} else {
                         				$newFileSize	= $fileSize - 1;
                         				header("Content-Length: ".(string)$fileSize);
                         				header("Content-Range: bytes 0-".$newFileSize . '/'.$fileSize);
                         			}
                         			header("Content-Type: " . (string)$mimeType);
                         			header('Content-Disposition: attachment; filename="'.$fileWithoutPath.'"');
                         			header("Content-Transfer-Encoding: binary\n");*/
                         // Modified by Rene
                         // HTTP Range - see RFC2616 for more informations (http://www.ietf.org/rfc/rfc2616.txt)
                         $httpRange = 0;
                         $newFileSize = $fileSize - 1;
                         // Default values! Will be overridden if a valid range header field was detected!
                         $resultLenght = (string) $fileSize;
                         $resultRange = "0-" . $newFileSize;
                         // We support requests for a single range only.
                         // So we check if we have a range field. If yes ensure that it is a valid one.
                         // If it is not valid we ignore it and sending the whole file.
                         if (isset($_SERVER['HTTP_RANGE']) && preg_match('%^bytes=\\d*\\-\\d*$%', $_SERVER['HTTP_RANGE'])) {
                             // Let's take the right side
                             list($a, $httpRange) = explode('=', $_SERVER['HTTP_RANGE']);
                             // and get the two values (as strings!)
                             $httpRange = explode('-', $httpRange);
                             // Check if we have values! If not we have nothing to do!
                             if (!empty($httpRange[0]) || !empty($httpRange[1])) {
                                 // We need the new content length ...
                                 $resultLenght = $fileSize - $httpRange[0] - $httpRange[1];
                                 // ... and we can add the 206 Status.
                                 header("HTTP/1.1 206 Partial Content");
                                 // Now we need the content-range, so we have to build it depending on the given range!
                                 // ex.: -500 -> the last 500 bytes
                                 if (empty($httpRange[0])) {
                                     $resultRange = $resultLenght . '-' . $newFileSize;
                                 } elseif (empty($httpRange[1])) {
                                     $resultRange = $httpRange[0] . '-' . $newFileSize;
                                 } else {
                                     $resultRange = $httpRange[0] . '-' . $httpRange[1];
                                 }
                                 //header("Content-Range: bytes ".$httpRange . $newFileSize .'/'. $fileSize);
                             }
                         }
                         header("Content-Length: " . $resultLenght);
                         header("Content-Range: bytes " . $resultRange . '/' . $fileSize);
                         header("Content-Type: " . (string) $mimeType);
                         header('Content-Disposition: attachment; filename="' . $fileWithoutPath . '"');
                         header("Content-Transfer-Encoding: binary\n");
                         // TEST TEMP SOLUTION
                         ob_end_clean();
                         //@readfile($absOrRelFile);
                         // Try to deliver in chunks
                         @set_time_limit(0);
                         $fp = @fopen($absOrRelFile, 'rb');
                         if ($fp !== false) {
                             while (!feof($fp)) {
                                 echo fread($fp, 8192);
                             }
                             fclose($fp);
                         } else {
                             @readfile($absOrRelFile);
                         }
                         flush();
                         exit;
                         /*
                         http://www.phoca.cz/forum/viewtopic.php?f=31&t=11811
                         
                         $fp = @fopen($absOrRelFile, 'rb');
                         // HTTP Range - see RFC2616 for more informations (http://www.ietf.org/rfc/rfc2616.txt)
                         $newFileSize = $fileSize - 1;
                         // Default values! Will be overridden if a valid range header field was detected!
                         $rangeStart = 0;
                         $rangeEnd = 0;
                         $resultLength = $fileSize;
                         // We support requests for a single range only.
                         // So we check if we have a range field. If yes ensure that it is a valid one.
                         // If it is not valid we ignore it and sending the whole file.
                         if ($fp && isset($_SERVER['HTTP_RANGE']) && preg_match('%^bytes=\d*\-\d*$%', $_SERVER['HTTP_RANGE'])) {
                         	// Let's take the right side
                         	list($a, $httpRange) = explode('=', $_SERVER['HTTP_RANGE']);
                         	// and get the two values (as strings!)
                         	$httpRange = explode('-', $httpRange);
                         	// Check if we have values! If not we have nothing to do!
                         	if (sizeof($httpRange) == 2) {
                         		// Explictly convert to int
                         		$rangeStart = intval($httpRange[0]);
                         		$rangeEnd = intval($httpRange[1]); // Allowed to be empty == 0
                         		if (($rangeStart || $rangeEnd) // something actually set?
                         		&& $rangeStart < $fileSize // must be smaller
                         		&& $rangeEnd < $fileSize // must be smaller
                         		&& (!$rangeEnd || $rangeEnd > $rangeStart) // end > start, if end is set
                         		) {
                         			header("HTTP/1.1 206 Partial Content");
                         			if (!$rangeEnd) {
                         				$resultLength = $fileSize - $rangeStart;
                         				$range = $rangeStart . "-" . ($fileSize - 1) . "/" . $fileSize;
                         			} else {
                         				$resultLength = ($rangeEnd - $rangeStart 1);
                         				$range = $rangeStart . "-" . $rangeEnd . "/" . $fileSize;
                         			}
                         			header("Content-Range: bytes " . $range);
                         		} else {
                         			// Didn't validate: kill
                         			$rangeStart = 0;
                         			$rangeEnd = 0;
                         		}
                         	}
                         }
                         
                         header("Content-Length: ". $resultLength);
                         header("Content-Type: " . (string)$mimeType);
                         header('Content-Disposition: attachment; filename="'.$fileWithoutPath.'"');
                         header("Content-Transfer-Encoding: binary\n");
                         @@ -211,13 +198,25 @@ class PhocaDownloadAccessFront
                         
                         // Try to deliver in chunks
                         @set_time_limit(0);
                         if ($fp !== false) {
                         	if ($rangeStart) {
                         		// Need to pass only part of the file, starting at $rangeStart
                         		fseek($fp, $rangeStart, SEEK_SET);
                         	}
                         	// If $rangeEnd is open ended (0, whole file from $rangeStart) try fpassthru,
                         	// else send in small chunks
                         	if ($rangeEnd || @!fpassthru($fp)) {
                         		while ($resultLength > 0 && !feof($fp)) {
                         			// 4 * 1460 (default MSS with ethernet 1500 MTU)
                         			// This is optimized for network packets, not disk access
                         			$bytes = min(5840, $resultLength);
                         			echo fread($fp, $bytes);
                         			$resultLength = $resultLength - $bytes;
                         		}
                         	}
                         	fclose($fp);
                         } else {
                         	// Ranges are disabled at this point and were never set up
                         	@readfile($absOrRelFile);
                         }
                         flush();
                         exit;
                         */
                     }
                 }
             }
         }
     }
     return false;
 }
Ejemplo n.º 18
0
echo $r->td(JHtml::_('grid.id', $i, $item->id), "small hidden-phone");

					
$checkO = '';
if ($item->checked_out) {
	$checkO .= JHtml::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, $this->t['tasks'].'.', $canCheckin);
}
if ($canCreate || $canEdit) {
	$checkO .= '<a href="'. JRoute::_($linkEdit).'">'. $this->escape($item->title).'</a>';
} else {
	$checkO .= $this->escape($item->title);
}

echo $r->td($checkO, "small hidden-phone");

$filename 	= PhocaDownloadFile::existsCss($item->filename, $item->type);
$main		= '';
if ((int)$item->type == 1) {
	$main = ' <span class="label label-warning">'.JText::_($this->t['l'].'_MAIN').'</span>';
}
if ($filename) {
	echo $r->td($item->filename . $main .' <span class="label label-success">'.JText::_($this->t['l'].'_FILE_EXISTS').'</span>', "small hidden-phone");
} else {
	echo $r->td($item->filename  . $main .' <span class="label label-important">'.JText::_($this->t['l'].'_FILE_DOES_NOT_EXIST').'</span>', "small hidden-phone");
}

echo $r->td(JHtml::_('jgrid.published', $item->published, $i, $this->t['tasks'].'.', $canChange), "small hidden-phone");

switch($item->type) {
	case 2:
		echo $r->td(JText::_($this->t['l'].'_CUSTOM_CSS'), "small hidden-phone");	
Ejemplo n.º 19
0
	function save($data) {
			
		//$data['filesize'] 	= PhocaDownloadUtils::getFileSize($data['filename'], 0);
		
		if ($data['alias'] == '') {
			$data['alias'] = $data['title'];
		}

		//$data['alias'] = PhocaDownloadText::get AliasName($data['alias']);

		
		// Initialise variables;
		$dispatcher = JDispatcher::getInstance();
		$table		= $this->getTable();
		$pk			= (!empty($data['id'])) ? $data['id'] : (int)$this->getState($this->getName().'.id');
		$isNew		= true;

		// Include the content plugins for the on save events.
		JPluginHelper::importPlugin('content');

		// Load the row if saving an existing record.
		if ($pk > 0) {
			$table->load($pk);
			$isNew = false;
		}
		
		// =================================================
		// Make a copy for play and preview
		$paramsC 	= JComponentHelper::getParams('com_phocadownload') ;
		$papCopy 	= $paramsC->get( 'pap_copy', 0 );
		$overwriteExistingFiles = $paramsC->get( 'overwrite_existing_files', 0 );
		$path		= PhocaDownloadPath::getPathSet();
		
		
		if ($papCopy == 2 || $papCopy == 3) {
			$canPlay			= PhocaDownloadFile::canPlay($data['filename']);
			$canPreview 		= PhocaDownloadFile::canPreview($data['filename']);
			$filepath			= JPath::clean($path['orig_abs_ds'] . DS.$data['filename']);
			$filepathPAP 		= JPath::clean($path['orig_abs_pap_ds'] . DS.$data['filename']);
			$filepathPAPFolder	= JPath::clean($path['orig_abs_pap_ds'] . DS. PhocaDownloadFile::getFolderFromTheFile($data['filename']));
			
			if ($canPlay || $canPreview) {
				
				$uploadPAP = 1;// upload file for preview and play
				if (JFile::exists($filepathPAP) && $overwriteExistingFiles == 0) {
					//$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_FILE_ALREADY_EXISTS");
					//return false;
					$uploadPAP = 0; // don't upload if it exists, it is not main file, don't do false and exit
					
					if ($canPlay == 1) {
						// set new file only no other is set
						if ($data['filename_play'] != '') {
							$uploadPAP = 0;
						} else {
							$data['filename_play']		=  $data['filename'];
						}
					} else if ($canPreview == 1) {
						// set new file only no other is set
						if ($data['filename_preview'] != '') {
							$uploadPAP = 0;
						} else {
							$data['filename_preview']	=  $data['filename'];
						}
					}
				}
				
				
				// Overwrite file and add no new item to database
				$fileExistsPAP = 0;
				if (JFile::exists($filepathPAP) && $overwriteExistingFiles == 1) {
					$fileExistsPAP = 1;
					
					if ($canPlay == 1) {
						// set new file only no other is set or it is the same like currect - to overwrite updated version of the same file
						if ($data['filename_play'] == '' || $data['filename_play'] == $data['filename']) {
							$data['filename_play']		=  $data['filename'];
						} else {
							$uploadPAP = 0;
						}
					} else if ($canPreview == 1) {
						// set new file only no other is set or it is the same like currect - to overwrite updated version of the same file
						if ($data['filename_preview'] == '' || $data['filename_preview'] == $data['filename']) {
							$data['filename_preview']	=  $data['filename'];
						} else {
							$uploadPAP = 0;
						}
					}
				}
				
				if ($uploadPAP == 0) {
				
				} else {
					if (!JFolder::exists($filepathPAPFolder)) {
						if (JFolder::create($filepathPAPFolder)) {
							$dataFile = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>";
							JFile::write($filepathPAPFolder . DS ."index.html", $dataFile);
						}
						// else {
							//$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_CREATE_FOLDER");
							//return false;
						//}
					}
				
					if (!JFile::copy($filepath, $filepathPAP)) {
						//$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_UPLOAD_FILE");
						//return false;
					} else {

						
						if ($canPlay == 1) {
							$data['filename_play']		=  $data['filename'];
						} else if ($canPreview == 1) {
							$data['filename_preview']	=  $data['filename'];
						}
					}
				}
			}
		}
		// ==============================================

		
		// Bind the data.
		if (!$table->bind($data)) {
			$this->setError($table->getError());
			return false;
		}
		
		// Date - - - - - 
		$nullDate	= $this->_db->getNullDate();
		$config 	= JFactory::getConfig();
		$tzoffset 	= $config->get('offset');
		//$date 		= JFactory::getDate($table->date, $tzoffset);
		//$table->date 	= $date->toSql();
		
		// Append time if not added to publish date
		//if (strlen(trim($table->publish_up)) <= 10) {
		//	$table->publish_up .= ' 00:00:00';
		//}
		//$date = JFactory::getDate($table->publish_up, $tzoffset);
		//$table->publish_up = $date->toSql();
		
		if ($table->id) {
			
			// Test Solution add date when it is removed
			if (!intval($table->date)) {
				$date	= JFactory::getDate();
				$table->date = $date->toSql();
			}

		} else {
			if (!intval($table->date)) {
				$date	= JFactory::getDate();
				$table->date = $date->toSql();
			}
		}
		
		if(intval($table->publish_up) == 0) {
			$table->publish_up = JFactory::getDate()->toSql();
		}
		
		// Handle never unpublish date
		if (trim($table->publish_down) == JText::_('Never') || trim( $table->publish_down ) == '') {
			$table->publish_down = $nullDate;
		} else {
			if (strlen(trim( $table->publish_down )) <= 10) {
				$table->publish_down .= ' 00:00:00';
			}
			//$date = JFactory::getDate($table->publish_down, $tzoffset);
			$date = JFactory::getDate($table->publish_down);
			$table->publish_down = $date->toSql();
		}
		// - - - - - -
		

		// if new item, order last in appropriate group
		if (!$table->id) {
			$where = 'catid = ' . (int) $table->catid ;
			$table->ordering = $table->getNextOrder( $where );
		}
		
		
		
		
		
		

		// Prepare the row for saving
		$this->prepareTable($table);

		// Check the data.
		if (!$table->check()) {
			$this->setError($table->getError());
			return false;
		}

		// Trigger the onContentBeforeSave event.
		/* $result = $dispatcher->trigger($this->event_before_save, array($this->option.'.'.$this->name, $table, $isNew));
		if (in_array(false, $result, true)) {
			$this->setError($table->getError());
			return false;
		} */

		// Store the data.
		if (!$table->store()) {
			$this->setError($table->getError());
			return false;
		}
		
		// Store to ref table
		if (!isset($data['tags'])) {
			$data['tags'] = array();
		}
		if ((int)$table->id > 0) {
			PhocaDownloadTag::storeTags($data['tags'], (int)$table->id);
		}

		// Clean the cache.
		$cache = JFactory::getCache($this->option);
		$cache->clean();

		// Trigger the onContentAfterSave event.
		//$dispatcher->trigger($this->event_after_save, array($this->option.'.'.$this->name, $table, $isNew));

		$pkName = $table->getKeyName();
		if (isset($table->$pkName)) {
			$this->setState($this->getName().'.id', $table->$pkName);
		}
		$this->setState($this->getName().'.new', $isNew);
		
		
		

		
		return true;
	}
Ejemplo n.º 20
0
             $buttonPlOptions = $this->t['buttonpl']->optionsmp3;
         }
         $playLink = JRoute::_(PhocaDownloadRoute::getFileRoute($v->id, $v->catid, $v->alias, $v->categoryalias, 0, 'play') . $this->t['limitstarturl']);
         $pdButtonPlay .= '<div class="pd-button-play">';
         if ($this->t['play_popup_window'] == 1) {
             $pdButtonPlay .= '<a class="btn btn-danger"  href="' . $playLink . '" onclick="' . $buttonPlOptions . '" >' . JText::_('COM_PHOCADOWNLOAD_PLAY') . '</a>';
         } else {
             $pdButtonPlay .= '<a class="btn btn-danger pd-modal-button" href="' . $playLink . '" rel="' . $buttonPlOptions . '" >' . JText::_('COM_PHOCADOWNLOAD_PLAY') . '</a>';
         }
         $pdButtonPlay .= '</div>';
     }
 }
 // pdbuttonpreview
 $pdButtonPreview = '';
 if (isset($v->filename_preview) && $v->filename_preview != '') {
     $fileExt = PhocaDownloadFile::getExtension($v->filename_preview);
     if ($fileExt == 'pdf' || $fileExt == 'jpeg' || $fileExt == 'jpg' || $fileExt == 'png' || $fileExt == 'gif') {
         $filePath = PhocaDownloadPath::getPathSet('filepreview');
         $filePath = str_replace('../', JURI::base(true) . '/', $filePath['orig_rel_ds']);
         $previewLink = $filePath . $v->filename_preview;
         $pdButtonPreview .= '<div class="pd-button-preview">';
         if ($this->t['preview_popup_window'] == 1) {
             $pdButtonPreview .= '<a  class="btn btn-warning" href="' . $previewLink . '" onclick="' . $this->t['buttonpr']->options . '" >' . JText::_('COM_PHOCADOWNLOAD_PREVIEW') . '</a>';
         } else {
             if ($fileExt == 'pdf') {
                 // Iframe - modal
                 $pdButtonPreview .= '<a class="btn btn-warning pd-modal-button" href="' . $previewLink . '" rel="' . $this->t['buttonpr']->options . '" >' . JText::_('COM_PHOCADOWNLOAD_PREVIEW') . '</a>';
             } else {
                 // Image - modal
                 $pdButtonPreview .= '<a class="btn btn-warning pd-modal-button" href="' . $previewLink . '" rel="' . $this->t['buttonpr']->optionsimg . '" >' . JText::_('COM_PHOCADOWNLOAD_PREVIEW') . '</a>';
             }