primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,229 @@
<?php
/*
* @package Joomla
* @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\Component\ComponentHelper;
use Joomla\CMS\Object\CMSObject;
jimport('joomla.application.component.model');
class PhocagalleryModelCategories extends BaseDatabaseModel
{
var $_data = null;
var $_total = null;
var $_context = 'com_phocagallery.categories';
private $_ordering = null;
function __construct() {
parent::__construct();
$app = Factory::getApplication();
$config = Factory::getConfig();
$paramsC = ComponentHelper::getParams('com_phocagallery') ;
$default_pagination = (int)$paramsC->get( 'default_pagination_categories', '0' );
$category_ordering = $paramsC->get( 'category_ordering', 1 );
$context = $this->_context.'.';
// Get the pagination r equest variables
$this->setState('limit', $app->getUserStateFromRequest($context .'limit', 'limit', $default_pagination, '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('catordering', $app->getUserStateFromRequest($context .'catordering', 'catordering', $category_ordering, 'int'));
// Get the filter r equest variables
//$this->setState('filter_order', J Request::get Cmd('filter_order', 'ordering'));
//$this->setState('filter_order_dir', J Request::get Cmd('filter_order_Dir', 'ASC'));
}
function getData() {
$app = Factory::getApplication();
if (empty($this->_data)) {
$query = $this->_buildQuery();
$this->_data = $this->_getList( $query );// We need all data because of tree
// Order Categories to tree
$text = ''; // test is tree name e.g. Category >> Subcategory
$tree = array();
$this->_data = $this->_categoryTree($this->_data, $tree, 0, $text, -1);
return $this->_data;
}
}
/*
* Is called after setTotal from the view
*/
function getTotal() {
return $this->_total;
}
function setTotal($total) {
$this->_total = (int)$total;
}
/*
* Is called after setTotal from the view
*/
function getPagination() {
if (empty($this->_pagination)) {
jimport('joomla.html.pagination');
$this->_pagination = new PhocaGalleryPaginationCategories( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
}
return $this->_pagination;
}
function getOrdering() {
if(empty($this->_ordering)) {
$this->_ordering = PhocaGalleryOrdering::renderOrderingFront($this->getState('catordering'), 2);
}
return $this->_ordering;
}
function _buildQuery() {
$app = Factory::getApplication();
$user = Factory::getUser();
$gid = $user->get('aid', 0);
// Filter by language
$whereLang = '';
if ($this->getState('filter.language')) {
$whereLang = ' AND cc.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
}
// Params
$params = $app->getParams();
$display_subcategories = $params->get( 'display_subcategories', 1 );
//$show_empty_categories= $params->get( 'display_empty_categories', 0 );
//$hide_categories = $params->get( 'hide_categories', '' );
$catOrdering = PhocaGalleryOrdering::getOrderingString($this->getState('catordering'), 2);
// Display or hide subcategories in CATEGORIES VIEW
$hideSubCatSql = '';
if ((int)$display_subcategories != 1) {
$hideSubCatSql = ' AND cc.parent_id = 0';
}
// Get all categories which should be hidden
/*$hideCatArray = explode( ',', trim( $hide_categories ) );
$hideCatSql = '';
if (is_array($hideCatArray)) {
foreach ($hideCatArray as $value) {
$hideCatSql .= ' AND cc.id != '. (int) trim($value) .' ';
}
}*/
//Display or hide empty categories
/* $emptyCat = '';
if ($show_empty_categories != 1) {
$emptyCat = ' AND a.published = 1';
}*/
phocagalleryimport('phocagallery.ordering.ordering');
//$categoryOrdering = PhocaGalleryOrdering::getOrderingString($category_ordering, 2);
$query = 'SELECT cc.*, a.catid, COUNT(a.id) AS numlinks, u.username AS username, r.count AS ratingcount, r.average AS ratingaverage, uc.avatar AS avatar, uc.approved AS avatarapproved, uc.published AS avatarpublished, min(a.filename) as filename, min(a.extm) as extm, min(a.exts) as exts, min(a.exth) as exth, min(a.extw) as extw,'
. ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(\':\', cc.id, cc.alias) ELSE cc.id END as slug'
. ' FROM #__phocagallery_categories AS cc'
//. ' LEFT JOIN #__phocagallery AS a ON a.catid = cc.id'
. ' LEFT JOIN #__phocagallery AS a ON a.catid = cc.id and a.published = 1'
. ' LEFT JOIN #__phocagallery_user AS uc ON uc.userid = cc.owner_id'
. ' LEFT JOIN #__users AS u ON u.id = cc.owner_id'
. ' LEFT JOIN #__phocagallery_votes_statistics AS r ON r.catid = cc.id'
. ' WHERE cc.published = 1'
. ' AND cc.approved = 1'
//. ' AND (a.published = 1 OR a.id is null)'
//. $emptyCat - need to be set in tree
. $whereLang
. $hideSubCatSql
//. $hideCatSql - need to be set in tree
. ' GROUP BY cc.id, cc.parent_id, cc.owner_id, cc.image_id, cc.title, cc.name, cc.alias, cc.image, cc.section, cc.image_position, cc.description, cc.date, cc.published, cc.approved, cc.checked_out, cc.checked_out_time, cc.editor, cc.ordering, cc.access, cc.count, cc.hits, cc.accessuserid, cc.deleteuserid, cc.uploaduserid, cc.userfolder, cc.latitude, cc.longitude, cc.zoom, cc.geotitle, cc.extid, cc.exta, cc.extu, cc.extauth, cc.extfbuid, cc.extfbcatid, cc.params, cc.metakey, cc.metadesc, cc.metadata, cc.language, a.catid, u.username, r.count, r.average, uc.avatar, uc.approved, uc.published'
//. ' ORDER BY cc.'.$categoryOrdering;
.$catOrdering['output'];
return $query;
}
/*
* Create category tree
*/
function _categoryTree( $data, $tree, $id = 0, $text='', $currentId = 0) {
foreach ($data as $key) {
$show_text = $text . $key->title;
static $iCT = 0;// All displayed items
if ($key->parent_id == $id && $currentId != $id && $currentId != $key->id ) {
$tree[$iCT] = new CMSObject();
$tree[$iCT]->id = $key->id;
$tree[$iCT]->title = $show_text;
$tree[$iCT]->title_self = $key->title;
$tree[$iCT]->parent_id = $key->parent_id;
$tree[$iCT]->image_id = $key->image_id;
$tree[$iCT]->name = $key->name;
$tree[$iCT]->alias = $key->alias;
$tree[$iCT]->image = $key->image;
$tree[$iCT]->section = $key->section;
$tree[$iCT]->image_position = $key->image_position;
$tree[$iCT]->description = $key->description;
$tree[$iCT]->published = $key->published;
$tree[$iCT]->editor = $key->editor;
$tree[$iCT]->ordering = $key->ordering;
$tree[$iCT]->access = $key->access;
$tree[$iCT]->count = $key->count;
$tree[$iCT]->params = $key->params;
$tree[$iCT]->catid = $key->catid;
$tree[$iCT]->numlinks = $key->numlinks;
$tree[$iCT]->slug = $key->slug;
$tree[$iCT]->hits = $key->hits;
$tree[$iCT]->username = $key->username;
$tree[$iCT]->ratingaverage = $key->ratingaverage;
$tree[$iCT]->ratingcount = $key->ratingcount;
$tree[$iCT]->accessuserid = $key->accessuserid;
$tree[$iCT]->uploaduserid = $key->uploaduserid;
$tree[$iCT]->deleteuserid = $key->deleteuserid;
$tree[$iCT]->userfolder = $key->userfolder;
$tree[$iCT]->latitude = $key->latitude;
$tree[$iCT]->longitude = $key->longitude;
$tree[$iCT]->zoom = $key->zoom;
$tree[$iCT]->geotitle = $key->geotitle;
$tree[$iCT]->avatar = $key->avatar;
$tree[$iCT]->avatarapproved = $key->avatarapproved;
$tree[$iCT]->avatarpublished = $key->avatarpublished;
$tree[$iCT]->link = '';
$tree[$iCT]->filename = '';// Will be added in View (after items will be reduced)
$tree[$iCT]->extid = $key->extid;// Picasa Album or Facebook Album
$tree[$iCT]->extfbcatid = $key->extfbcatid;
// info about one image (not using recursive function)
$tree[$iCT]->filename = $key->filename;
$tree[$iCT]->extm = $key->extm;
$tree[$iCT]->exts = $key->exts;
$tree[$iCT]->extw = $key->extw;
$tree[$iCT]->exth = $key->exth;
$tree[$iCT]->date = $key->date;
$tree[$iCT]->linkthumbnailpath = '';
$iCT++;
$tree = $this->_categoryTree($data, $tree, $key->id, $show_text . " &raquo; ", $currentId );
}
}
return($tree);
}
}
?>

View File

@ -0,0 +1,650 @@
<?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;
*/
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
defined('_JEXEC') or die();
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Table\Table;
jimport('joomla.application.component.model');
phocagalleryimport('phocagallery.ordering.ordering');
phocagalleryimport('phocagallery.file.filethumbnail');
class PhocagalleryModelCategory extends BaseDatabaseModel
{
var $_id = null;
var $_data = null;
var $_category = null;
var $_total = null;
var $_context = 'com_phocagallery.category';
private $_ordering = null;
function __construct() {
$app = Factory::getApplication();
parent::__construct();
$config = Factory::getConfig();
$paramsC = ComponentHelper::getParams('com_phocagallery') ;
$default_pagination = (int)$paramsC->get( 'default_pagination_category', '20' );
$image_ordering = $paramsC->get( 'image_ordering', 1 );
$context = $this->_context.'.';
// Get the pagination request variables
$this->setState('limit', $app->getUserStateFromRequest($context .'limit', 'limit', $default_pagination, '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));
// Get the filter request variables
$this->setState('filter.language',$app->getLanguageFilter());
$this->setState('imgordering', $app->getUserStateFromRequest($context .'imgordering', 'imgordering', $image_ordering, 'int'));
//$this->setState('filter_order', J Request::get Cmd('filter_order', 'ordering'));
//$this->setState('filter_order_dir', J Request::get Cmd('filter_order_Dir', 'ASC'));
$id = $app->input->get('id', 0, 'int');
$this->setId((int)$id);
}
function setId($id) {
$this->_id = $id;
$this->_category = null;
}
/*
* IMAGES
*/
function getData( $rightDisplayDelete = 0, $tagId = 0) {
if (empty($this->_data)) {
$query = $this->_buildQuery($rightDisplayDelete, $tagId);
$this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
}
return $this->_data;
}
function getTotal($rightDisplayDelete = 0, $tagId = 0) {
if (empty($this->_total)) {
$query = $this->_buildQuery($rightDisplayDelete, $tagId, 1);
$this->_total = $this->_getListCount($query);
}
return $this->_total;
}
function getPagination($rightDisplayDelete = 0, $tagId = 0) {
if (empty($this->_pagination)) {
jimport('joomla.html.pagination');
$this->_pagination = new PhocaGalleryPaginationCategory( $this->getTotal($rightDisplayDelete, $tagId), $this->getState('limitstart'), $this->getState('limit') );
}
return $this->_pagination;
}
function getOrdering() {
if(empty($this->_ordering)) {
$this->_ordering = PhocaGalleryOrdering::renderOrderingFront($this->getState('imgordering'), 1);
}
return $this->_ordering;
}
function _buildQuery($rightDisplayDelete = 0, $tagId = 0, $count = 0) {
$app = Factory::getApplication();
$user = Factory::getUser();
$params = $app->getParams();
//$image_ordering = $params->get( 'image_ordering', 1 );
$wheres = array();
$enable_overlib = $params->get( 'enable_overlib', 0 );
$imageOrdering = PhocaGalleryOrdering::getOrderingString($this->getState('imgordering'), 1);
// Filter by language
if ($this->getState('filter.language')) {
$wheres[] = ' a.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
}
// Link from comment system
$cimgid = $app->input->get( 'cimgid', 0, 'int');
if ($cimgid > 0) {
$wheres[] = ' a.id = '.(int)$cimgid;
}
$selectUser = '';
$leftUser = '';
if ($enable_overlib > 3) {
$selectUser = ', ua.id AS userid, ua.username AS username, ua.name AS usernameno';
$leftUser = ' LEFT JOIN #__users AS ua ON ua.id = a.userid';
//$whereUser = ' AND ua.id ='.(int)$user->id;
}
if ($rightDisplayDelete == 0 ) {
$published = ' AND a.published = 1';
$published .= ' AND a.approved = 1';
} else {
$published = '';
}
$leftTag = '';
if ((int)$tagId > 0) {
$leftTag = ' LEFT JOIN #__phocagallery_tags_ref AS t ON t.imgid = a.id';
}
if ((int)$tagId > 0) {
$wheres[] = ' t.tagid= '.(int)$tagId;
} else {
$wheres[] = ' a.catid= '.(int)$this->_id;
}
$leftCat = ' LEFT JOIN #__phocagallery_categories AS cc ON cc.id = a.catid';
if ($count == 1) {
$query = 'SELECT a.id'
//. $selectUser
.' FROM #__phocagallery AS a'
//.' LEFT JOIN #__phocagallery_img_votes_statistics AS r ON r.imgid = a.id'
. $leftCat
//. $leftUser
. $leftTag
. ' WHERE ' . implode( ' AND ', $wheres )
. $published
//. $imageOrdering['output'];
. ' ORDER BY a.id';
} else {
$query = 'SELECT a.*, cc.alias AS catalias, cc.accessuserid AS cataccessuserid, cc.access AS cataccess,'
. ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(\':\', cc.id, cc.alias) ELSE cc.id END as catslug'
. $selectUser
.' FROM #__phocagallery AS a'
.' LEFT JOIN #__phocagallery_img_votes_statistics AS r ON r.imgid = a.id'
. $leftCat
. $leftUser
. $leftTag
. ' WHERE ' . implode( ' AND ', $wheres )
. $published
. $imageOrdering['output'];
}
return $query;
}
/*
* CATEGORY - get info about this category
*/
function getCategory() {
$app = Factory::getApplication();
if ($this->_id == 0) {
return '';
}
if ($this->_loadCategory()) {
$user = Factory::getUser();
if (!$this->_category->published) {
//$mainframe->redirect(JRoute::_('index.php', false), JText::_("COM_PHOCAGALLERY_CATEGORY_IS_UNPUBLISHED"));
throw new Exception(Text::_( "COM_PHOCAGALLERY_CATEGORY_IS_UNPUBLISHED" ), 404);
exit;
}
if (!$this->_category->approved) {
//$mainframe->redirect(JRoute::_('index.php', false), JText::_("COM_PHOCAGALLERY_CATEGORY_IS_UNAUTHORIZED"));// don't loop
throw new Exception(Text::_( "COM_PHOCAGALLERY_ERROR_CATEGORY_IS_UNAUTHORIZED" ), 404);
exit;
}
// USER RIGHT - ACCESS - - - - - -
$rightDisplay = 1;//default is set to 1 (all users can see the category)
if (!empty($this->_category)) {
$rightDisplay = PhocaGalleryAccess::getUserRight('accessuserid', $this->_category->accessuserid, $this->_category->access, $user->getAuthorisedViewLevels(), $user->get('id', 0), 0);
}
if ($rightDisplay == 0) {
$uri = \Joomla\CMS\Uri\Uri::getInstance();
$t['pl'] = 'index.php?option=com_users&view=login&return='.base64_encode($uri->toString());
$app->enqueueMessage(Text::_('COM_PHOCAGALLERY_NOT_AUTHORISED_ACTION'));
$app->redirect(Route::_($t['pl'], false));
//exit;
}
// - - - - - - - - - - - - - - - -
}
return $this->_category;
}
function _loadCategory() {
if (empty($this->_category)){
//$query = 'SELECT c.*,' .
$query = 'SELECT c.id, c.title, c.alias, c.description, c.published, c.approved, c.parent_id, c.deleteuserid, c.accessuserid, c.uploaduserid, c.owner_id, c.access, c.metakey, c.metadesc, c.latitude, c.longitude, c.zoom, c.geotitle, c.userfolder, c.image_id,' .
' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as slug '.
' FROM #__phocagallery_categories AS c' .
' WHERE c.id = '. (int) $this->_id;
' AND c.approved = 1';
$this->_db->setQuery($query, 0, 1);
$this->_category = $this->_db->loadObject();
}
return true;
}
/*
* PARENT CATEGORIES
*/
function getParentCategory() {
$parentCategory = 0;
if (isset($this->_category->parent_id) && isset($this->_category->id)) {
$app = Factory::getApplication();
$params = $app->getParams();
$category_ordering = $params->get( 'category_ordering', 1 );
$categoryOrdering = PhocaGalleryOrdering::getOrderingString($category_ordering, 2);
//$query = 'SELECT cc.*' .
$query = 'SELECT cc.id, cc.title, cc.alias, cc.published, cc.approved, cc.parent_id, cc.deleteuserid, cc.accessuserid, cc.uploaduserid, cc.access' .
' FROM #__phocagallery_categories AS cc' .
' WHERE cc.id = '.(int) $this->_category->parent_id.
' AND cc.published = 1' .
' AND cc.approved = 1' .
' AND cc.id <> '.(int) $this->_category->id.
$categoryOrdering['output'];
$this->_db->setQuery($query, 0, 1);
$parentCategory = $this->_db->loadObject();
}
return $parentCategory ;
}
/*
* SUB CATEGORIES
*/
function getSubCategory() {
$app = Factory::getApplication();
$params = $app->getParams();
$category_ordering = $params->get( 'category_ordering', 1 );
$categoryOrdering = PhocaGalleryOrdering::getOrderingString($category_ordering, 2);
// Filter by language
$whereLang = '';
if ($this->getState('filter.language')) {
$whereLang = ' AND cc.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
}
//$query = 'SELECT c.*, COUNT(a.id) countimage' ... Cannot be used because get error if there is no image
//$query = 'SELECT cc.*, a.filename, a.extm, a.exts, a.extw, a.exth'
//$query = 'SELECT cc.id, cc.title, cc.alias, cc.published, cc.approved, cc.parent_id, cc.deleteuserid, cc.accessuserid, cc.uploaduserid, cc.access, cc.image_id';
//$query = 'SELECT DISTINCT cc.id, cc.title, cc.alias, cc.published, cc.approved, cc.parent_id, cc.deleteuserid, cc.accessuserid, cc.uploaduserid, cc.access, cc.image_id, a.filename, a.extm, a.exts, a.extw, a.exth, a.extid';
$query = 'SELECT DISTINCT cc.id, cc.title, cc.alias, cc.published, cc.approved, cc.parent_id, cc.deleteuserid, cc.accessuserid, cc.uploaduserid, cc.access, cc.image_id, min(a.filename) as filename, min(a.extm) as extm, min(a.exts) as exts, min(a.extw) as extw, min(a.exth) as exth, min(a.extid) as extid';
$query .= ' FROM #__phocagallery_categories AS cc'
.' LEFT JOIN #__phocagallery AS a ON cc.id = a.catid'
.' WHERE cc.parent_id = '.(int) $this->_id
.' AND cc.published = 1'
.' AND cc.approved = 1'
.' AND cc.id <> '.(int) $this->_id
// .' AND a.published = 1'
// .' AND countimage > 0'
// .' AND (SELECT COUNT(a.id) AS countimage'
// .' FROM #__phocagallery as a'
// .' WHERE a.catid = c.id'
// .' AND a.published = 1) > 0'
. $whereLang
//.' GROUP BY cc.id, cc.title, cc.alias, cc.published, cc.approved, cc.parent_id, cc.deleteuserid, cc.accessuserid, cc.uploaduserid, cc.access, cc.image_id, a.filename, a.extm, a.exts, a.extw, a.exth, a.extid'
.' GROUP BY cc.id, cc.title, cc.alias, cc.published, cc.approved, cc.parent_id, cc.deleteuserid, cc.accessuserid, cc.uploaduserid, cc.access, cc.image_id'
.$categoryOrdering['output'];
$this->_db->setQuery($query);
$subCategory = $this->_db->loadObjectList();
return $subCategory;
}
// Called from SubCategories
// Called from Category Controller
function getCountItem($catid = 0, $rightDisplayDelete = 0) {
if ($rightDisplayDelete == 0 ) {
$published = ' WHERE a.published = 1 AND a.approved = 1 AND a.catid = '.$catid;
} else {
$published = ' WHERE a.catid = '.$catid;
}
$query = 'SELECT COUNT(a.id) FROM #__phocagallery AS a'
. $published;
;
$this->_db->setQuery( $query );
/*if (!$this->_db->query()) {
$this->setError('Database Error 3');
return false;
}*/
return $this->_db->loadRow();
}
/*
* Called from Controller
*/
function getCategoryIdFromImageId($id) {
// id is id
$query = 'SELECT a.catid' .
' FROM #__phocagallery AS a' .
' WHERE a.id = '. (int) $id;
$this->_db->setQuery($query, 0, 1);
$categoryId = $this->_db->loadObject();
return $categoryId;
}
function getCategoryAlias($id) {
// id is catid
$query = 'SELECT c.alias' .
' FROM #__phocagallery_categories AS c' .
' WHERE c.id = '. (int) $id;
$this->_db->setQuery($query, 0, 1);
$categoryAlias = $this->_db->loadObject();
return $categoryAlias;
}
/*
* Actions
*/
function delete($id = 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 #__phocagallery WHERE id ='.(int)$id;
$this->_db->setQuery($queryd);
$file_object = $this->_db->loadObjectList();
$query = 'DELETE FROM #__phocagallery'
. ' WHERE id ='.(int)$id;
$this->_db->setQuery( $query );
$this->_db->execute();
/*if(!$this->_db->query()) {
$this->setError('Database Error 2');
return false;
}*/
// Delete thumbnails - medium and large, small from server
// All id we want to delete - gel all filenames
foreach ($file_object 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 #__phocagallery WHERE filename='".$value->filename."' ";
$this->_db->setQuery($queryd);
$same_file_object = $this->_db->loadObject();
//same file in other category doesn't exist - we can delete it
if (!$same_file_object){
//Delete all thumbnail files but not original
PhocaGalleryFileThumbnail::deleteFileThumbnail($value->filename, 1, 1, 1);
PhocaGalleryFile::deleteFile($value->filename);
}
}
return true;
}
function publish($id = 0, $publish = 1) {
$user = Factory::getUser();
$query = 'UPDATE #__phocagallery'
. ' SET published = '.(int) $publish
. ' WHERE id = '.(int)$id
. ' AND ( checked_out = 0 OR ( checked_out = '.(int) $user->get('id').' ) )';
$this->_db->setQuery( $query );
$this->_db->execute();
/*if (!$this->_db->query()) {
$this->setError('Database Error 2');
return false;
}*/
return true;
}
function store($data, $return) {
//If this file doesn't exists don't save it
if (!PhocaGalleryFile::existsFileOriginal($data['filename'])) {
$this->setError('File not exists');
return false;
}
$data['imgorigsize'] = PhocaGalleryFile::getFileSize($data['filename'], 0);
$data['format'] = PhocaGalleryFile::getFileFormat($data['filename']);
//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'] = PhocaGalleryFile::getTitleFromFile($data['filename']);
}
if (!isset($data['alias']) || (isset($data['alias']) && $data['alias'] == '')) {
$data['alias'] = PhocaGalleryFile::getTitleFromFile($data['filename']);
}
//clean alias name (no bad characters)
//$data['alias'] = PhocaGalleryText::getAliasName($data['alias']);
if((!isset($data['longitude']) || (isset($data['longitude']) && $data['longitude'] == '')) ||
(!isset($data['latitude']) || (isset($data['latitude']) && $data['latitude'] ==''))) {
phocagalleryimport('phocagallery.geo.geo');
$coords = PhocaGalleryGeo::getGeoCoords($data['filename']);
if (!isset($data['longitude']) || (isset($data['longitude']) && $data['longitude'] =='')){
$data['longitude'] = $coords['longitude'];
}
if (!isset($data['latitude']) || (isset($data['latitude']) && $data['latitude'] =='')){
$data['latitude'] = $coords['latitude'];
}
if ((!isset($data['zoom']) || (isset($data['zoom']) && $data['zoom'] == '')) && $data['longitude'] != '' && $data['latitude'] != ''){
$data['zoom'] = PhocaGallerySettings::getAdvancedSettings('geozoom');
}
}
$row = $this->getTable('phocagallery', 'Table');
// Bind the form fields to the Phoca gallery table
if (!$row->bind($data)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Create the timestamp for the date
$row->date = gmdate('Y-m-d H:i:s');
// if new item, order last in appropriate group
if (!$row->id) {
$where = 'catid = ' . (int) $row->catid ;
$row->ordering = $row->getNextOrder( $where );
}
// Make sure the Phoca gallery table is valid
if (!$row->check()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Store the Phoca gallery table to the database
if (!$row->store()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
//Create thumbnail small, medium, large
$returnFrontMessage = PhocaGalleryFileThumbnail::getOrCreateThumbnail($row->filename, $return, 1, 1, 1, 1);
if ($returnFrontMessage == 'Success') {
return true;
} else {
return false;
}
}
function rate($data) {
$row = $this->getTable('phocagalleryvotes', 'Table');
if (!$row->bind($data)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
$row->date = gmdate('Y-m-d H:i:s');
$row->published = 1;
if (!$row->id) {
$where = 'catid = ' . (int) $row->catid ;
$row->ordering = $row->getNextOrder( $where );
}
if (!$row->check()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
if (!$row->store()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Update the Vote Statistics
phocagalleryimport('phocagallery.rate.ratecategory');
if (!PhocaGalleryRateCategory::updateVoteStatistics( $data['catid'])) {
return false;
}
return true;
}
function comment($data) {
$row = $this->getTable('phocagallerycomments', 'Table');
if (!$row->bind($data)) {
$this->setError($row->getError());
return false;
}
$row->date = gmdate('Y-m-d H:i:s');
$row->published = 1;
if (!$row->id) {
$where = 'catid = ' . (int) $row->catid ;
$row->ordering = $row->getNextOrder( $where );
}
if (!$row->check()) {
$this->setError($row->getError());
return false;
}
if (!$row->store()) {
$this->setError($row->getError());
return false;
}
return true;
}
function hit($id) {
$app = Factory::getApplication();
$table = Table::getInstance('phocagalleryc', 'Table');
$table->hit($id);
return true;
}
function getCountImages($catId, $published = 1) {
$app = Factory::getApplication();
$query = 'SELECT COUNT(i.id) AS countimg'
.' FROM #__phocagallery AS i'
.' WHERE i.catid = '. (int) $catId
.' AND i.published ='.(int)$published
.' AND i.approved = 1';
$this->_db->setQuery($query, 0, 1);
$countPublished = $this->_db->loadObject();
return $countPublished;
}
function getHits($catId) {
$app = Factory::getApplication();
$query = 'SELECT cc.hits AS catviewed'
.' FROM #__phocagallery_categories AS cc'
.' WHERE cc.id = '. (int) $catId;
$this->_db->setQuery($query, 0, 1);
$categoryViewed = $this->_db->loadObject();
return $categoryViewed;
}
function getStatisticsImages($catId, $order, $order2 = 'ASC', $limit = 3) {
$query = 'SELECT i.*,'
.' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(\':\', cc.id, cc.alias) ELSE cc.id END as catslug'
.' FROM #__phocagallery AS i'
.' LEFT JOIN #__phocagallery_categories AS cc ON cc.id = i.catid'
.' WHERE i.catid = '.(int) $catId
.' AND i.published = 1'
.' AND i.approved = 1'
.' ORDER BY '.$order.' '.$order2;
$this->_db->setQuery($query, 0, $limit);
$statistics = $this->_db->loadObjectList();
$item = array();
$count = 0;
$total = count($statistics);
for($i = 0; $i < $total; $i++) {
$statisticsData[$count] = $statistics[$i] ;
$item[$i] =& $statisticsData[$count];
$item[$i]->slug = $item[$i]->id.':'.$item[$i]->alias;
$item[$i]->item_type = "image";
$extImg = PhocaGalleryImage::isExtImage($item[$i]->extid);
if ($extImg) {
$item[$i]->linkthumbnailpath = $item[$i]->extm;
} else {
$item[$i]->linkthumbnailpath = PhocaGalleryImageFront::displayCategoryImageOrNoImage($item[$i]->filename, 'medium');
}
$count++;
}
return $item;
}
}
?>

View File

@ -0,0 +1,101 @@
<?php
/*
* @package Joomla
* @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 Gallery
* @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;
jimport('joomla.application.component.model');
phocagalleryimport('phocagallery.access.access');
phocagalleryimport('phocagallery.ordering.ordering');
class PhocagalleryModelComment extends BaseDatabaseModel
{
function __construct() {
parent::__construct();
$app = Factory::getApplication();
$id = $app->input->get('id', 0, 'int');
$this->setId((int)$id);
}
function setId($id) {
$this->_id = $id;
$this->_data = null;
}
function &getData() {
if (!$this->_loadData()) {
$this->_initData();
}
return $this->_data;
}
function _loadData() {
if (empty($this->_data)) {
$app = Factory::getApplication();
$params = $app->getParams();
$image_ordering = $params->get( 'image_ordering', 1 );
$imageOrdering = PhocaGalleryOrdering::getOrderingString($image_ordering);
$query = 'SELECT a.*, c.accessuserid as cataccessuserid, c.access as cataccess,'
.' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as catslug,'
.' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug'
.' FROM #__phocagallery AS a'
.' LEFT JOIN #__phocagallery_categories AS c ON c.id = a.catid'
.' WHERE a.id = '.(int) $this->_id
.$imageOrdering['output'];
$this->_db->setQuery($query);
$this->_data = $this->_db->loadObject();
return (boolean) $this->_data;
}
return true;
}
function _initData() {
if (empty($this->_data)) {
$this->_data = '';
return (boolean) $this->_data;
}
return true;
}
function comment($data) {
$row = $this->getTable('phocagallerycommentimgs', 'Table');
if (!$row->bind($data)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
$row->date = gmdate('Y-m-d H:i:s');
$row->published = 1;
if (!$row->id) {
$where = 'imgid = ' . (int) $row->imgid ;
$row->ordering = $row->getNextOrder( $where );
}
if (!$row->check()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
if (!$row->store()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
return true;
}
}
?>

View File

@ -0,0 +1,50 @@
<?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 PhocagalleryModelCommentImgA extends BaseDatabaseModel
{
function comment($data) {
$row = $this->getTable('phocagallerycommentimgs', 'Table');
if (!$row->bind($data)) {
$this->setError($row->getError());
return false;
}
$row->date = gmdate('Y-m-d H:i:s');
$row->published = 1;
if (!$row->id) {
$where = 'imgid = ' . (int) $row->imgid ;
$row->ordering = $row->getNextOrder( $where );
}
if (!$row->check()) {
$this->setError($row->getError());
return false;
}
if (!$row->store()) {
$this->setError($row->getError());
return false;
}
return true;
}
}
?>

View File

@ -0,0 +1,57 @@
<?php
/*
* @package Joomla
* @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 Gallery
* @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;
jimport('joomla.application.component.model');
class PhocagalleryModelCooliris3DWall extends BaseDatabaseModel
{
function __construct() {
parent::__construct();
}
function getCategory($id) {
$app = Factory::getApplication();
if ($id > 0) {
$query = 'SELECT c.*,' .
' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as slug '.
' FROM #__phocagallery_categories AS c' .
' WHERE c.id = '. (int) $id;
$this->_db->setQuery($query, 0, 1);
$category = $this->_db->loadObject();
$user = Factory::getUser();
// USER RIGHT - ACCESS - - - - - -
$rightDisplay = 1;//default is set to 1 (all users can see the category)
if (!empty($category)) {
$rightDisplay = PhocaGalleryAccess::getUserRight('accessuserid', $category->accessuserid, $category->access, $user->getAuthorisedViewLevels(), $user->get('id', 0), 0);
}
if ($rightDisplay == 0) {
$uri = \Joomla\CMS\Uri\Uri::getInstance();
$t['pl'] = 'index.php?option=com_users&view=login&return='.base64_encode($uri->toString());
$app->enqueueMessage(Text::_('COM_PHOCAGALLERY_NOT_AUTHORISED_ACTION'));
$app->redirect(Route::_($t['pl'], false));
exit;
}
// - - - - - - - - - - - - - - - -
return $category;
}
return false;
}
}
?>

View File

@ -0,0 +1,328 @@
<?php
/*
* @package Joomla
* @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 Gallery
* @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\Table\Table;
use Joomla\CMS\Component\ComponentHelper;
jimport('joomla.application.component.model');
phocagalleryimport('phocagallery.access.access');
phocagalleryimport('phocagallery.ordering.ordering');
class PhocaGalleryModelDetail extends BaseDatabaseModel
{
public $_category = null;
function __construct() {
parent::__construct();
$app = Factory::getApplication();
$id = $app->input->get('id', 0, 'int');
$this->setState('filter.language',$app->getLanguageFilter());
$this->setId((int)$id);
}
function setId($id) {
$this->_id = $id;
$this->_data = null;
}
function &getData() {
if (!$this->_loadData()) {
$this->_initData();
}
return $this->_data;
}
function _loadData() {
if (empty($this->_data)) {
$app = Factory::getApplication();
$params = $app->getParams();
//$image_ordering = $params->get( 'image_ordering', 1 );
//$imageOrdering = PhocaGalleryOrdering::getOrderingString($image_ordering);
$whereLang = '';
if ($this->getState('filter.language')) {
$whereLang = ' AND a.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
}
$selectUser = ' ua.id AS userid, ua.username AS username, ua.name AS usernameno,';
$leftUser = ' LEFT JOIN #__users AS ua ON ua.id = a.userid';
$query = 'SELECT a.*, c.accessuserid as cataccessuserid, c.access as cataccess, c.owner_id as owner_id, '
. $selectUser
.' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as catslug,'
.' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug'
.' FROM #__phocagallery AS a'
.' LEFT JOIN #__phocagallery_categories AS c ON c.id = a.catid'
. $leftUser
.' WHERE a.id = '.(int) $this->_id
. $whereLang
.' AND a.published > 0'
.' AND a.approved > 0';
//.' ORDER BY a.'.$imageOrdering;
$this->_db->setQuery($query);
$this->_data = $this->_db->loadObject();
return (boolean) $this->_data;
}
return true;
}
function _initData() {
if (empty($this->_data)) {
$this->_data = '';
return (boolean) $this->_data;
}
return true;
}
function hit($id) {
$table = Table::getInstance('phocagallery', 'Table');
$table->hit($id);
return true;
}
function rate($data) {
$row = $this->getTable('phocagalleryimgvotes', 'Table');
if (!$row->bind($data)) {
$this->setError($row->getError());
return false;
}
$row->date = gmdate('Y-m-d H:i:s');
$row->published = 1;
if (!$row->id) {
$where = 'imgid = ' . (int) $row->imgid ;
$row->ordering = $row->getNextOrder( $where );
}
if (!$row->check()) {
$this->setError($row->getError());
return false;
}
if (!$row->store()) {
$this->setError($row->getError());
return false;
}
// Update the Vote Statistics
phocagalleryimport('phocagallery.rate.rateimage');
if (!PhocaGalleryRateImage::updateVoteStatistics( $data['imgid'])) {
return false;
}
return true;
}
public function getThumbnails($id, $catid, $order) {
$paramsC = ComponentHelper::getParams('com_phocagallery') ;
$multibox_thubms_count = $paramsC->get( 'multibox_thubms_count', 4 );
// 1) Display only next thumbnails of current image - use the $order variable - to know next order values
$thumbnails1 = array();
$this->_db->setQuery($this->getThumbnailsQuery($id, $catid, $order), 0, (int)$multibox_thubms_count);
$thumbnails1 = $this->_db->loadObjectList();
$cT = count($thumbnails1);
// 2) if there are no more next thumbnails, fill them with thumbnails from beginning
$thumbnails2 = array();
if ((int)$cT < (int)$multibox_thubms_count) {
$newCount = (int)$multibox_thubms_count - (int)$cT;
$this->_db->setQuery($this->getThumbnailsQuery($id, $catid, 0, 1, $thumbnails1), 0, (int)$newCount);
$thumbnails2 = $this->_db->loadObjectList();
}
$thumbnails = array_merge((array)$thumbnails1, (array)$thumbnails2);
return $thumbnails;
}
protected function getThumbnailsQuery($id, $catid, $order, $completion = 0, $currentThumbs = array()) {
$paramsC = ComponentHelper::getParams('com_phocagallery') ;
$image_ordering = $paramsC->get( 'image_ordering', 1 );
$wheres = array();
if ($this->getState('filter.language')) {
$wheres[] = ' a.language IN ('.$this->_db->Quote(Factory::getLanguage()->getTag()).','.$this->_db->Quote('*').')';
}
$imageOrdering = PhocaGalleryOrdering::getOrderingString($image_ordering, 1);
$published = ' AND a.published = 1';
$published .= ' AND a.approved = 1';
$wheres[] = ' a.catid = '.(int) $catid;
// Known issue - thumbnails with only larger order taken
if ($completion == 1) {
// with completion displaying, it can happen, that the same thumbnail as active thumbnail can be selected
// because thumbnails are selected from beginning
$wheres[] = ' a.id <> '.(int) $id;//do not complete thumbnails with image which is displayed as active
if (!empty($currentThumbs)) {
foreach ($currentThumbs as $k => $v) {
$wheres[] = ' a.id <> '.(int) $v->id;
}
}
} else {
// with standard displaying, it cannot happen, that the active image will be displayed,
// as only images with larger order will be displayed
$wheres[] = ' a.ordering > '.(int) $order;
}
$query = 'SELECT a.id, a.extid, a.exts, a.filename, a.title, a.description, a.metadesc, cc.alias AS catalias, cc.accessuserid AS cataccessuserid, cc.access AS cataccess,'
. ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(\':\', cc.id, cc.alias) ELSE cc.id END as catslug,'
. ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug'
.' FROM #__phocagallery AS a'
.' LEFT JOIN #__phocagallery_categories AS cc ON cc.id = a.catid'
. ' WHERE ' . implode( ' AND ', $wheres )
. $published
. $imageOrdering['output'];
return $query;
}
function comment($data) {
$row = $this->getTable('phocagallerycommentimgs', 'Table');
if (!$row->bind($data)) {
$this->setError($row->getError());
return false;
}
$row->date = gmdate('Y-m-d H:i:s');
$row->published = 1;
if (!$row->id) {
$where = 'imgid = ' . (int) $row->imgid ;
$row->ordering = $row->getNextOrder( $where );
}
if (!$row->check()) {
$this->setError($row->getError());
return false;
}
if (!$row->store()) {
$this->setError($row->getError());
return false;
}
return true;
}
function getItemNext($ordering, $catid) {
if (empty($this->_itemnext)) {
$query = $this->_getItemQueryOrdering( $ordering, $catid, 2 );
$this->_itemnext = $this->_getList( $query, 0 , 1 );
if (empty($this->_itemnext)) {
return null;
}
}
return $this->_itemnext;
}
function getItemPrev($ordering, $catid) {
if (empty($this->_itemprev)) {
$query = $this->_getItemQueryOrdering( $ordering, $catid, 1 );
$this->_itemprev = $this->_getList( $query, 0 , 1 );
if (empty($this->_itemprev)) {
return null;
}
}
return $this->_itemprev;
}
private function _getItemQueryOrdering($ordering, $catid, $direction) {
$wheres[] = " c.catid= ".(int) $catid;
//$wheres[] = " c.catid= cc.id";
$wheres[] = " c.published = 1";
$wheres[] = " cc.published = 1";
if ($direction == 1) {
$wheres[] = " c.ordering < " . (int) $ordering;
$order = 'DESC';
} else {
$wheres[] = " c.ordering > " . (int) $ordering;
$order = 'ASC';
}
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('*').')';
}
$query = ' SELECT c.id, c.title, c.alias, c.catid,'
.' cc.id AS categoryid, cc.title AS categorytitle, cc.alias AS categoryalias'
.' FROM #__phocagallery AS c'
.' LEFT JOIN #__phocagallery_categories AS cc ON cc.id = c.catid'
.' WHERE ' . implode( ' AND ', $wheres )
.' ORDER BY c.ordering '.$order;
return $query;
}
function getCategory($imageId) {
if (empty($this->_category)) {
$query = $this->_getCategoryQuery( $imageId );
$this->_category= $this->_getList( $query, 0, 1 );
}
return $this->_category;
}
function _getCategoryQuery( $imageId ) {
$wheres = array();
$app = Factory::getApplication();
$params = $app->getParams();
$user = Factory::getUser();
$userLevels = implode (',', $user->getAuthorisedViewLevels());
$wheres[] = " c.id= ".(int)$imageId;
$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('*').')';
}
$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 #__phocagallery_categories AS cc"
. " LEFT JOIN #__phocagallery AS c ON c.catid = cc.id"
. " WHERE " . implode( " AND ", $wheres )
. " ORDER BY cc.ordering";
return $query;
}
}
?>

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -0,0 +1,79 @@
<?php
/*
* @package Joomla
* @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 Gallery
* @copyright Copyright (C) Jan Pavelka www.phoca.cz
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Factory;
jimport('joomla.application.component.model');
class PhocaGalleryModelInfo extends BaseDatabaseModel
{
function __construct() {
parent::__construct();
$app = Factory::getApplication();
$id = $app->input->get('id', 0, 'int');
$this->setId((int)$id);
//$post = $app->input->get('get');
}
function setId($id){
$this->_id = $id;
$this->_data = null;
}
function &getData() {
// Load the Phoca gallery data
if (!$this->_loadData()) {
$this->_initData();
}
return $this->_data;
}
function _loadData() {
$app = Factory::getApplication();
$user = Factory::getUser();
// Lets load the content if it doesn't already exist
if (empty($this->_data)) {
// First try to get image data
$query = 'SELECT a.title, a.filename, a.description, a.exto, a.extid, a.metakey, a.metadesc,'
.' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as catslug,'
.' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug'
.' FROM #__phocagallery AS a'
.' LEFT JOIN #__phocagallery_categories AS c ON c.id = a.catid'
.' WHERE a.id = '. (int) $this->_id;
$this->_db->setQuery($query, 0, 1);
$this->_data = $this->_db->loadObject();
/*
if (isset($image->description) && $image->description != '') {
$this->_data['description'] = $image->description;
} else {
$this->_data['description'] = '';
}*/
return (boolean) $this->_data;
}
return true;
}
function _initData() {
if (empty($this->_data)) {
$this->_data = '';
return (boolean) $this->_data;
}
return true;
}
}
?>

View File

@ -0,0 +1,115 @@
<?php
/*
* @package Joomla
* @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;
jimport('joomla.application.component.model');
class PhocaGalleryModelMap extends BaseDatabaseModel
{
function __construct() {
parent::__construct();
$app = Factory::getApplication();
$id = $app->input->get('id', 0, 'int');
$this->setId((int)$id);
$catid = $app->input->get('catid', 0, 'int');
$this->setCatid((int)$catid);
//$post = $app->input->get('get');
}
function setId($id){
$this->_id = $id;
$this->_data = null;
$this->_data_category = null;
}
function setCatid($catid) {
if ($catid == 0) { //SEF
$query = 'SELECT c.catid,'
.' FROM #__phocagallery AS c'
.' WHERE c.id = '. (int) $this->_id;
$this->_db->setQuery($query, 0, 1);
$catid = $this->_db->loadObject();
$this->_catid = $catid->catid;
} else {
$this->_catid = $catid;
}
$this->_data = null;
$this->_data_category = null;
}
function &getData() {
if (!$this->_loadData()) {
$this->_initData();
}
return $this->_data;
}
function _loadData() {
$app = Factory::getApplication();
if (empty($this->_data)) {
$query = 'SELECT a.title, a.filename, a.description, a.latitude, a.longitude, a.zoom, a.geotitle, a.metadesc, a.metakey,'
.' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as catslug,'
.' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug'
.' FROM #__phocagallery AS a'
.' LEFT JOIN #__phocagallery_categories AS c ON c.id = a.catid'
.' WHERE a.id = '. (int) $this->_id;
$this->_db->setQuery($query, 0, 1);
$this->_data = $this->_db->loadObject();
return (boolean) $this->_data;
}
return true;
}
function _initData() {
if (empty($this->_data)) {
$this->_data = '';
return (boolean) $this->_data;
}
return true;
}
/*
* Category
*/
function &getDataCategory() {
if (!$this->_loadDataCategory()) {
$this->_initDataCategory();
}
return $this->_data_category;
}
function _loadDataCategory() {
$query = 'SELECT c.title, c.description, c.latitude, c.longitude, c.zoom, c.geotitle,'
.' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as catslug'
.' FROM #__phocagallery_categories AS c'
.' WHERE c.id = '. (int) $this->_catid;
$this->_db->setQuery($query, 0, 1);
$this->_data_category = $this->_db->loadObject();
return (boolean) $this->_data_category;
}
function _initDataCategory() {
if (empty($this->_data_category)) {
$this->_data_category = '';
return (boolean) $this->_data_category;
}
return true;
}
}
?>

View File

@ -0,0 +1,242 @@
<?php
/*
* @package Joomla
* @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 Gallery
* @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\Language\Text;
use Joomla\CMS\Pagination\PaginationObject;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
jimport('joomla.application.component.model');
use Joomla\String\StringHelper;
// CUSTOM PAGINATON
class PhocaGalleryModelPhocaGalleryLinkImgPagination extends Pagination
{
protected function _buildDataObject()
{
$data = new stdClass;
$uri = \Joomla\CMS\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 PhocaGalleryModelPhocaGalleryLinkImg extends BaseDatabaseModel
{
var $_data = null;
var $_total = null;
var $_pagination = null;
var $_context = 'com_phocagallery.phocagallerylinkimg';
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'));
}
if (!empty($this->_data)) {
foreach ($this->_data as $key => $value) {
$fileOriginal = PhocaGalleryFile::getFileOriginal($value->filename);
//Let the user know that the file doesn't exists
if (!File::exists($fileOriginal)) {
$this->_data[$key]->filename = Text::_( 'COM_PHOCAGALLERY_IMG_FILE_NOT_EXISTS' );
$this->_data[$key]->fileoriginalexist = 0;
} else {
//Create thumbnails small, medium, large
$refresh_url = 'index.php?option=com_phocagallery&view=phocagalleryimgs';
$fileThumb = PhocaGalleryFileThumbnail::getOrCreateThumbnail($value->filename, $refresh_url, 1, 1, 1);
$this->_data[$key]->linkthumbnailpath = $fileThumb['thumb_name_s_no_rel'];
$this->_data[$key]->fileoriginalexist = 1;
}
}
}
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 PhocaGalleryModelPhocaGalleryLinkImgPagination( $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 category, u.name AS editor, v.average AS ratingavg'
. ' FROM #__phocagallery AS a '
. ' LEFT JOIN #__phocagallery_categories AS cc ON cc.id = a.catid '
. ' LEFT JOIN #__phocagallery_img_votes_statistics AS v ON v.imgid = a.id'
. ' 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 category, a.ordering '.$filter_order_Dir;
} else {
$orderby = ' ORDER BY '.$filter_order.' '.$filter_order_Dir.' , category, 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.'.filter_catid', 'filter_catid', 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();
$where[] = 'a.published = 1';
$where[] = 'a.approved = 1';
$where[] = 'cc.published = 1';
$where[] = 'cc.approved = 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';
}
}
$where = ( count( $where ) ? ' WHERE '. implode( ' AND ', $where ) : '' );
return $where;
}
}
?>

View File

@ -0,0 +1,54 @@
<?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 PhocaGalleryModelRatingImgA extends BaseDatabaseModel
{
function rate($data) {
$row = $this->getTable('phocagalleryimgvotes');
if (!$row->bind($data)) {
$this->setError($row->getError());
return false;
}
$row->date = gmdate('Y-m-d H:i:s');
$row->published = 1;
if (!$row->id) {
$where = 'imgid = ' . (int) $row->imgid ;
$row->ordering = $row->getNextOrder( $where );
}
if (!$row->check()) {
$this->setError($row->getError());
return false;
}
if (!$row->store()) {
$this->setError($row->getError());
return false;
}
// Update the Vote Statistics
if (!PhocaGalleryRateImage::updateVoteStatistics( $data['imgid'])) {
return false;
}
return true;
}
}
?>

File diff suppressed because it is too large Load Diff