.'</a></div>';
		}
	}
} else {
	echo '<div class="pd-file"><div class="ph-top"></div>';
}


if (!empty($this->file[0])) {
	$v = $this->file[0];
	
	// 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($this->category[0])) {
		$rightDisplay = PhocaDownloadAccess::getUserRight('accessuserid', $v->cataccessuserid, $v->cataccess, $this->t['user']->getAuthorisedViewLevels(), $this->t['user']->get('id', 0), 0);
	}
	// - - - - - - - - - - - - - - - - - - - - - -
	
	if ($rightDisplay == 1) {
	
		$l = new PhocaDownloadLayout();
	
		echo '<h3 class="pdfv-name">'.$l->getName($v->title, $v->filename, 1). '</h3>';
		
		
// =====================================================================================		
// BEGIN LAYOUT AREA
// =====================================================================================
		
		// Is this direct menu link to File View
Exemple #2
0
	public static function renderRateFile($id, $displayRating, $small = 1, $refresh = false) {
	
		$user					= JFactory::getUser();
		$neededAccessLevels		= PhocaDownloadAccess::getNeededAccessLevels();
		$access					= PhocaDownloadAccess::isAccess($user->getAuthorisedViewLevels(), $neededAccessLevels);
		
		
		if ($small == 1) {
			$smallO = '-small';
			$ratio = 18;
		} else {
			$smallO = '';
			$ratio = 22;
		}
	
		$o = '';
		
		//.$rating['urlvote'].$amp.'controller=detail&task=rate&rating=1
		//$amp 	= PhocaDownloadAccess::setQuestionmarkOrAmp($rating['urlvote']);
		$href	= 'javascript:void(0);';
		
		if ((int)$displayRating != 1) {
			return '';
		} else {
		
			$rating['alreadyratedfile']	= self::checkUserVoteFile( (int)$id, (int)$user->id );
			
			$rating['notregisteredfile'] 	= true;
			//$rating['usernamefile']		= '';
			if ($access > 0) {
				$rating['notregisteredfile'] 	= false;
				$rating['usernamefile']			= $user->name;
			}	
			
			$rating['votescountfile'] 	= 0;
			$rating['votesaveragefile'] = 0;
			$rating['voteswidthfile'] 	= 0;
			$votesStatistics	= self::getVotesStatisticsFile((int)$id);
			if (!empty($votesStatistics->count)) {
				$rating['votescountfile'] = $votesStatistics->count;
			}
			if (!empty($votesStatistics->average)) {
				$rating['votesaveragefile'] = $votesStatistics->average;
				if ($rating['votesaveragefile'] > 0) {
					$rating['votesaveragefile'] 	= round(((float)$rating['votesaveragefile'] / 0.5)) * 0.5;
					$rating['voteswidthfile']		= $ratio * $rating['votesaveragefile'];
				} else {
					$rating['votesaveragefile'] 	= (int)0;// not float displaying
				}
			}
		
			// Leave message for already voted images
			//$vote = JRequest::getVar('vote', 0, '', 'int');
			$voteMsg = JText::_('COM_PHOCADOWNLOAD_RATING_ALREADY_RATED_FILE');
			//if ($vote == 1) {
			//	$voteMsg = JText::_('COM_PHOCADOWNLOAD_ALREADY_RATED_FILE_THANKS');
			//}
		
			$rating['votestextimg'] = 'VOTE';
			if ((int)$rating['votescountfile'] > 1) {
				$rating['votestextimg'] = 'VOTES';
			}

			$o .= '<div style="float:left;"><strong>' 
					. JText::_('COM_PHOCADOWNLOAD_RATING'). '</strong>: ' . $rating['votesaveragefile'] .' / '
					.$rating['votescountfile'] . ' ' . JText::_('COM_PHOCADOWNLOAD_'.$rating['votestextimg']). '&nbsp;&nbsp;</div>';
		
			if ($rating['alreadyratedfile']) {
				$o .= '<div style="float:left;"><ul class="star-rating'.$smallO.'">'
						.'<li class="current-rating" style="width:'.$rating['voteswidthfile'].'px"></li>'
						.'<li><span class="star1"></span></li>';

				for ($i = 2;$i < 6;$i++) {
					$o .= '<li><span class="stars'.$i.'"></span></li>';
				}
				$o .= '</ul></div>';
				
				$or ='<div class="pd-result" id="pdresult'.(int)$id.'" style="float:left;margin-left:5px">'.JText::_('COM_PHOCADOWNLOAD_RATING_ALREADY_RATED_FILE').'</div>';
			
			} else if ($rating['notregisteredfile']) {

				$o .= '<div style="float:left;"><ul class="star-rating'.$smallO.'">'
						.'<li class="current-rating" style="width:'.$rating['voteswidthfile'].'px"></li>'
						.'<li><span class="star1"></span></li>';

				for ($i = 2;$i < 6;$i++) {
					$o .= '<li><span class="stars'.$i.'"></span></li>';
				}
				$o .= '</ul></div>';
				
				$or ='<div class="pd-result" id="pdresult'.(int)$id.'" style="float:left;margin-left:5px">'.JText::_('COM_PHOCADOWNLOAD_ONLY_REGISTERED_LOGGED_RATE_FILE').'</div>';
			
			} else {
		
				$o .= '<div style="float:left;"><ul class="star-rating'.$smallO.'">'
						.'<li class="current-rating" style="width:'.$rating['voteswidthfile'].'px"></li>'
						.'<li><a href="'.$href.'" onclick="pdRating('.(int)$id.', 1)" title="1 '. JText::_('COM_PHOCADOWNLOAD_STAR_OUT_OF').' 5" class="star1">1</a></li>';
		
				for ($i = 2;$i < 6;$i++) {
					$o .= '<li><a href="'.$href.'" onclick="pdRating('.(int)$id.', '.$i.')" title="'.$i.' '. JText::_('COM_PHOCADOWNLOAD_STARS_OUT_OF').' 5" class="stars'.$i.'">'.$i.'</a></li>';
				}
				$o .= '</ul></div>';
				
				$or ='<div class="pd-result" id="pdresult'.(int)$id.'" style="float:left;margin-left:5px"></div>';
			}
			
			

		}
		
		if ($refresh == true) {
			return $o;//we are in Ajax, return only content of pdvoting div
		} else {
			return '<div id="pdvoting'.(int)$id.'">'.$o.'</div>' .$or ;//not in ajax, return the contend in div
		}
		
	
	}
Exemple #3
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);
                 }
             }
         }
     }
 }
