Esempio n. 1
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);
 }
Esempio n. 2
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;
	}
Esempio n. 3
0
     $pdFile .= PhocaDownloadRenderFront::displayNewIcon($v->date, $this->t['displaynew']);
     $pdFile .= PhocaDownloadRenderFront::displayHotIcon($v->hits, $this->t['displayhot']);
     //Specific icons
     if (isset($v->image_filename_spec1) && $v->image_filename_spec1 != '') {
         $pdFile .= '<div class="pd-float">' . $l->getImageDownload($v->image_filename_spec1) . '</div>';
     }
     if (isset($v->image_filename_spec2) && $v->image_filename_spec2 != '') {
         $pdFile .= '<div class="pd-float">' . $l->getImageDownload($v->image_filename_spec2) . '</div>';
     }
     $pdFile .= '</div></div></div>' . "\n";
 }
 // pdbuttonplay
 $pdButtonPlay = '';
 if (isset($v->filename_play) && $v->filename_play != '') {
     $fileExt = PhocaDownloadFile::getExtension($v->filename_play);
     $canPlay = PhocaDownloadFile::canPlay($v->filename_play);
     if ($canPlay) {
         // Special height for music only
         $buttonPlOptions = $this->t['buttonpl']->options;
         if ($fileExt == 'mp3' || $fileExt == 'ogg') {
             $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>';
     }
Esempio n. 4
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;
 }
Esempio n. 5
0
	function singleFileUpload(&$errUploadMsg, $file, $post) {
	
		$app		= JFactory::getApplication();;
		JRequest::checkToken( 'request' ) or jexit( 'Invalid Token' );
		jimport('joomla.client.helper');
		$user 				= JFactory::getUser();
		$ftp 		= JClientHelper::setCredentialsFromRequest('ftp');
		$path		= PhocaDownloadPath::getPathSet();
		$folder		= $app->input->get( 'folder', '', '', 'path' );
		$format		= $app->input->get( 'format', 'html', '', 'cmd');
		$return		= $app->input->get( 'return-url', null, 'post', 'base64' );
		$viewBack	= $app->input->get( 'viewback', '', 'post', 'string' );
		//$catid 		= $app->input->get( 'catid', '', '', 'int'  );
		$paramsC 	= JComponentHelper::getParams('com_phocadownload') ;

		$overwriteExistingFiles 	= $paramsC->get( 'overwrite_existing_files', 0 );
		
		// USER RIGHT - UPLOAD - - - - - - - - - - -
		// 2, 2 means that user access will be ignored in function getUserRight for display Delete button
		$rightDisplayUpload	= 0;
		$catAccess	= PhocaDownloadAccess::getCategoryAccess((int)$post['catidfiles']);
		if (!empty($catAccess)) {
			$rightDisplayUpload = PhocaDownloadAccess::getUserRight('uploaduserid', $catAccess->uploaduserid, 2, $user->getAuthorisedViewLevels(), 1, 0);
		}
		// - - - - - - - - - - - - - - - - - - - - - -	
		
		
		/*$post['sectionid'] = $this->getSection((int)$post['catidfiles']);
		if(!$post['sectionid']) {
			$errUploadMsg = JText::_('COM_PHOCADOWNLOAD_WRONG_SECTION');	
			return false;
		}*/
		
		//$userFolder = substr(md5($user->username),0, 10);
		$userFolder = PhocaDownloadUtils::cleanFolderUrlName(htmlspecialchars(strip_tags($user->username)));
		
		if ($rightDisplayUpload == 1) {

			// Make the filename safe
			if (isset($file['name'])) {
				$file['name']	= JFile::makeSafe($file['name']);
			}
			
			if($file['tmp_name'] == '') {
				$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_ERROR_SERVER_NOT_ABLE_TO_STORE_FILE_TEMP_FOLDER");
				return false;
			}
			
			if (isset($file['name'])) {
				$filepath 				= JPath::clean($path['orig_abs_user_upload']. DS. $userFolder . DS.$file['name']);
				$filepathUserFolder 	= JPath::clean($path['orig_abs_user_upload']. DS. $userFolder);
				if (!PhocaDownloadFileUpload::canUpload( $file, $errUploadMsg, 'file', 2 )) {
				
					if ($errUploadMsg == 'COM_PHOCADOWNLOAD_WARNUSERFILESTOOLARGE') {
						$errUploadMsg 	= JText::_($errUploadMsg) . ' ('.PhocaDownloadFile::getFileSizeReadable($file['size']).')';
					} else {
						$errUploadMsg 	= JText::_($errUploadMsg);
					}
					
					return false;
				}

				if (JFile::exists($filepath) && $overwriteExistingFiles == 0) {
					$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_FILE_ALREADY_EXISTS");
					return false;
				}
				
				// Overwrite file and add no new item to database
				$fileExists = 0;
				if (JFile::exists($filepath) && $overwriteExistingFiles == 1) {
					$fileExists = 1;
				}

				if (!JFile::upload($file['tmp_name'], $filepath, false, true)) {
					$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_UPLOAD_FILE");
					return false;
				} else {
					
					// Saving file name into database with relative path
					if (!JFile::exists($filepathUserFolder . DS ."index.html")) {
						$data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>";
						JFile::write($filepathUserFolder . DS ."index.html", $data);
					}
					$file['namepap']	= $file['name'];
					$file['name']		=  'userupload/'.$userFolder.'/' . $file['name'];
					$succeeded 			= false;
					
					// =================================================
					// Make a copy for play and preview
					$papCopy 	= $paramsC->get( 'pap_copy', 0 );
					if ($papCopy == 1 || $papCopy == 3) {
						$canPlay	= PhocaDownloadFile::canPlay($file['namepap']);
						$canPreview = PhocaDownloadFile::canPreview($file['namepap']);
						$filepathPAP 			= JPath::clean($path['orig_abs_user_upload_pap']. DS. $userFolder . DS.$file['namepap']);
						$filepathUserFolderPAP 	= JPath::clean($path['orig_abs_user_upload_pap']. DS. $userFolder);
						
						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
							}
							
							// Overwrite file and add no new item to database
							$fileExistsPAP = 0;
							if (JFile::exists($filepathPAP) && $overwriteExistingFiles == 1) {
								$fileExistsPAP = 1;
							}
							
							if ($uploadPAP == 0) {
							
							} else {
								if (!JFolder::exists($filepathUserFolderPAP)) {
									if (JFolder::create($filepathUserFolderPAP)) {
										$data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>";
										JFile::write($filepathUserFolderPAP . 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) {
										$post['filename_play']		=  'userupload/'.$userFolder.'/' . $file['namepap'];
									} else if ($canPreview == 1) {
										$post['filename_preview']	=  'userupload/'.$userFolder.'/' . $file['namepap'];
									}
								}
							}
						}
					}
					// ==============================================
					
					if ($this->_save($post, $file['name'], $errUploadMsg, $fileExists)) {
						
						return true;
					} else {
						return false;
					}
				}
			} else {				
				$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_WARNFILETYPE");	
				$redirectUrl = $return;				
				return false;
			}
		} else {			
			$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_NOT_AUTHORISED_TO_UPLOAD");			
			
			return false;
		}
		return false;
		
		
	}
Esempio n. 6
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;
 }