primo commit
This commit is contained in:
263
components/com_phocadownload/models/categories.php
Normal file
263
components/com_phocadownload/models/categories.php
Normal file
@ -0,0 +1,263 @@
|
||||
<?php
|
||||
/*
|
||||
* @package Joomla.Framework
|
||||
* @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*
|
||||
* @component Phoca Component
|
||||
* @copyright Copyright (C) Jan Pavelka www.phoca.cz
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License version 2 or later;
|
||||
*/
|
||||
defined('_JEXEC') or die();
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
jimport('joomla.application.component.model');
|
||||
|
||||
|
||||
class PhocaDownloadModelCategories extends BaseDatabaseModel
|
||||
{
|
||||
var $_categories = null;
|
||||
var $_most_viewed_docs = null;
|
||||
var $_categories_ordering = null;
|
||||
var $_category_ordering = null;
|
||||
|
||||
function __construct() {
|
||||
$app = Factory::getApplication();
|
||||
parent::__construct();
|
||||
|
||||
$this->setState('filter.language',$app->getLanguageFilter());
|
||||
}
|
||||
|
||||
function getCategoriesList() {
|
||||
if (empty($this->_categories)) {
|
||||
$query = $this->_getCategoriesListQuery();
|
||||
|
||||
//$this->_categories = $this->_getList( $query );
|
||||
$categories = $this->_getList( $query );
|
||||
|
||||
if (!empty($categories)) {
|
||||
|
||||
// Parent Only
|
||||
foreach ($categories as $k => $v) {
|
||||
if ($v->parent_id == 0) {
|
||||
$this->_categories[$v->id] = $categories[$k];
|
||||
}
|
||||
}
|
||||
|
||||
// Subcategories
|
||||
foreach ($categories as $k => $v) {
|
||||
if (isset($this->_categories[$v->parent_id])) {
|
||||
$this->_categories[$v->parent_id]->subcategories[] = $categories[$k];
|
||||
$this->_categories[$v->parent_id]->numsubcat++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
$this->categories = $this->_getList( $query );
|
||||
if (!empty($this->categories)) {
|
||||
foreach ($this->categories as $key => $value) {
|
||||
$query = $this->getCategoriesListQuery( $value->id, $categoriesOrdering );
|
||||
$this->categories[$key]->subcategories = $this->_getList( $query );
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
return $this->_categories;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Get only parent categories
|
||||
*/
|
||||
function _getCategoriesListQuery( ) {
|
||||
|
||||
$wheres = array();
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$user = Factory::getUser();
|
||||
$userLevels = implode (',', $user->getAuthorisedViewLevels());
|
||||
|
||||
|
||||
$pQ = $params->get( 'enable_plugin_query', 0 );
|
||||
$display_categories = $params->get('display_categories', '');
|
||||
$hide_categories = $params->get('hide_categoriess', '');
|
||||
|
||||
if ( $display_categories != '' ) {
|
||||
$wheres[] = " cc.id IN (".$display_categories.")";
|
||||
}
|
||||
|
||||
if ( $hide_categories != '' ) {
|
||||
$wheres[] = " cc.id NOT IN (".$hide_categories.")";
|
||||
}
|
||||
//$wheres[] = " cc.parent_id = 0";
|
||||
$wheres[] = " cc.published = 1";
|
||||
$wheres[] = " cc.access IN (".$userLevels.")";
|
||||
|
||||
if ($this->getState('filter.language')) {
|
||||
$wheres[] = ' cc.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
}
|
||||
|
||||
$categoriesOrdering = $this->_getCategoryOrdering();
|
||||
|
||||
if ($pQ == 1) {
|
||||
// GWE MOD - to allow for access restrictions
|
||||
PluginHelper::importPlugin("phoca");
|
||||
//$dispatcher = JEventDispatcher::getInstance();
|
||||
$joins = array();
|
||||
$results = Factory::getApplication()->triggerEvent('onGetCategoriesList', array (&$wheres, &$joins, $params));
|
||||
// END GWE MOD
|
||||
}
|
||||
|
||||
$query = " SELECT cc.id, cc.parent_id, cc.title, cc.alias, cc.image, cc.access, cc.description, cc.accessuserid, COUNT(c.id) AS numdoc, 0 AS numsubcat"
|
||||
. " FROM #__phocadownload_categories AS cc"
|
||||
. " LEFT JOIN #__phocadownload AS c ON c.catid = cc.id AND c.published = 1 AND c.textonly = 0"
|
||||
. ($pQ == 1 ? ((count($joins)>0?( " LEFT JOIN " .implode( " LEFT JOIN ", $joins )):"")):"") // GWE MOD
|
||||
. " WHERE " . implode( " AND ", $wheres )
|
||||
. " GROUP BY cc.id, cc.parent_id, cc.title, cc.image, cc.alias, cc.access, cc.description, cc.accessuserid"
|
||||
. " ORDER BY ".$categoriesOrdering;
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get only first level under parent categories
|
||||
*/
|
||||
function _getCategoryListQuery( $parentCatId ) {
|
||||
|
||||
$wheres = array();
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$user = Factory::getUser();
|
||||
$userLevels = implode (',', $user->getAuthorisedViewLevels());
|
||||
|
||||
$pQ = $params->get( 'enable_plugin_query', 0 );
|
||||
$display_categories = $params->get('display_categories', '');
|
||||
$hide_categories = $params->get('hide_categoriess', '');
|
||||
|
||||
if ( $display_categories != '' ) {
|
||||
$wheres[] = " cc.id IN (".$display_categories.")";
|
||||
}
|
||||
|
||||
if ( $hide_categories != '' ) {
|
||||
$wheres[] = " cc.id NOT IN (".$hide_categories.")";
|
||||
}
|
||||
$wheres[] = " cc.parent_id = ".(int)$parentCatId;
|
||||
$wheres[] = " cc.published = 1";
|
||||
$wheres[] = " cc.access IN (".$userLevels.")";
|
||||
|
||||
if ($this->getState('filter.language')) {
|
||||
$wheres[] = ' cc.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
}
|
||||
|
||||
$categoryOrdering = $this->_getCategoryOrdering();
|
||||
|
||||
if ($pQ == 1) {
|
||||
// GWE MOD - to allow for access restrictions
|
||||
PluginHelper::importPlugin("phoca");
|
||||
//$dispatcher = JEventDispatcher::getInstance();
|
||||
$joins = array();
|
||||
$results = Factory::getApplication()->triggerEvent('onGetCategoryList', array (&$wheres, &$joins, $params));
|
||||
// END GWE MOD
|
||||
}
|
||||
|
||||
$query = " SELECT cc.id, cc.title, cc.alias, cc.image, cc.access, cc.accessuserid, COUNT(c.id) AS numdoc"
|
||||
. " FROM #__phocadownload_categories AS cc"
|
||||
. " LEFT JOIN #__phocadownload AS c ON c.catid = cc.id AND c.published = 1 AND c.textonly = 0"
|
||||
. ($pQ == 1 ? ((count($joins)>0?( " LEFT JOIN " .implode( " LEFT JOIN ", $joins )):"")):"") // GWE MOD
|
||||
. " WHERE " . implode( " AND ", $wheres )
|
||||
. " GROUP BY cc.id, cc.title, cc.alias, cc.image, cc.access, cc.accessuserid"
|
||||
. " ORDER BY ".$categoryOrdering;
|
||||
|
||||
return $query;
|
||||
|
||||
|
||||
}
|
||||
|
||||
function getMostViewedDocsList() {
|
||||
|
||||
if (empty($this->_most_viewed_docs)) {
|
||||
$query = $this->_getMostViewedDocsListQuery();
|
||||
$this->_most_viewed_docs = $this->_getList( $query );
|
||||
}
|
||||
return $this->_most_viewed_docs;
|
||||
}
|
||||
|
||||
function _getMostViewedDocsListQuery() {
|
||||
|
||||
$wheres = array();
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$user = Factory::getUser();
|
||||
$userLevels = implode (',', $user->getAuthorisedViewLevels());
|
||||
|
||||
$pQ = $params->get( 'enable_plugin_query', 0 );
|
||||
$most_viewed_docs_num = $params->get( 'most_download_files_num', 5 );
|
||||
$display_categories = $params->get('display_categories', '');
|
||||
$hide_categories = $params->get('hide_categoriess', '');
|
||||
|
||||
if ( $display_categories != '' ) {
|
||||
$wheres[] = " cc.id IN (".$display_categories.")";
|
||||
}
|
||||
|
||||
if ( $hide_categories != '' ) {
|
||||
$wheres[] = " cc.id NOT IN (".$hide_categories.")";
|
||||
}
|
||||
|
||||
|
||||
$wheres[] = " c.catid= cc.id";
|
||||
$wheres[] = " c.published= 1";
|
||||
$wheres[] = " c.approved= 1";
|
||||
$wheres[] = " c.textonly= 0";
|
||||
$wheres[] = " cc.access IN (".$userLevels.")";
|
||||
$wheres[] = " c.access IN (".$userLevels.")";
|
||||
|
||||
|
||||
if ($this->getState('filter.language')) {
|
||||
$wheres[] = ' c.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
$wheres[] = ' cc.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
}
|
||||
|
||||
// Active
|
||||
$jnow = Factory::getDate();
|
||||
$now = $jnow->toSql();
|
||||
$nullDate = $this->_db->getNullDate();
|
||||
$wheres[] = ' ( c.publish_up = '.$this->_db->Quote($nullDate).' OR c.publish_up <= '.$this->_db->Quote($now).' )';
|
||||
$wheres[] = ' ( c.publish_down = '.$this->_db->Quote($nullDate).' OR c.publish_down >= '.$this->_db->Quote($now).' )';
|
||||
|
||||
|
||||
|
||||
if ($pQ == 1) {
|
||||
// GWE MOD - to allow for access restrictions
|
||||
PluginHelper::importPlugin("phoca");
|
||||
//$dispatcher = JEventDispatcher::getInstance();
|
||||
$joins = array();
|
||||
$results = Factory::getApplication()->triggerEvent('onGetMostViewedDocs', array (&$wheres, &$joins, 0, $params));
|
||||
// END GWE MOD
|
||||
}
|
||||
|
||||
$query = " SELECT c.id, c.title, c.alias, c.filename, c.date, c.hits, c.image_filename, cc.id AS categoryid, cc.access as cataccess, cc.accessuserid as cataccessuserid, cc.title AS categorytitle, cc.alias AS categoryalias "
|
||||
." FROM #__phocadownload AS c, #__phocadownload_categories AS cc"
|
||||
. ($pQ == 1 ? ((count($joins)>0?( " LEFT JOIN " .implode( " LEFT JOIN ", $joins )):"")):"") // GWE MOD
|
||||
. " WHERE " . implode( " AND ", $wheres )
|
||||
. " ORDER BY c.hits DESC"
|
||||
. " LIMIT ".(int)$most_viewed_docs_num;
|
||||
return $query;
|
||||
}
|
||||
|
||||
function _getCategoryOrdering() {
|
||||
if (empty($this->_category_ordering)) {
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$ordering = $params->get( 'category_ordering', 1 );
|
||||
$this->_category_ordering = PhocaDownloadOrdering::getOrderingText($ordering, 2);
|
||||
|
||||
}
|
||||
return $this->_category_ordering;
|
||||
}
|
||||
}
|
||||
?>
|
||||
279
components/com_phocadownload/models/category.php
Normal file
279
components/com_phocadownload/models/category.php
Normal file
@ -0,0 +1,279 @@
|
||||
<?php
|
||||
/*
|
||||
* @package Joomla.Framework
|
||||
* @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*
|
||||
* @component Phoca Component
|
||||
* @copyright Copyright (C) Jan Pavelka www.phoca.cz
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License version 2 or later;
|
||||
*/
|
||||
defined('_JEXEC') or die();
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
jimport('joomla.application.component.model');
|
||||
|
||||
class PhocaDownloadModelCategory extends BaseDatabaseModel
|
||||
{
|
||||
var $_document = null;
|
||||
var $_category = null;
|
||||
var $_subcategories = null;
|
||||
var $_filename = null;
|
||||
var $_directlink = 0;
|
||||
var $_file_ordering = null;
|
||||
var $_category_ordering = null;
|
||||
var $file_ordering_select = null;
|
||||
var $category_ordering_select = null;
|
||||
var $_pagination = null;
|
||||
var $_total = null;
|
||||
var $_context = 'com_phocadownload.category';
|
||||
|
||||
function __construct() {
|
||||
|
||||
$app = Factory::getApplication();
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$config = Factory::getConfig();
|
||||
|
||||
//$paramsC = JComponentHelper::getParams('com_phocadownload') ;
|
||||
$paramsC = $app->getParams();
|
||||
$defaultPagination = (int)$paramsC->get( 'default_pagination', '20' );
|
||||
$file_ordering = $paramsC->get( 'file_ordering', 1 );
|
||||
|
||||
$context = $this->_context.'.';
|
||||
|
||||
// Get the pagination request variables
|
||||
$this->setState('limit', $app->getUserStateFromRequest($context.'limit', 'limit', $defaultPagination, 'int'));
|
||||
$this->setState('limitstart', $app->input->get('limitstart', 0, 'int'));
|
||||
|
||||
// In case limit has been changed, adjust limitstart accordingly
|
||||
$this->setState('limitstart', ($this->getState('limit') != 0 ? (floor($this->getState('limitstart') / $this->getState('limit')) * $this->getState('limit')) : 0));
|
||||
|
||||
$this->setState('filter.language',$app->getLanguageFilter());
|
||||
|
||||
$this->setState('fileordering', $app->getUserStateFromRequest($context .'fileordering', 'fileordering', $file_ordering, 'int'));
|
||||
|
||||
// Get the filter request variables
|
||||
$this->setState('filter_order', Factory::getApplication()->input->getCmd('filter_order', 'ordering'));
|
||||
$this->setState('filter_order_dir', Factory::getApplication()->input->getCmd('filter_order_Dir', 'ASC'));
|
||||
|
||||
}
|
||||
|
||||
function getPagination($categoryId, $tagId) {
|
||||
if (empty($this->_pagination)) {
|
||||
jimport('joomla.html.pagination');
|
||||
$this->_pagination = new PhocaDownloadPagination( $this->getTotal($categoryId, $tagId), $this->getState('limitstart'), $this->getState('limit') );
|
||||
}
|
||||
return $this->_pagination;
|
||||
}
|
||||
|
||||
function getTotal($categoryId, $tagId) {
|
||||
if (empty($this->_total)) {
|
||||
$query = $this->_getFileListQuery($categoryId, $tagId, 1);
|
||||
$this->_total = $this->_getListCount($query);
|
||||
}
|
||||
return $this->_total;
|
||||
}
|
||||
|
||||
function getFileList($categoryId, $tagId) {
|
||||
if (empty($this->_document)) {
|
||||
$query = $this->_getFileListQuery( $categoryId, $tagId);
|
||||
$this->_document= $this->_getList( $query ,$this->getState('limitstart'), $this->getState('limit'));
|
||||
}
|
||||
return $this->_document;
|
||||
}
|
||||
|
||||
function getCategory($categoryId) {
|
||||
if (empty($this->_category)) {
|
||||
$query = $this->_getCategoriesQuery( $categoryId, FALSE );
|
||||
$this->_category = $this->_getList( $query, 0, 1 );
|
||||
}
|
||||
return $this->_category;
|
||||
}
|
||||
|
||||
function getSubcategories($categoryId) {
|
||||
if (empty($this->_subcategories)) {
|
||||
$query = $this->_getCategoriesQuery( $categoryId, TRUE );
|
||||
$this->_subcategories = $this->_getList( $query );
|
||||
}
|
||||
return $this->_subcategories;
|
||||
}
|
||||
|
||||
function _getFileListQuery( $categoryId, $tagId = 0, $count = 0 ) {
|
||||
|
||||
$wheres = array();
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$user = Factory::getUser();
|
||||
$userLevels = implode (',', $user->getAuthorisedViewLevels());
|
||||
|
||||
|
||||
$pQ = $params->get( 'enable_plugin_query', 0 );
|
||||
|
||||
if ((int)$tagId > 0) {
|
||||
$wheres[] = ' t.tagid= '.(int)$tagId;
|
||||
} else {
|
||||
$wheres[] = ' c.catid= '.(int)$categoryId;
|
||||
}
|
||||
|
||||
$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';
|
||||
|
||||
if ($this->getState('filter.language')) {
|
||||
$wheres[] = ' c.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
$wheres[] = ' cc.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
}
|
||||
|
||||
// Active
|
||||
$jnow = Factory::getDate();
|
||||
$now = $jnow->toSql();
|
||||
$nullDate = $this->_db->getNullDate();
|
||||
$wheres[] = ' ( c.publish_up = '.$this->_db->Quote($nullDate).' OR c.publish_up <= '.$this->_db->Quote($now).' )';
|
||||
$wheres[] = ' ( c.publish_down = '.$this->_db->Quote($nullDate).' OR c.publish_down >= '.$this->_db->Quote($now).' )';
|
||||
|
||||
if ($pQ == 1) {
|
||||
// GWE MOD - to allow for access restrictions
|
||||
PluginHelper::importPlugin("phoca");
|
||||
//$dispatcher = JEventDispatcher::getInstance();
|
||||
$joins = array();
|
||||
$results = Factory::getApplication()->triggerEvent('onGetFileList', array (&$wheres, &$joins,$categoryId , $params));
|
||||
// END GWE MOD
|
||||
}
|
||||
|
||||
|
||||
$fileOrdering = $this->_getFileOrdering();
|
||||
|
||||
|
||||
if ($count == 1) {
|
||||
$query = ' SELECT c.id'
|
||||
.' FROM #__phocadownload AS c'
|
||||
.' LEFT JOIN #__phocadownload_categories AS cc ON cc.id = c.catid';
|
||||
if ((int)$tagId > 0) {
|
||||
$query .= ' LEFT JOIN #__phocadownload_tags_ref AS t ON t.fileid = c.id';
|
||||
}
|
||||
$query .= ($pQ == 1 ? ((count($joins)>0?( " LEFT JOIN " .implode( " LEFT JOIN ", $joins )):"")):"") // GWE MOD
|
||||
. ' WHERE ' . implode( ' AND ', $wheres )
|
||||
//. ' ORDER BY '.$fileOrdering;
|
||||
. ' ORDER BY c.id';
|
||||
|
||||
} else {
|
||||
|
||||
$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';
|
||||
if ((int)$tagId > 0) {
|
||||
$query .= ' LEFT JOIN #__phocadownload_tags_ref AS t ON t.fileid = c.id';
|
||||
}
|
||||
|
||||
$query .= ' LEFT JOIN #__phocadownload_file_votes_statistics AS r ON r.fileid = c.id';
|
||||
|
||||
$query .= ($pQ == 1 ? ((count($joins)>0?( " LEFT JOIN " .implode( " LEFT JOIN ", $joins )):"")):"") // GWE MOD
|
||||
. ' WHERE ' . implode( ' AND ', $wheres )
|
||||
. ' ORDER BY '.$fileOrdering;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function _getCategoriesQuery( $categoryId, $subcategories = FALSE ) {
|
||||
|
||||
$wheres = array();
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$user = Factory::getUser();
|
||||
$userLevels = implode (',', $user->getAuthorisedViewLevels());
|
||||
|
||||
$pQ = $params->get( 'enable_plugin_query', 0 );
|
||||
|
||||
|
||||
// Get the current category or get parent categories of the current category
|
||||
if ($subcategories) {
|
||||
$wheres[] = " cc.parent_id = ".(int)$categoryId;
|
||||
$categoryOrdering = $this->_getCategoryOrdering();
|
||||
} else {
|
||||
$wheres[] = " cc.id= ".(int)$categoryId;
|
||||
}
|
||||
|
||||
$wheres[] = " cc.access IN (".$userLevels.")";
|
||||
$wheres[] = " cc.published = 1";
|
||||
|
||||
if ($this->getState('filter.language')) {
|
||||
$wheres[] = ' cc.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
}
|
||||
|
||||
|
||||
if ($pQ == 1) {
|
||||
// GWE MOD - to allow for access restrictions
|
||||
PluginHelper::importPlugin("phoca");
|
||||
//$dispatcher = JEventDispatcher::getInstance();
|
||||
$joins = array();
|
||||
$results = Factory::getApplication()->triggerEvent('onGetCategory', array (&$wheres, &$joins,$categoryId , $params));
|
||||
// END GWE MOD
|
||||
}
|
||||
|
||||
if ($subcategories) {
|
||||
$query = " SELECT cc.id, cc.title, cc.alias, cc.access as cataccess, cc.accessuserid as cataccessuserid, COUNT(c.id) AS numdoc"
|
||||
. " FROM #__phocadownload_categories AS cc"
|
||||
. " LEFT JOIN #__phocadownload AS c ON c.catid = cc.id AND c.published = 1 AND c.textonly = 0"
|
||||
. ($pQ == 1 ? ((count($joins)>0?( " LEFT JOIN " .implode( " LEFT JOIN ", $joins )):"")):"") // GWE MOD
|
||||
. " WHERE " . implode( " AND ", $wheres )
|
||||
. " GROUP BY cc.id, cc.title, cc.alias, cc.access, cc.accessuserid"
|
||||
. " ORDER BY ".$categoryOrdering;
|
||||
} else {
|
||||
$query = " SELECT cc.id, cc.title, cc.alias, cc.access as cataccess, cc.accessuserid as cataccessuserid, cc.description, cc.metakey, cc.metadesc, pc.title as parenttitle, cc.parent_id as parent_id, pc.alias as parentalias"
|
||||
. " FROM #__phocadownload_categories AS cc"
|
||||
. " LEFT JOIN #__phocadownload_categories AS pc ON pc.id = cc.parent_id"
|
||||
. ($pQ == 1 ? ((count($joins)>0?( " LEFT JOIN " .implode( " LEFT JOIN ", $joins )):"")):"") // GWE MOD
|
||||
. " WHERE " . implode( " AND ", $wheres )
|
||||
. " ORDER BY cc.ordering";
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
function _getFileOrdering() {
|
||||
if (empty($this->_file_ordering)) {
|
||||
$ordering = $this->getState('fileordering');
|
||||
$this->_file_ordering = PhocaDownloadOrdering::getOrderingText($ordering);
|
||||
|
||||
}
|
||||
|
||||
return $this->_file_ordering;
|
||||
}
|
||||
|
||||
public function getFileOrderingSelect() {
|
||||
if(empty($this->file_ordering_select)) {
|
||||
|
||||
$this->file_ordering_select = PhocaDownloadOrdering::renderOrderingFront($this->getState('fileordering'), 1);
|
||||
}
|
||||
|
||||
return $this->file_ordering_select;
|
||||
}
|
||||
|
||||
function _getCategoryOrdering() {
|
||||
if (empty($this->_category_ordering)) {
|
||||
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$ordering = $params->get( 'category_ordering', 1 );
|
||||
$this->_category_ordering = PhocaDownloadOrdering::getOrderingText($ordering, 2);
|
||||
|
||||
}
|
||||
return $this->_category_ordering;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
83
components/com_phocadownload/models/download.php
Normal file
83
components/com_phocadownload/models/download.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/* @package Joomla
|
||||
* @copyright Copyright (C) Open Source Matters. All rights reserved.
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
|
||||
* @extension Phoca Extension
|
||||
* @copyright Copyright (C) Jan Pavelka www.phoca.cz
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
|
||||
*/
|
||||
defined('_JEXEC') or die();
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
jimport('joomla.application.component.model');
|
||||
|
||||
|
||||
class PhocaDownloadModelDownload extends BaseDatabaseModel
|
||||
{
|
||||
var $_file = null;
|
||||
var $_category = null;
|
||||
var $_filename = null;
|
||||
var $_directlink = 0;
|
||||
|
||||
function __construct() {
|
||||
$app = Factory::getApplication();
|
||||
parent::__construct();
|
||||
$this->setState('filter.language',$app->getLanguageFilter());
|
||||
}
|
||||
|
||||
function getFile( $downloadToken) {
|
||||
if (empty($this->_file)) {
|
||||
$query = $this->_getFileQuery( $downloadToken);
|
||||
$this->_file = $this->_getList( $query, 0 , 1 );
|
||||
|
||||
// Don't display file if user has no access
|
||||
// - - - - - - - - - - - - - - -
|
||||
if (empty($this->_file)) {
|
||||
return null;
|
||||
}
|
||||
// - - - - - - - - - - - - - - - -
|
||||
}
|
||||
return $this->_file;
|
||||
}
|
||||
|
||||
function _getFileQuery( $downloadToken ) {
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$user = Factory::getUser();
|
||||
|
||||
$pQ = $params->get( 'enable_plugin_query', 0 );
|
||||
|
||||
$wheres[] = " c.approved = 1";
|
||||
$wheres[] = " c.published = 1";
|
||||
$wheres[] = " c.token = " . $this->_db->Quote($downloadToken);
|
||||
|
||||
|
||||
// Active
|
||||
$jnow = Factory::getDate();
|
||||
$now = $jnow->toSql();
|
||||
$nullDate = $this->_db->getNullDate();
|
||||
$wheres[] = ' ( c.publish_up = '.$this->_db->Quote($nullDate).' OR c.publish_up <= '.$this->_db->Quote($now).' )';
|
||||
$wheres[] = ' ( c.publish_down = '.$this->_db->Quote($nullDate).' OR c.publish_down >= '.$this->_db->Quote($now).' )';
|
||||
|
||||
if ($pQ == 1) {
|
||||
// GWE MOD - to allow for access restrictions
|
||||
PluginHelper::importPlugin("phoca");
|
||||
//$dispatcher = JEventDispatcher::getInstance();
|
||||
$joins = array();
|
||||
$results = Factory::getApplication()->triggerEvent('onGetFile', array (&$wheres, &$joins, $fileId, $params));
|
||||
// END GWE MOD
|
||||
}
|
||||
|
||||
$query = ' SELECT c.*, lc.title AS licensetitle, lc.description AS licensetext, lc.id AS licenseid'
|
||||
.' FROM #__phocadownload AS c'
|
||||
.' LEFT JOIN #__phocadownload_licenses AS lc ON lc.id = c.confirm_license'
|
||||
. ($pQ == 1 ? ((count($joins)>0?( " LEFT JOIN " .implode( " LEFT JOIN ", $joins )):"")):"") // GWE MOD
|
||||
.' WHERE ' . implode( ' AND ', $wheres )
|
||||
.' ORDER BY c.ordering';
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
?>
|
||||
177
components/com_phocadownload/models/file.php
Normal file
177
components/com_phocadownload/models/file.php
Normal file
@ -0,0 +1,177 @@
|
||||
<?php
|
||||
/*
|
||||
* @package Joomla.Framework
|
||||
* @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*
|
||||
* @component Phoca Component
|
||||
* @copyright Copyright (C) Jan Pavelka www.phoca.cz
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License version 2 or later;
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die();
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
jimport('joomla.application.component.model');
|
||||
|
||||
|
||||
class PhocaDownloadModelFile extends BaseDatabaseModel
|
||||
{
|
||||
var $_file = null;
|
||||
var $_category = null;
|
||||
var $_section = null;
|
||||
var $_filename = null;
|
||||
var $_directlink = 0;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$app = Factory::getApplication();
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->setState('filter.language',$app->getLanguageFilter());
|
||||
}
|
||||
|
||||
function getFile( $fileId, $limitstartUrl) {
|
||||
if (empty($this->_file)) {
|
||||
$query = $this->_getFileQuery( $fileId );
|
||||
$this->_file = $this->_getList( $query, 0 , 1 );
|
||||
|
||||
// Don't display file if user has no access
|
||||
// - - - - - - - - - - - - - - -
|
||||
if (empty($this->_file)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($this->_file[0]->access)) {
|
||||
$app = Factory::getApplication();
|
||||
$user = Factory::getUser();
|
||||
|
||||
|
||||
if (!in_array($this->_file[0]->access, $user->getAuthorisedViewLevels())) {
|
||||
//$app->redirect(JRoute::_('index.php?option=com_user&view=login', false), JText::_("Please login to download the file"));
|
||||
// Return URL
|
||||
$return = 'index.php?option=com_phocadownload&view=file&catid='.$this->_file[0]->catid.':'.$this->_file[0]->categoryalias
|
||||
. '&id='.$this->_file[0]->id.':'.$this->_file[0]->alias. $limitstartUrl . '&Itemid='. $app->input->get('Itemid', 0, 'int');
|
||||
$returnUrl = 'index.php?option=com_users&view=login&return='.base64_encode($return);
|
||||
$app->enqueueMessage(Text::_("COM_PHOCADOWNLOAD_PLEASE_LOGIN_DOWNLOAD_FILE"), 'error');
|
||||
$app->redirect(Route::_($returnUrl, false));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
// - - - - - - - - - - - - - - - -
|
||||
}
|
||||
return $this->_file;
|
||||
}
|
||||
|
||||
function _getFileQuery( $fileId ) {
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$user = Factory::getUser();
|
||||
$userLevels = implode (',', $user->getAuthorisedViewLevels());
|
||||
|
||||
$pQ = $params->get( 'enable_plugin_query', 0 );
|
||||
|
||||
$categoryId = 0;
|
||||
$category = $this->getCategory($fileId);
|
||||
if (isset($category[0]->id)) {
|
||||
$categoryId = $category[0]->id;
|
||||
}
|
||||
|
||||
$wheres[] = " c.catid= ".(int) $categoryId;
|
||||
$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.id = " . (int) $fileId;
|
||||
|
||||
if ($this->getState('filter.language')) {
|
||||
$wheres[] = ' c.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
$wheres[] = ' cc.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
}
|
||||
|
||||
// Active
|
||||
$jnow = Factory::getDate();
|
||||
$now = $jnow->toSql();
|
||||
$nullDate = $this->_db->getNullDate();
|
||||
$wheres[] = ' ( c.publish_up = '.$this->_db->Quote($nullDate).' OR c.publish_up <= '.$this->_db->Quote($now).' )';
|
||||
$wheres[] = ' ( c.publish_down = '.$this->_db->Quote($nullDate).' OR c.publish_down >= '.$this->_db->Quote($now).' )';
|
||||
|
||||
if ($pQ == 1) {
|
||||
// GWE MOD - to allow for access restrictions
|
||||
PluginHelper::importPlugin("phoca");
|
||||
//$dispatcher = JEventDispatcher::getInstance();
|
||||
$joins = array();
|
||||
$results = Factory::getApplication()->triggerEvent('onGetFile', array (&$wheres, &$joins, $fileId, $params));
|
||||
// END GWE MOD
|
||||
}
|
||||
|
||||
$query = ' SELECT c.*, cc.id AS categoryid, cc.title AS categorytitle, cc.alias AS categoryalias, cc.access as cataccess, cc.accessuserid as cataccessuserid, lc.title AS licensetitle, lc.description AS licensetext, lc.id AS licenseid'
|
||||
.' FROM #__phocadownload AS c'
|
||||
.' LEFT JOIN #__phocadownload_categories AS cc ON cc.id = c.catid'
|
||||
.' LEFT JOIN #__phocadownload_licenses AS lc ON lc.id = c.confirm_license'
|
||||
. ($pQ == 1 ? ((count($joins)>0?( " LEFT JOIN " .implode( " LEFT JOIN ", $joins )):"")):"") // GWE MOD
|
||||
.' WHERE ' . implode( ' AND ', $wheres )
|
||||
.' ORDER BY c.ordering';
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
function getCategory($fileId) {
|
||||
if (empty($this->_category)) {
|
||||
$query = $this->_getCategoryQuery( $fileId );
|
||||
$this->_category= $this->_getList( $query, 0, 1 );
|
||||
}
|
||||
return $this->_category;
|
||||
}
|
||||
|
||||
function _getCategoryQuery( $fileId ) {
|
||||
|
||||
$wheres = array();
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$user = Factory::getUser();
|
||||
$userLevels = implode (',', $user->getAuthorisedViewLevels());
|
||||
|
||||
$pQ = $params->get( 'enable_plugin_query', 0 );
|
||||
|
||||
|
||||
$wheres[] = " c.id= ".(int)$fileId;
|
||||
$wheres[] = " cc.access IN (".$userLevels.")";
|
||||
$wheres[] = " cc.published = 1";
|
||||
|
||||
if ($this->getState('filter.language')) {
|
||||
$wheres[] = ' c.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
$wheres[] = ' cc.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
}
|
||||
|
||||
if ($pQ == 1) {
|
||||
// GWE MOD - to allow for access restrictions
|
||||
PluginHelper::importPlugin("phoca");
|
||||
//$dispatcher = JEventDispatcher::getInstance();
|
||||
$joins = array();
|
||||
$results = Factory::getApplication()->triggerEvent('onGetCategory', array (&$wheres, &$joins, $fileId, $params));
|
||||
// END GWE MOD
|
||||
}
|
||||
|
||||
$query = " SELECT cc.id, cc.title, cc.alias, cc.description, cc.access as cataccess, cc.accessuserid as cataccessuserid, cc.parent_id as parent_id"
|
||||
. " FROM #__phocadownload_categories AS cc"
|
||||
. " LEFT JOIN #__phocadownload AS c ON c.catid = cc.id"
|
||||
. ($pQ == 1 ? ((count($joins)>0?( " LEFT JOIN " .implode( " LEFT JOIN ", $joins )):"")):"") // GWE MOD
|
||||
. " WHERE " . implode( " AND ", $wheres )
|
||||
. " ORDER BY cc.ordering";
|
||||
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
1
components/com_phocadownload/models/index.html
Normal file
1
components/com_phocadownload/models/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
82
components/com_phocadownload/models/phocadownloadlinkcat.php
Normal file
82
components/com_phocadownload/models/phocadownloadlinkcat.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/*
|
||||
* @package Joomla.Framework
|
||||
* @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*
|
||||
* @component Phoca Component
|
||||
* @copyright Copyright (C) Jan Pavelka www.phoca.cz
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License version 2 or later;
|
||||
*/
|
||||
defined('_JEXEC') or die();
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
jimport('joomla.application.component.model');
|
||||
|
||||
class PhocaDownloadModelPhocaDownloadLinkCat extends BaseDatabaseModel
|
||||
{
|
||||
//var $_data_sec;
|
||||
var $_data_cat;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
/*
|
||||
function &getDataSec() {
|
||||
if ($this->_loadDataSec()) {
|
||||
|
||||
} else {
|
||||
$this->_initDataSec();
|
||||
}
|
||||
return $this->_data_sec;
|
||||
}*/
|
||||
|
||||
function &getDataCat($sectionList) {
|
||||
if ($this->_loadDataCat($sectionList)) {
|
||||
|
||||
} else {
|
||||
$this->_initDataCat();
|
||||
}
|
||||
return $this->_data_cat;
|
||||
}
|
||||
/*
|
||||
function _loadDataSec() {
|
||||
if (empty($this->_data_sec)) {
|
||||
$query = 'SELECT s.id, s.title'
|
||||
. ' FROM #__phocadownload_sections AS s'
|
||||
. ' WHERE s.published = 1'
|
||||
. ' ORDER BY s.ordering';
|
||||
$this->_db->setQuery($query);
|
||||
$this->_data_sec = $this->_db->loadObjectList();
|
||||
return (boolean) $this->_data_sec;
|
||||
}
|
||||
return true;
|
||||
}*/
|
||||
/*
|
||||
function _loadDataCat($sectionList) {
|
||||
if (empty($this->_data_cat)) {
|
||||
$query = 'SELECT c.id, c.title, c.section'
|
||||
.' FROM #__phocadownload_categories AS c'
|
||||
.' WHERE c.section IN ( \''.$sectionList.'\' )'
|
||||
.' AND c.published = 1'
|
||||
.' ORDER BY c.ordering';
|
||||
$this->_db->setQuery($query);
|
||||
$this->_data_cat = $this->_db->loadObjectList();
|
||||
return (boolean) $this->_data_cat;
|
||||
}
|
||||
return true;
|
||||
}*/
|
||||
/*
|
||||
function _initDataSec() {
|
||||
if (empty($this->_data_sec)) {
|
||||
return (boolean) array();
|
||||
}
|
||||
return true;
|
||||
}*/
|
||||
function _initDataCat() {
|
||||
if (empty($this->_data_cat)) {
|
||||
return (boolean) array();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
221
components/com_phocadownload/models/phocadownloadlinkfile.php
Normal file
221
components/com_phocadownload/models/phocadownloadlinkfile.php
Normal file
@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/*
|
||||
* @package Joomla 1.5
|
||||
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
|
||||
*
|
||||
* @component Phoca Component
|
||||
* @copyright Copyright (C) Jan Pavelka www.phoca.cz
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
|
||||
*/
|
||||
defined('_JEXEC') or die();
|
||||
use Joomla\CMS\Pagination\Pagination;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Pagination\PaginationObject;
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Factory;
|
||||
jimport('joomla.application.component.model');
|
||||
use Joomla\String\StringHelper;
|
||||
|
||||
// CUSTOM PAGINATON
|
||||
class PhocaDownloadViewPhocaDownloadLinkFilePagination extends Pagination
|
||||
{
|
||||
protected function _buildDataObject()
|
||||
{
|
||||
$data = new stdClass;
|
||||
|
||||
$uri = Uri::getInstance();
|
||||
$uriS = $uri->toString();
|
||||
|
||||
// Build the additional URL parameters string.
|
||||
$params = '';
|
||||
|
||||
if (!empty($this->additionalUrlParams))
|
||||
{
|
||||
foreach ($this->additionalUrlParams as $key => $value)
|
||||
{
|
||||
$params .= '&' . $key . '=' . $value;
|
||||
}
|
||||
}
|
||||
|
||||
$data->all = new PaginationObject(Text::_('JLIB_HTML_VIEW_ALL'), $this->prefix);
|
||||
|
||||
if (!$this->viewall)
|
||||
{
|
||||
$data->all->base = '0';
|
||||
$data->all->link = $uriS . '' .$params . '&' . $this->prefix . 'limitstart=';
|
||||
}
|
||||
|
||||
// Set the start and previous data objects.
|
||||
$data->start = new PaginationObject(Text::_('JLIB_HTML_START'), $this->prefix);
|
||||
$data->previous = new PaginationObject(Text::_('JPREV'), $this->prefix);
|
||||
|
||||
if ($this->pagesCurrent > 1)
|
||||
{
|
||||
$page = ($this->pagesCurrent - 2) * $this->limit;
|
||||
|
||||
// Set the empty for removal from route
|
||||
// @to do remove code: $page = $page == 0 ? '' : $page;
|
||||
|
||||
|
||||
|
||||
$data->start->base = '0';
|
||||
$data->start->link = $uriS . '' . $params . '&' . $this->prefix . 'limitstart=0';
|
||||
$data->previous->base = $page;
|
||||
$data->previous->link = $uriS . '' .$params . '&' . $this->prefix . 'limitstart=' . $page;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Set the next and end data objects.
|
||||
$data->next = new PaginationObject(Text::_('JNEXT'), $this->prefix);
|
||||
$data->end = new PaginationObject(Text::_('JLIB_HTML_END'), $this->prefix);
|
||||
|
||||
if ($this->pagesCurrent < $this->pagesTotal)
|
||||
{
|
||||
$next = $this->pagesCurrent * $this->limit;
|
||||
$end = ($this->pagesTotal - 1) * $this->limit;
|
||||
|
||||
$data->next->base = $next;
|
||||
$data->next->link = $uriS . '' .$params . '&' . $this->prefix . 'limitstart=' . $next;
|
||||
$data->end->base = $end;
|
||||
$data->end->link = $uriS . '' .$params . '&' . $this->prefix . 'limitstart=' . $end;
|
||||
}
|
||||
|
||||
$data->pages = array();
|
||||
$stop = $this->pagesStop;
|
||||
|
||||
for ($i = $this->pagesStart; $i <= $stop; $i++)
|
||||
{
|
||||
$offset = ($i - 1) * $this->limit;
|
||||
|
||||
$data->pages[$i] = new PaginationObject($i, $this->prefix);
|
||||
|
||||
if ($i != $this->pagesCurrent || $this->viewall)
|
||||
{
|
||||
$data->pages[$i]->base = $offset;
|
||||
$data->pages[$i]->link = $uriS . '' .$params . '&' . $this->prefix . 'limitstart=' . $offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
$data->pages[$i]->active = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
class PhocaDownloadModelPhocaDownloadLinkFile extends BaseDatabaseModel
|
||||
{
|
||||
var $_data = null;
|
||||
var $_total = null;
|
||||
var $_pagination = null;
|
||||
var $_context = 'com_phocadownload.phocadownloadlinkfile';
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$app = Factory::getApplication();
|
||||
// Get the pagination request variables
|
||||
$limit = $app->getUserStateFromRequest( $this->_context.'.list.limit', 'limit', $app->get('list_limit'), 'int' );
|
||||
$limitstart = $app->getUserStateFromRequest( $this->_context.'.limitstart', 'limitstart', 0, 'int' );
|
||||
// In case limit has been changed, adjust limitstart accordingly
|
||||
$limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
|
||||
|
||||
|
||||
$this->setState('limit', $limit);
|
||||
$this->setState('limitstart', $limitstart);
|
||||
}
|
||||
|
||||
function getData() {
|
||||
if (empty($this->_data)) {
|
||||
$query = $this->_buildQuery();
|
||||
$this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
|
||||
}
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
function getTotal() {
|
||||
if (empty($this->_total)) {
|
||||
$query = $this->_buildQuery();
|
||||
$this->_total = $this->_getListCount($query);
|
||||
}
|
||||
return $this->_total;
|
||||
}
|
||||
|
||||
function getPagination() {
|
||||
if (empty($this->_pagination)) {
|
||||
jimport('joomla.html.pagination');
|
||||
$this->_pagination = new PhocaDownloadViewPhocaDownloadLinkFilePagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
|
||||
}
|
||||
return $this->_pagination;
|
||||
}
|
||||
|
||||
function _buildQuery() {
|
||||
$where = $this->_buildContentWhere();
|
||||
$orderby = $this->_buildContentOrderBy();
|
||||
|
||||
$query = ' SELECT a.*, cc.title AS categorytitle, ag.title AS access_level '
|
||||
. ' FROM #__phocadownload AS a '
|
||||
. ' LEFT JOIN #__phocadownload_categories AS cc ON cc.id = a.catid '
|
||||
//. ' LEFT JOIN #__phocadownload_sections AS s ON s.id = a.sectionid '
|
||||
. ' LEFT JOIN #__viewlevels AS ag ON ag.id = a.access '
|
||||
. ' LEFT JOIN #__users AS u ON u.id = a.checked_out '
|
||||
. $where
|
||||
. $orderby
|
||||
;
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
function _buildContentOrderBy() {
|
||||
$app = Factory::getApplication();
|
||||
$filter_order = $app->getUserStateFromRequest( $this->_context.'.filter_order', 'filter_order', 'a.ordering','cmd' );
|
||||
$filter_order_Dir = $app->getUserStateFromRequest( $this->_context.'.filter_order_Dir', 'filter_order_Dir', '', 'word' );
|
||||
|
||||
if ($filter_order == 'a.ordering'){
|
||||
$orderby = ' ORDER BY categorytitle, a.ordering '.$filter_order_Dir;
|
||||
} else {
|
||||
$orderby = ' ORDER BY '.$filter_order.' '.$filter_order_Dir.', categorytitle, a.ordering ';
|
||||
}
|
||||
return $orderby;
|
||||
}
|
||||
|
||||
function _buildContentWhere() {
|
||||
$app = Factory::getApplication();
|
||||
$filter_published = $app->getUserStateFromRequest( $this->_context.'.filter_published', 'filter_published', '', 'word' );
|
||||
$filter_catid = $app->getUserStateFromRequest( $this->_context.'.catid','catid',0, 'int' );
|
||||
//$filter_sectionid = $app->getUserStateFromRequest( $this->_context.'.filter_sectionid', 'filter_sectionid', 0, 'int' );
|
||||
$filter_order = $app->getUserStateFromRequest( $this->_context.'.filter_order', 'filter_order', 'a.ordering', 'cmd' );
|
||||
$filter_order_Dir = $app->getUserStateFromRequest( $this->_context.'.filter_order_Dir', 'filter_order_Dir', '', 'word' );
|
||||
$search = $app->getUserStateFromRequest( $this->_context.'.search','search','','string' );
|
||||
$search = StringHelper::strtolower( $search );
|
||||
|
||||
$where = array();
|
||||
|
||||
if ($filter_catid > 0) {
|
||||
$where[] = 'a.catid = '.(int) $filter_catid;
|
||||
}
|
||||
if ($search) {
|
||||
$where[] = 'LOWER(a.title) LIKE '.$this->_db->Quote('%'.$search.'%');
|
||||
}
|
||||
if ( $filter_published ) {
|
||||
if ( $filter_published == 'P' ) {
|
||||
$where[] = 'a.published = 1';
|
||||
} else if ($filter_published == 'U' ) {
|
||||
$where[] = 'a.published = 0';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$where[] = 'a.published = 1';
|
||||
$where[] = 'a.approved = 1';
|
||||
$where[] = 'a.textonly <> 1';
|
||||
|
||||
$where = ( count( $where ) ? ' WHERE '. implode( ' AND ', $where ) : '' );
|
||||
return $where;
|
||||
}
|
||||
}
|
||||
?>
|
||||
174
components/com_phocadownload/models/play.php
Normal file
174
components/com_phocadownload/models/play.php
Normal file
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
/*
|
||||
* @package Joomla 1.5
|
||||
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
|
||||
*
|
||||
* @component Phoca Component
|
||||
* @copyright Copyright (C) Jan Pavelka www.phoca.cz
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die();
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
jimport('joomla.application.component.model');
|
||||
|
||||
class PhocaDownloadModelPlay extends BaseDatabaseModel
|
||||
{
|
||||
var $_file = null;
|
||||
var $_category = null;
|
||||
var $_section = null;
|
||||
var $_filename = null;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$app = Factory::getApplication();
|
||||
parent::__construct();
|
||||
$this->setState('filter.language',$app->getLanguageFilter());
|
||||
|
||||
}
|
||||
|
||||
function getFile( $fileId) {
|
||||
if (empty($this->_file)) {
|
||||
$query = $this->_getFileQuery( $fileId );
|
||||
$this->_file = $this->_getList( $query, 0 , 1 );
|
||||
|
||||
/* // Don't display file if user has no access
|
||||
// - - - - - - - - - - - - - - -
|
||||
if (empty($this->_file)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($this->_file[0]->access)) {
|
||||
if ($aid !== null) {
|
||||
if ($this->_file[0]->access > (int) $aid) {
|
||||
$app->redirect(Route::_('index.php?option=com_users&view=login', false), Text::_("Please login to download the file"));
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
// - - - - - - - - - - - - - - - -*/
|
||||
}
|
||||
return $this->_file;
|
||||
}
|
||||
|
||||
function _getFileQuery( $fileId ) {
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$categoryId = 0;
|
||||
$category = $this->getCategory($fileId);
|
||||
if (isset($category[0]->id)) {
|
||||
$categoryId = $category[0]->id;
|
||||
}
|
||||
|
||||
$pQ = $params->get( 'enable_plugin_query', 0 );
|
||||
|
||||
$wheres[] = " c.catid= ".(int) $categoryId;
|
||||
$wheres[] = " c.catid= cc.id";
|
||||
/*if ($aid !== null) {
|
||||
|
||||
// Should be not displayed, only in case user will add direct url
|
||||
// IF unaccessible file = 1 then display unaccessible file for all
|
||||
// IF unaccessible file = 0 then display it only for them who have access to this file
|
||||
$wheres[] = '( (unaccessible_file = 1 ) OR (unaccessible_file = 0 AND c.access <= ' . (int) $aid.') )';
|
||||
$wheres[] = '( (unaccessible_file = 1 ) OR (unaccessible_file = 0 AND cc.access <= ' . (int) $aid.') )';
|
||||
//$wheres[] = "c.access <= " . (int) $aid;
|
||||
//$wheres[] = "cc.access <= " . (int) $aid;
|
||||
}*/
|
||||
$wheres[] = " c.published = 1";
|
||||
$wheres[] = " c.approved = 1";
|
||||
$wheres[] = " cc.published = 1";
|
||||
|
||||
$wheres[] = " c.id = " . (int) $fileId;
|
||||
|
||||
if ($this->getState('filter.language')) {
|
||||
$wheres[] = ' c.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
$wheres[] = ' cc.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
}
|
||||
|
||||
// Active
|
||||
$jnow = Factory::getDate();
|
||||
$now = $jnow->toSql();
|
||||
$nullDate = $this->_db->getNullDate();
|
||||
$wheres[] = ' ( c.publish_up = '.$this->_db->Quote($nullDate).' OR c.publish_up <= '.$this->_db->Quote($now).' )';
|
||||
$wheres[] = ' ( c.publish_down = '.$this->_db->Quote($nullDate).' OR c.publish_down >= '.$this->_db->Quote($now).' )';
|
||||
|
||||
|
||||
|
||||
if ($pQ == 1) {
|
||||
// GWE MOD - to allow for access restrictions
|
||||
PluginHelper::importPlugin("phoca");
|
||||
//$dispatcher = JEventDispatcher::getInstance();
|
||||
$joins = array();
|
||||
$results = Factory::getApplication()->triggerEvent('onGetFile', array (&$wheres, &$joins, $fileId, $params));
|
||||
// END GWE MOD
|
||||
}
|
||||
|
||||
$query = ' SELECT c.*, cc.id AS categoryid, cc.title AS categorytitle, cc.alias AS categoryalias, cc.access as cataccess, cc.accessuserid as cataccessuserid, lc.title AS licensetitle, lc.description AS licensetext'
|
||||
.' FROM #__phocadownload AS c'
|
||||
.' LEFT JOIN #__phocadownload_categories AS cc ON cc.id = c.catid'
|
||||
.' LEFT JOIN #__phocadownload_licenses AS lc ON lc.id = c.confirm_license'
|
||||
. ($pQ == 1 ? ((count($joins)>0?( " LEFT JOIN " .implode( " LEFT JOIN ", $joins )):"")):"") // GWE MOD
|
||||
.' WHERE ' . implode( ' AND ', $wheres )
|
||||
.' ORDER BY c.ordering';
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
function getCategory($fileId) {
|
||||
|
||||
if (empty($this->_category)) {
|
||||
$query = $this->_getCategoryQuery( $fileId );
|
||||
$this->_category= $this->_getList( $query, 0, 1 );
|
||||
}
|
||||
return $this->_category;
|
||||
}
|
||||
|
||||
function _getCategoryQuery( $fileId ) {
|
||||
|
||||
$wheres = array();
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$user = Factory::getUser();
|
||||
$userLevels = implode (',', $user->getAuthorisedViewLevels());
|
||||
|
||||
$pQ = $params->get( 'enable_plugin_query', 0 );
|
||||
|
||||
$wheres[] = " c.id= ".(int)$fileId;
|
||||
$wheres[] = " cc.access IN (".$userLevels.")";
|
||||
$wheres[] = " cc.published = 1";
|
||||
|
||||
if ($this->getState('filter.language')) {
|
||||
$wheres[] = ' c.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
$wheres[] = ' cc.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
|
||||
}
|
||||
|
||||
if ($pQ == 1) {
|
||||
// GWE MOD - to allow for access restrictions
|
||||
PluginHelper::importPlugin("phoca");
|
||||
//$dispatcher = JEventDispatcher::getInstance();
|
||||
$joins = array();
|
||||
$results = Factory::getApplication()->triggerEvent('onGetCategory', array (&$wheres, &$joins,$categoryId, $params));
|
||||
// END GWE MOD
|
||||
}
|
||||
|
||||
$query = " SELECT cc.id, cc.title, cc.alias, cc.image, cc.image_position, cc.description"
|
||||
. " FROM #__phocadownload_categories AS cc"
|
||||
. " LEFT JOIN #__phocadownload AS c ON c.catid = cc.id"
|
||||
. ($pQ == 1 ? ((count($joins)>0?( " LEFT JOIN " .implode( " LEFT JOIN ", $joins )):"")):"") // GWE MOD
|
||||
. " WHERE " . implode( " AND ", $wheres )
|
||||
. " ORDER BY cc.ordering";
|
||||
return $query;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
57
components/com_phocadownload/models/ratingfilea.php
Normal file
57
components/com_phocadownload/models/ratingfilea.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/*
|
||||
* @package Joomla.Framework
|
||||
* @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*
|
||||
* @component Phoca Component
|
||||
* @copyright Copyright (C) Jan Pavelka www.phoca.cz
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License version 2 or later;
|
||||
*/
|
||||
defined('_JEXEC') or die();
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
jimport('joomla.application.component.model');
|
||||
|
||||
|
||||
class PhocaDownloadModelRatingFileA extends BaseDatabaseModel
|
||||
{
|
||||
|
||||
function rate($data) {
|
||||
$row = $this->getTable('phocadownloadfilevotes');
|
||||
|
||||
if (!$row->bind($data)) {
|
||||
//throw new Exception($this->_db->getError());
|
||||
$this->setError($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
$row->date = gmdate('Y-m-d H:i:s');
|
||||
|
||||
$row->published = 1;
|
||||
|
||||
if (!$row->id) {
|
||||
$where = 'fileid = ' . (int) $row->fileid ;
|
||||
$row->ordering = $row->getNextOrder( $where );
|
||||
}
|
||||
|
||||
if (!$row->check()) {
|
||||
//throw new Exception($this->_db->getError());
|
||||
$this->setError($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$row->store()) {
|
||||
//throw new Exception($this->_db->getError());
|
||||
$this->setError($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update the Vote Statistics
|
||||
if (!PhocaDownloadRate::updateVoteStatisticsFile( $data['fileid'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
692
components/com_phocadownload/models/user.php
Normal file
692
components/com_phocadownload/models/user.php
Normal file
@ -0,0 +1,692 @@
|
||||
<?php
|
||||
/*
|
||||
* @package Joomla 1.5
|
||||
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
|
||||
*
|
||||
* @component Phoca Download
|
||||
* @copyright Copyright (C) Jan Pavelka www.phoca.cz
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die();
|
||||
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Pagination\Pagination;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Session\Session;
|
||||
use Joomla\CMS\Client\ClientHelper;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Filesystem\File;
|
||||
use Joomla\CMS\Filesystem\Path;
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
jimport('joomla.application.component.model');
|
||||
jimport( 'joomla.filesystem.folder' );
|
||||
jimport( 'joomla.filesystem.file' );
|
||||
use Joomla\String\StringHelper;
|
||||
|
||||
class PhocaDownloadModelUser extends BaseDatabaseModel
|
||||
{
|
||||
var $_data_files = null;
|
||||
var $_total_files = null;
|
||||
var $_pagination_files = null;
|
||||
var $_context_files = 'com_phocadownload.phocadownloaduserfiles';
|
||||
|
||||
protected $event_before_save = null;
|
||||
protected $event_after_save = null;
|
||||
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
//if (isset($config['event_before_save'])) {
|
||||
// $this->event_before_save = $config['event_before_save'];
|
||||
//} elseif (empty($this->event_before_save)) {
|
||||
$this->event_before_save = 'onContentBeforeSave';
|
||||
//}
|
||||
$this->event_after_save = 'onContentAfterSave';
|
||||
|
||||
$app = Factory::getApplication();
|
||||
// SubCategory
|
||||
$limit_files = $app->getUserStateFromRequest( $this->_context_files.'.list.limit', 'limit', 20, 'int' );
|
||||
$limitstart_files = $app->input->get('limitstart', 0, 'int');
|
||||
$limitstart_files = ($limit_files != 0 ? (floor($limitstart_files / $limit_files) * $limit_files) : 0);
|
||||
$this->setState($this->_context_files.'.list.limit', $limit_files);
|
||||
$this->setState($this->_context_files.'.list.limitstart', $limitstart_files);
|
||||
|
||||
}
|
||||
|
||||
function getDataFiles($userId) {
|
||||
if (empty($this->_data_files)) {
|
||||
$query = $this->_buildQueryFiles($userId);
|
||||
$this->_data_files = $this->_getList($query, $this->getState($this->_context_files.'.list.limitstart'), $this->getState($this->_context_files.'.list.limit'));
|
||||
|
||||
}
|
||||
return $this->_data_files;
|
||||
}
|
||||
|
||||
function getTotalFiles($userId) {
|
||||
if (empty($this->_total_files)) {
|
||||
$query = $this->_buildQueryFiles($userId);
|
||||
$this->_total_files = $this->_getListCount($query);
|
||||
}
|
||||
return $this->_total_files;
|
||||
}
|
||||
|
||||
function getPaginationFiles($userId) {
|
||||
if (empty($this->_pagination_files)) {
|
||||
jimport('joomla.html.pagination');
|
||||
$this->_pagination_files = new Pagination( $this->getTotalFiles($userId), $this->getState($this->_context_files.'.list.limitstart'), $this->getState($this->_context_files.'.list.limit') );
|
||||
}
|
||||
return $this->_pagination_files;
|
||||
}
|
||||
|
||||
function _buildQueryFiles($userId) {
|
||||
$where = $this->_buildContentWhereFiles($userId);
|
||||
$orderby = $this->_buildContentOrderByFiles();
|
||||
|
||||
$query = ' SELECT a.*, cc.title AS categorytitle, u.name AS editor, ag.title AS access_level, us.id AS ownerid, us.username AS ownername '
|
||||
. ' FROM #__phocadownload AS a '
|
||||
. ' LEFT JOIN #__phocadownload_categories AS cc ON cc.id = a.catid'
|
||||
. ' LEFT JOIN #__viewlevels AS ag ON ag.id = a.access'
|
||||
. ' LEFT JOIN #__users AS u ON u.id = a.checked_out'
|
||||
. ' LEFT JOIN #__users AS us ON us.id = a.owner_id'
|
||||
. $where
|
||||
. $orderby;
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
function _buildContentOrderByFiles() {
|
||||
$app = Factory::getApplication();
|
||||
$filter_order = $app->getUserStateFromRequest( $this->_context_files.'.filter_order', 'filter_order', 'a.ordering', 'cmd' );
|
||||
$filter_order_Dir = $app->getUserStateFromRequest( $this->_context_files.'.filter_order_Dir', 'filter_order_Dir', '', 'word' );
|
||||
|
||||
if ($filter_order == 'a.ordering'){
|
||||
$orderby = ' ORDER BY categorytitle, a.ordering '.$filter_order_Dir;
|
||||
} else {
|
||||
$orderby = ' ORDER BY '.$filter_order.' '.$filter_order_Dir.' , categorytitle, a.ordering ';
|
||||
}
|
||||
return $orderby;
|
||||
}
|
||||
|
||||
function _buildContentWhereFiles($userId) {
|
||||
$app = Factory::getApplication();
|
||||
$filter_published = $app->getUserStateFromRequest( $this->_context_files.'.filter_published','filter_published','', 'word' );
|
||||
$filter_catid = $app->getUserStateFromRequest( $this->_context_files.'.catid','catid',0,'int' );
|
||||
//$filter_sectionid = $app->getUserStateFromRequest( $this->_context_files.'.filter_sectionid', 'filter_sectionid', 0, 'int' );
|
||||
$filter_order = $app->getUserStateFromRequest( $this->_context_files.'.filter_order','filter_order','a.ordering','cmd' );
|
||||
$filter_order_Dir = $app->getUserStateFromRequest( $this->_context_files.'.filter_order_Dir','filter_order_Dir_files', '', 'word' );
|
||||
$search = $app->getUserStateFromRequest( $this->_context_files.'.search', 'search', '', 'string' );
|
||||
$search = StringHelper::strtolower( $search );
|
||||
|
||||
$where = array();
|
||||
|
||||
$where[] = 'a.owner_id = '.(int)$userId;
|
||||
$where[] = 'a.owner_id > 0'; // Ignore -1
|
||||
|
||||
if ($filter_catid > 0) {
|
||||
$where[] = 'a.catid = '.(int) $filter_catid;
|
||||
}
|
||||
if ($search) {
|
||||
$where[] = 'LOWER(a.title) LIKE '.$this->_db->Quote('%'.$search.'%');
|
||||
}
|
||||
if ( $filter_published ) {
|
||||
if ( $filter_published == 'P' ) {
|
||||
$where[] = 'a.published = 1';
|
||||
} else if ($filter_published == 'U' ) {
|
||||
$where[] = 'a.published = 0';
|
||||
}
|
||||
}
|
||||
//if ( $filter_sectionid ) {
|
||||
// $where[] = 'cc.section = '.(int)$filter_sectionid;
|
||||
//}
|
||||
$where = ( count( $where ) ? ' WHERE '. implode( ' AND ', $where ) : '' );
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Add Image
|
||||
*/
|
||||
/*
|
||||
function storefile($data, $return, $edit = false) {
|
||||
|
||||
if (!$edit) {
|
||||
//If this file doesn't exists don't save it
|
||||
if (!phocadownloadFile::existsFileOriginal($data['filename'])) {
|
||||
$this->set Error('File not exists');
|
||||
return false;
|
||||
}
|
||||
|
||||
$data['imgorigsize'] = phocadownloadFile::getFileSize($data['filename'], 0);
|
||||
|
||||
//If there is no title and no alias, use filename as title and alias
|
||||
if (!isset($data['title']) || (isset($data['title']) && $data['title'] == '')) {
|
||||
$data['title'] = phocadownloadFile::getTitleFromFile($data['filename']);
|
||||
}
|
||||
|
||||
if (!isset($data['alias']) || (isset($data['alias']) && $data['alias'] == '')) {
|
||||
$data['alias'] = phocadownloadFile::getTitleFromFile($data['filename']);
|
||||
}
|
||||
|
||||
//clean alias name (no bad characters)
|
||||
$data['alias'] = phocadownloadText::getAliasName($data['alias']);
|
||||
|
||||
} else {
|
||||
$data['alias'] = phocadownloadText::getAliasName($data['title']);
|
||||
}
|
||||
|
||||
$row = $this->getTable('phocadownload');
|
||||
|
||||
|
||||
if(isset($data['id']) && $data['id'] > 0) {
|
||||
if (!$row->load($data['id'])) {
|
||||
throw new Exception($this->_db->getErrorMsg(), 500);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Bind the form fields to the Phoca gallery table
|
||||
if (!$row->bind($data)) {
|
||||
throw new Exception($this->_db->getErrorMsg(), 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the timestamp for the date
|
||||
$row->date = gmdate('Y-m-d H:i:s');
|
||||
|
||||
// if new item, order last in appropriate group
|
||||
if (!$row->id) {
|
||||
$where = 'catid = ' . (int) $row->catid ;
|
||||
$row->ordering = $row->getNextOrder( $where );
|
||||
}
|
||||
|
||||
// Make sure the Phoca gallery table is valid
|
||||
if (!$row->check()) {
|
||||
throw new Exception($this->_db->getErrorMsg(), 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the Phoca gallery table to the database
|
||||
if (!$row->store()) {
|
||||
throw new Exception($this->_db->getErrorMsg(), 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$edit) {
|
||||
//Create thumbnail small, medium, large
|
||||
$returnFrontMessage = phocadownloadFileThumbnail::getOrCreateThumbnail($row->filename, $return, 1, 1, 1, 1);
|
||||
|
||||
if ($returnFrontMessage == 'Success') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (isset($row->id)) {
|
||||
return $row->id;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
function singleFileUpload(&$errUploadMsg, $file, $post) {
|
||||
|
||||
$app = Factory::getApplication();;
|
||||
Session::checkToken( 'request' ) or jexit( 'Invalid Token' );
|
||||
jimport('joomla.client.helper');
|
||||
$user = Factory::getUser();
|
||||
$ftp = ClientHelper::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 = ComponentHelper::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 = Text::_('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'] = File::makeSafe($file['name']);
|
||||
}
|
||||
|
||||
if($file['tmp_name'] == '') {
|
||||
$errUploadMsg = Text::_("COM_PHOCADOWNLOAD_ERROR_SERVER_NOT_ABLE_TO_STORE_FILE_TEMP_FOLDER");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($file['name'])) {
|
||||
$filepath = Path::clean($path['orig_abs_user_upload']. '/'. $userFolder . '/'.$file['name']);
|
||||
$filepathUserFolder = Path::clean($path['orig_abs_user_upload']. '/'. $userFolder);
|
||||
if (!PhocaDownloadFileUpload::canUpload( $file, $errUploadMsg, 'file', 2 )) {
|
||||
|
||||
if ($errUploadMsg == 'COM_PHOCADOWNLOAD_WARNUSERFILESTOOLARGE') {
|
||||
$errUploadMsg = Text::_($errUploadMsg) . ' ('.PhocaDownloadFile::getFileSizeReadable($file['size']).')';
|
||||
} else {
|
||||
$errUploadMsg = Text::_($errUploadMsg);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (File::exists($filepath) && $overwriteExistingFiles == 0) {
|
||||
$errUploadMsg = Text::_("COM_PHOCADOWNLOAD_FILE_ALREADY_EXISTS");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Overwrite file and add no new item to database
|
||||
$fileExists = 0;
|
||||
if (File::exists($filepath) && $overwriteExistingFiles == 1) {
|
||||
$fileExists = 1;
|
||||
}
|
||||
|
||||
if (!File::upload($file['tmp_name'], $filepath, false, true)) {
|
||||
$errUploadMsg = Text::_("COM_PHOCADOWNLOAD_UNABLE_TO_UPLOAD_FILE");
|
||||
return false;
|
||||
} else {
|
||||
|
||||
// Saving file name into database with relative path
|
||||
if (!File::exists($filepathUserFolder . '/' ."index.html")) {
|
||||
$data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>";
|
||||
File::write($filepathUserFolder . '/' ."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 = Path::clean($path['orig_abs_user_upload_pap']. '/'. $userFolder . '/'.$file['namepap']);
|
||||
$filepathUserFolderPAP = Path::clean($path['orig_abs_user_upload_pap']. '/'. $userFolder);
|
||||
|
||||
if ($canPlay || $canPreview) {
|
||||
|
||||
// 1. UPLOAD - this is real upload to folder
|
||||
// 2. STORE - this is storing info to database (e.g. download and play/preview files are identical, then there will be no copy of the file but only storing DB info
|
||||
$uploadPAP = 1;// upload file for preview and play
|
||||
$storePAP = 0;
|
||||
|
||||
|
||||
// 1. Care about upload
|
||||
if (File::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 (File::exists($filepathPAP) && $overwriteExistingFiles == 1) {
|
||||
$fileExistsPAP = 1;
|
||||
}
|
||||
|
||||
if ($uploadPAP == 0) {
|
||||
|
||||
} else {
|
||||
if (!Folder::exists($filepathUserFolderPAP)) {
|
||||
if (Folder::create($filepathUserFolderPAP)) {
|
||||
$data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>";
|
||||
File::write($filepathUserFolderPAP . '/' ."index.html", $data);
|
||||
}
|
||||
// else {
|
||||
//$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_CREATE_FOLDER");
|
||||
//return false;
|
||||
//}
|
||||
}
|
||||
|
||||
if ($filepath === $filepathPAP) {
|
||||
// Don't try to copy the same file to the same file (including path) because you get error
|
||||
$storePAP = 1;
|
||||
} else if (!File::copy($filepath, $filepathPAP)) {
|
||||
|
||||
//$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_UPLOAD_FILE");
|
||||
//return false;
|
||||
} else {
|
||||
$storePAP = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Care about store
|
||||
if ($filepath === $filepathPAP) {
|
||||
|
||||
// SPECIFIC CASE - administrator set the download folder the same like preview/play folder
|
||||
// - in such case, there will be no copy because both files including path are identical
|
||||
// - but we still write the info about play/preview into database
|
||||
// - so no set uploadPAP to 0
|
||||
$storePAP = 1;
|
||||
}
|
||||
|
||||
if ($storePAP == 1) {
|
||||
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 = Text::_("COM_PHOCADOWNLOAD_WARNFILETYPE");
|
||||
$redirectUrl = $return;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$errUploadMsg = Text::_("COM_PHOCADOWNLOAD_NOT_AUTHORISED_TO_UPLOAD");
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
function _save($data, $filename, &$errSaveMsg, $fileExists = 0) {
|
||||
|
||||
$user = Factory::getUser();
|
||||
$app = Factory::getApplication();
|
||||
|
||||
$paramsC = ComponentHelper::getParams('com_phocadownload') ;
|
||||
$default_access = $paramsC->get( 'default_access', 1 );
|
||||
$frontend_run_events = $paramsC->get( 'frontend_run_events', 0 );
|
||||
$fileId = false;
|
||||
if ($fileExists == 1) {
|
||||
// We not only owerwrite the file but we must update it
|
||||
if (isset($filename) && $filename != '') {
|
||||
|
||||
$db = Factory::getDBO();
|
||||
|
||||
$query = 'SELECT a.id AS id'
|
||||
.' FROM #__phocadownload AS a'
|
||||
.' WHERE a.filename = '.$db->Quote($filename);
|
||||
|
||||
$db->setQuery($query, 0, 1);
|
||||
$fileId = $db->loadObject();
|
||||
|
||||
/*if (!$db->query()) {
|
||||
throw new Exception($db->getErrorMsg(), 500);
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
$row = $this->getTable('phocadownload');
|
||||
|
||||
$isNew = true;
|
||||
if (isset($fileId->id) && (int)$fileId->id > 0) {
|
||||
$data['id'] = (int)$fileId->id;
|
||||
$isNew = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$data['filesize'] = PhocaDownloadFile::getFileSize($filename, 0);
|
||||
|
||||
$data['userid'] = $user->id;
|
||||
$data['author_email'] = $data['email'];
|
||||
$data['author_url'] = $data['website'];
|
||||
$data['access'] = $default_access;
|
||||
$data['token'] = PhocaDownloadUtils::getToken($data['title'].$filename);
|
||||
//$data['token'] = PhocaDownloadUtils::getToken($data['title'].$data['filename']);
|
||||
|
||||
// Bind the form fields to the Phoca gallery table
|
||||
if (!$row->bind($data)) {
|
||||
//throw new Exception($this->_db->getError());
|
||||
$this->setError($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Create the timestamp for the date
|
||||
//$row->date = gmdate('Y-m-d H:i:s');
|
||||
//$row->publish_up = gmdate('Y-m-d H:i:s');
|
||||
//$jnow =JFactory::getDate();
|
||||
/*$jnowU = $jnow->toUnix();
|
||||
if (isset($jnowU)) {
|
||||
$jnowU = (int)$jnowU - 2; // to not display pending because of 1 second
|
||||
}*/
|
||||
|
||||
$unow = time();
|
||||
$unow = $unow - 2;//Frontend will display pending if standard $jnow->toSql(); will be used
|
||||
$jnow = Factory::getDate($unow);// the class JDate construct works with unix date
|
||||
$now = $jnow->toSql();
|
||||
|
||||
$row->date = $now;
|
||||
$row->publish_up = $now; //date('Y-m-d H:i:s', $jnowU);
|
||||
//$row->publish_down = null;
|
||||
$row->publish_down = '0000-00-00 00:00:00';
|
||||
$row->filename = $filename;
|
||||
$row->catid = $data['catidfiles'];
|
||||
|
||||
// Lang
|
||||
$userLang = PhocaDownloadUser::getUserLang();
|
||||
$row->language = $userLang['lang'];
|
||||
|
||||
|
||||
// if new item, order last in appropriate group
|
||||
if (!$row->id) {
|
||||
$where = 'catid = ' . (int) $row->catid ;
|
||||
$row->ordering = $row->getNextOrder( $where );
|
||||
}
|
||||
|
||||
// Make sure the Phoca gallery table is valid
|
||||
if (!$row->check()) {
|
||||
//throw new Exception($this->_db->getError());
|
||||
$this->setError($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
PluginHelper::importPlugin($this->events_map['save']);
|
||||
$result = $app->triggerEvent($this->event_before_save, array($this->option.'.'.$this->name, $row, $isNew, $data));
|
||||
if (\in_array(false, $result, true)) {
|
||||
$this->setError($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the data.
|
||||
/*if (!$table->store()) {
|
||||
throw new Exception($table->getError(), 500);
|
||||
return false;
|
||||
}*/
|
||||
|
||||
// Trigger the before save event.
|
||||
if ($frontend_run_events == 1) {
|
||||
PluginHelper::importPlugin('content');
|
||||
$context = $this->option . '.' . 'file';// com_phocadownload.file
|
||||
$table = $row;
|
||||
$dispatcher = $this->getDispatcher();
|
||||
|
||||
// Before Save
|
||||
$beforeSaveEvent = new Joomla\CMS\Event\Model\BeforeSaveEvent($this->event_before_save, [
|
||||
'context' => $context,
|
||||
'subject' => $table,
|
||||
'isNew' => $isNew,
|
||||
'data' => $data,
|
||||
]);
|
||||
$result = $dispatcher->dispatch($this->event_before_save, $beforeSaveEvent)->getArgument('result', []);
|
||||
//$result = $app->triggerEvent($this->event_before_save, array($context, $row, $isNew, $data));
|
||||
|
||||
|
||||
/*if (\in_array(false, $result, true)) {
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
|
||||
// Store the Phoca gallery table to the database
|
||||
if (!$row->store()) {
|
||||
//throw new Exception($this->_db->getError());
|
||||
$this->setError($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($frontend_run_events == 1) {
|
||||
// After Save
|
||||
$afterSaveEvent = new Joomla\CMS\Event\Model\AfterSaveEvent($this->event_after_save, [
|
||||
'context' => $context,
|
||||
'subject' => $table,
|
||||
'isNew' => $isNew,
|
||||
'data' => $data,
|
||||
]);
|
||||
$result = $dispatcher->dispatch($this->event_after_save, $afterSaveEvent)->getArgument('result', []);
|
||||
}
|
||||
PhocaDownloadLog::log($row->id, 2);
|
||||
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
function getSection($catid) {
|
||||
|
||||
$query = 'SELECT c.section'
|
||||
. ' FROM #__phocadownload_categories AS c'
|
||||
. ' WHERE c.id = '.(int)$catid;
|
||||
|
||||
$this->_db->setQuery( $query );
|
||||
$sectionId = $this->_db->loadObject();
|
||||
|
||||
if (isset($sectionId->section)) {
|
||||
return $sectionId->section;
|
||||
}
|
||||
return false;
|
||||
}*/
|
||||
|
||||
function isOwnerCategoryFile($userId, $fileId) {
|
||||
|
||||
$query = 'SELECT cc.id'
|
||||
. ' FROM #__phocadownload_categories AS cc'
|
||||
. ' LEFT JOIN #__phocadownload AS a ON a.catid = cc.id'
|
||||
. ' WHERE cc.owner_id = '.(int)$userId
|
||||
. ' AND a.id = '.(int)$fileId;
|
||||
|
||||
$this->_db->setQuery( $query );
|
||||
$ownerCategoryId = $this->_db->loadObject();
|
||||
if (isset($ownerCategoryId->id)) {
|
||||
return $ownerCategoryId->id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function publish($id = 0, $publish = 1) {
|
||||
|
||||
//$user = JFactory::getUser();
|
||||
$query = 'UPDATE #__phocadownload AS a'
|
||||
//. ' LEFT JOIN #__phocadownload_categories AS cc ON cc.id = a.catid '
|
||||
. ' SET a.published = '.(int) $publish
|
||||
. ' WHERE a.id = '.(int)$id;
|
||||
//. ' AND cc.owner_id = '.(int) $user->get('id');
|
||||
|
||||
$this->_db->setQuery( $query );
|
||||
if (!$this->_db->execute()) {
|
||||
|
||||
throw new Exception('Database Error Publishing', 500);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function delete($id = 0) {
|
||||
|
||||
$paramsC = ComponentHelper::getParams('com_phocadownload');
|
||||
$deleteExistingFiles = $paramsC->get( 'delete_existing_files', 0 );
|
||||
|
||||
// - - - - - - - - - - - - -
|
||||
// Get all filenames we want to delete from database, we delete all thumbnails from server of this file
|
||||
$queryd = 'SELECT filename as filename FROM #__phocadownload WHERE id = '.(int)$id;
|
||||
$this->_db->setQuery($queryd);
|
||||
$fileObject = $this->_db->loadObjectList();
|
||||
// - - - - - - - - - - - - -
|
||||
|
||||
$query = 'DELETE FROM #__phocadownload'
|
||||
. ' WHERE id ='.(int)$id;
|
||||
|
||||
$this->_db->setQuery( $query );
|
||||
if(!$this->_db->execute()) {
|
||||
throw new Exception('Database Error - Delete Files', 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Delete record from statistics table
|
||||
$query = 'DELETE FROM #__phocadownload_user_stat WHERE fileid='.(int)$id;
|
||||
$this->_db->setQuery( $query );
|
||||
if(!$this->_db->execute()) {
|
||||
throw new Exception('Database Error - Delete User Stats (Files)', 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Delete tags
|
||||
$query = 'DELETE FROM #__phocadownload_tags_ref'
|
||||
. ' WHERE fileid ='.(int)$id;
|
||||
|
||||
$this->_db->setQuery( $query );
|
||||
if(!$this->_db->execute()) {
|
||||
|
||||
throw new Exception('Database Error - Delete Tags (Files)', 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - -
|
||||
// DELETE FILES ON SERVER
|
||||
if ($deleteExistingFiles == 1) {
|
||||
$path = PhocaDownloadPath::getPathSet();
|
||||
foreach ($fileObject as $key => $value) {
|
||||
//The file can be stored in other category - don't delete it from server because other category use it
|
||||
$querys = "SELECT id as id FROM #__phocadownload WHERE filename='".$value->filename."' ";
|
||||
$this->_db->setQuery($querys);
|
||||
$sameFileObject = $this->_db->loadObject();
|
||||
// same file in other category doesn't exist - we can delete it
|
||||
if (!$sameFileObject) {
|
||||
File::delete(Path::clean($path['orig_abs_ds'].$value->filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user