Exemple #4
0
 public static function getDownloadData($id, $return, $type = 0)
 {
     $outcome = array();
     $wheres = array();
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     $params = $app->getParams();
     $user = JFactory::getUser();
     $redirectUrl = urlencode(base64_encode($return));
     $returnUrl = 'index.php?option=com_users&view=login&return=' . $redirectUrl;
     $userLevels = implode(',', $user->getAuthorisedViewLevels());
     $limitEnabled = $params->get('user_files_max_count_download', 0);
     if ((int) $limitEnabled > 0) {
         if ((int) $user->id < 1) {
             $app->redirect(JRoute::_($returnUrl, false), JText::_("COM_PHOCADOWNLOAD_NOT_LOGGED_IN_USERS_NOT_ALLOWED_DOWNLOAD"));
             exit;
         }
         $userFileCount = PhocaDownloadStat::getCountFilePerUser($id);
         (int) $userFileCount++;
         // Because we need to count this attempt too.
         if ((int) $userFileCount > (int) $limitEnabled) {
             $app->redirect(JRoute::_($returnUrl, false), JText::_("COM_PHOCADOWNLOAD_MAX_LIMIT_DOWNLOAD_PER_FILE_REACHED"));
             exit;
         }
     }
     $pQ = $params->get('enable_plugin_query', 0);
     $wheres[] = " c.id = " . (int) $id;
     $wheres[] = " c.published = 1";
     $wheres[] = " c.approved \t= 1";
     $wheres[] = " c.catid = cc.id";
     if ($type == 1) {
         // Unique download link does not have any access
         $rightDisplay = 1;
     } else {
         $wheres[] = " cc.access IN (" . $userLevels . ")";
     }
     // 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) . ' )';
     if ($pQ == 1) {
         // GWE MOD - to allow for access restrictions
         JPluginHelper::importPlugin("phoca");
         $dispatcher =& JDispatcher::getInstance();
         $joins = array();
         $results = $dispatcher->trigger('onGetDownload', array(&$wheres, &$joins, $id, $paramsC));
         // END GWE MOD
     }
     /*$query = " SELECT c.filename, c.directlink, c.access"
     		." FROM #__phocadownload AS c"
     		. ($pQ == 1 ? ((count($joins)>0?( " LEFT JOIN " .implode( " LEFT JOIN ", $joins )):"")):"") // GWE MOD
     		. " WHERE " . implode( " AND ", $wheres )
     		. " ORDER BY c.ordering";*/
     $query = ' SELECT c.catid, c.filename, c.directlink, c.link_external, c.access, c.confirm_license, c.metakey, c.metadesc, cc.access as cataccess, cc.accessuserid as cataccessuserid, c.tokenhits ' . ' FROM #__phocadownload AS c, #__phocadownload_categories AS cc ' . ($pQ == 1 ? count($joins) > 0 ? ' LEFT JOIN ' . implode(' LEFT JOIN ', $joins) : '' : '') . ' WHERE ' . implode(' AND ', $wheres) . ' ORDER BY c.ordering';
     $db->setQuery($query, 0, 1);
     $filename = $db->loadObjectList();
     $limitTokenEnabled = $params->get('token_files_max_count_download', 0);
     if ((int) $limitTokenEnabled > 0) {
         if (isset($filename[0]->tokenhits)) {
             $tokenFileCount = $filename[0]->tokenhits;
             (int) $tokenFileCount++;
             // Because we need to count this attempt too.
             if ((int) $tokenFileCount > (int) $limitTokenEnabled) {
                 $app->redirect(JRoute::_(htmlspecialchars($return)), JText::_("COM_PHOCADOWNLOAD_MAX_LIMIT_DOWNLOAD_TOKEN_REACHED"));
                 exit;
             }
         }
     }
     //OSE Modified Start;
     if (!empty($filename[0])) {
         phocadownloadimport('phocadownload.utils.external');
         PhocaDownloadExternal::checkOSE($filename[0]);
     }
     //OSE Modified End;
     // - - - - - - - - - - - - - - -
     // 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 ($type == 1) {
         // Unique download link does not have any access
         $rightDisplay = 1;
     } else {
         if (!empty($filename[0])) {
             $rightDisplay = PhocaDownloadAccess::getUserRight('accessuserid', $filename[0]->cataccessuserid, $filename[0]->cataccess, $user->getAuthorisedViewLevels(), $user->get('id', 0), 0);
         }
         // - - - - - - - - - - - - - - - - - - - - - -
         if ($rightDisplay == 0) {
             $app->redirect(JRoute::_($returnUrl, false), JText::_("COM_PHOCADOWNLOAD_NO_RIGHTS_ACCESS_CATEGORY_FILE"));
             exit;
         }
     }
     if (empty($filename)) {
         $outcome['file'] = "COM_PHOCADOWNLOAD_ERROR_NO_DB_RESULT";
         $outcome['directlink'] = 0;
         $outcome['externallink'] = 0;
         return $outcome;
     }
     if ($type == 1) {
         // Unique download link
     } else {
         if (isset($filename[0]->access)) {
             if (!in_array($filename[0]->access, $user->getAuthorisedViewLevels())) {
                 $app->redirect(JRoute::_($returnUrl, false), JText::_('COM_PHOCADOWNLOAD_PLEASE_LOGIN_DOWNLOAD_FILE'));
                 exit;
             }
         } else {
             $outcome['file'] = "COM_PHOCADOWNLOAD_ERROR_NO_DB_RESULT";
             $outcome['directlink'] = 0;
             $outcome['externallink'] = 0;
             return $outcome;
         }
     }
     // - - - - - - - - - - - - - - - -
     $filenameT = $filename[0]->filename;
     $directlinkT = $filename[0]->directlink;
     $linkExternalT = $filename[0]->link_external;
     // Unique Download Link
     if ($type == 1) {
         $directlinkT = 0;
         // Unique Download Link cannot work with direct link
     }
     $filePath = PhocaDownloadPath::getPathSet('file');
     if ($filenameT != '') {
         // Important - you cannot use direct link if you have selected absolute path
         // Absolute Path defined by user
         $absolutePath = $params->get('absolute_path', '');
         if ($absolutePath != '') {
             $directlinkT = 0;
         }
         if ($directlinkT == 1) {
             $relFile = JURI::base(true) . '/' . $params->get('download_folder', 'phocadownload') . '/' . $filenameT;
             $outcome['file'] = $relFile;
             $outcome['directlink'] = $directlinkT;
             $outcome['externallink'] = $linkExternalT;
             return $outcome;
         } else {
             if ($directlinkT == 0 && $linkExternalT != '') {
                 $relFile = JURI::base(true) . '/' . $params->get('download_folder', 'phocadownload') . '/' . $filenameT;
                 $outcome['file'] = $relFile;
                 $outcome['directlink'] = $directlinkT;
                 $outcome['externallink'] = $linkExternalT;
                 return $outcome;
             } else {
                 $absFile = str_replace('/', DS, JPath::clean($filePath['orig_abs_ds'] . $filenameT));
             }
         }
         if (JFile::exists($absFile)) {
             $outcome['file'] = $absFile;
             $outcome['directlink'] = $directlinkT;
             $outcome['externallink'] = $linkExternalT;
             return $outcome;
         } else {
             $outcome['file'] = "COM_PHOCADOWNLOAD_ERROR_NO_ABS_FILE";
             $outcome['directlink'] = 0;
             $outcome['externallink'] = $linkExternalT;
             return $outcome;
         }
     } else {
         $outcome['file'] = "COM_PHOCADOWNLOAD_ERROR_NO_DB_FILE";
         $outcome['directlink'] = 0;
         $outcome['externallink'] = $linkExternalT;
         return $outcome;
     }
 }
Exemple #5
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);
 }
			
<tbody><?php 
    $k = 0;
    $i = 0;
    $n = count($this->t['filesitems']);
    $rows =& $this->t['filesitems'];
    if (is_array($rows)) {
        foreach ($rows as $row) {
            // USER RIGHT - Delete (Publish/Unpublish) - - - - - - - - - - -
            // 2, 2 means that user access will be ignored in function getUserRight for display Delete button
            // because we cannot check the access and delete in one time
            $user = JFactory::getUser();
            $rightDisplayDelete = 0;
            $catAccess = PhocaDownloadAccess::getCategoryAccessByFileId((int) $row->id);
            if (!empty($catAccess)) {
                $rightDisplayDelete = PhocaDownloadAccess::getUserRight('deleteuserid', $catAccess->deleteuserid, 2, $user->getAuthorisedViewLevels(), $user->get('id', 0), 0);
            }
            // - - - - - - - - - - - - - - - - - - - - - -
            ?>
<tr class="<?php 
            echo "row{$k}";
            ?>
">

	<td><?php 
            echo $row->title;
            ?>
</td>
	
	<?php 
            // Publish Unpublish
Exemple #7
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;
		
		
	}
Exemple #8
0
 function delete()
 {
     $app = JFactory::getApplication();
     $post['id'] = $app->input->get('actionid', '', 'int', 0);
     $post['limitstart'] = $app->input->get('limitstart', '', 'int', 0);
     $model = $this->getModel('user');
     //$isOwnerCategory 	= 1;//$model->isOwnerCategoryImage((int)$this->_user->id, (int)$id);
     // USER RIGHT - Delete - - - - - - - - - - -
     // 2, 2 means that user access will be ignored in function getUserRight for display Delete button
     $user = JFactory::getUser();
     $rightDisplayDelete = 0;
     $catAccess = PhocaDownloadAccess::getCategoryAccessByFileId((int) $post['id']);
     if (!empty($catAccess)) {
         $rightDisplayDelete = PhocaDownloadAccess::getUserRight('deleteuserid', $catAccess->deleteuserid, 2, $user->getAuthorisedViewLevels(), $user->get('id', 0), 0);
     }
     // - - - - - - - - - - - - - - - - - - - - - -
     if ($rightDisplayDelete) {
         if (!$model->delete((int) $post['id'])) {
             $msg = JText::_('COM_PHOCADOWNLOAD_ERROR_DELETING_ITEM');
         } else {
             $msg = JText::_('COM_PHOCADOWNLOAD_SUCCESS_DELETING_ITEM');
         }
     } else {
         $app->redirect($this->loginUrl, $this->loginString);
         exit;
     }
     $lSO = '';
     if ($post['limitstart'] != '') {
         $lSO = '&limitstart=' . (int) $post['limitstart'];
     }
     $this->setRedirect(JRoute::_($this->url . $lSO, false), $msg);
 }
Exemple #9
0
 function display($tpl = null)
 {
     if (!JRequest::checkToken('request')) {
         $response = array('status' => '0', 'error' => JText::_('JINVALID_TOKEN'));
         echo json_encode($response);
         return;
     }
     $app = JFactory::getApplication();
     $params = $app->getParams();
     $ratingVote = $app->input->get('ratingVote', 0, 'post', 'int');
     $ratingId = $app->input->get('ratingId', 0, 'post', 'int');
     // ID of File
     $format = $app->input->get('format', '', 'post', 'string');
     $task = $app->input->get('task', '', 'get', 'string');
     $view = $app->input->get('view', '', 'get', 'string');
     $small = $app->input->get('small', 1, 'get', 'string');
     //small or large rating icons
     $paramsC = JComponentHelper::getParams('com_phocadownload');
     $param['displayratingfile'] = $paramsC->get('display_rating_file', 0);
     // Check if rating is enabled - if not then user should not be able to rate or to see updated reating
     if ($task == 'refreshrate' && (int) $param['displayratingfile'] > 0) {
         $ratingOutput = PhocaDownloadRate::renderRateFile((int) $ratingId, 1, $small, true);
         // ID of File
         $response = array('status' => '0', 'message' => $ratingOutput);
         echo json_encode($response);
         return;
         //return $ratingOutput;
     } else {
         if ($task == 'rate') {
             $user = JFactory::getUser();
             //$view 		= $app->input->get( 'view', '', 'get', '', JREQUEST_NOTRIM  );
             //$Itemid		= $app->input->get( 'Itemid', 0, 'int');
             $neededAccessLevels = PhocaDownloadAccess::getNeededAccessLevels();
             $access = PhocaDownloadAccess::isAccess($user->getAuthorisedViewLevels(), $neededAccessLevels);
             $post['fileid'] = (int) $ratingId;
             $post['userid'] = $user->id;
             $post['rating'] = (int) $ratingVote;
             if ($format != 'json') {
                 $msg = JText::_('COM_PHOCADOWNLOAD_ERROR_WRONG_RATING');
                 $response = array('status' => '0', 'error' => $msg);
                 echo json_encode($response);
                 return;
             }
             if ((int) $post['fileid'] < 1) {
                 $msg = JText::_('COM_PHOCADOWNLOAD_ERROR_FILE_NOT_EXISTS');
                 $response = array('status' => '0', 'error' => $msg);
                 echo json_encode($response);
                 return;
             }
             $model = $this->getModel();
             $checkUserVote = PhocaDownloadRate::checkUserVoteFile($post['fileid'], $post['userid']);
             // User has already rated this category
             if ($checkUserVote) {
                 $msg = JText::_('COM_PHOCADOWNLOAD_RATING_ALREADY_RATED_FILE');
                 $response = array('status' => '0', 'error' => '', 'message' => $msg);
                 echo json_encode($response);
                 return;
             } else {
                 if ((int) $post['rating'] < 1 || (int) $post['rating'] > 5) {
                     $msg = JText::_('COM_PHOCADOWNLOAD_ERROR_WRONG_RATING');
                     $response = array('status' => '0', 'error' => $msg);
                     echo json_encode($response);
                     return;
                 }
                 if ($access > 0 && $user->id > 0) {
                     if (!$model->rate($post)) {
                         $msg = JText::_('COM_PHOCADOWNLOAD_ERROR_RATING_FILE');
                         $response = array('status' => '0', 'error' => $msg);
                         echo json_encode($response);
                         return;
                     } else {
                         $msg = JText::_('COM_PHOCADOWNLOAD_SUCCESS_RATING_FILE');
                         $response = array('status' => '1', 'error' => '', 'message' => $msg);
                         echo json_encode($response);
                         return;
                     }
                 } else {
                     $msg = JText::_('COM_PHOCADOWNLOAD_NOT_AUTHORISED_ACTION');
                     $response = array('status' => '0', 'error' => $msg);
                     echo json_encode($response);
                     return;
                 }
             }
         } else {
             $msg = JText::_('COM_PHOCADOWNLOAD_NOT_AUTHORISED_ACTION');
             $response = array('status' => '0', 'error' => $msg);
             echo json_encode($response);
             return;
         }
     }
 }