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 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -0,0 +1,59 @@
<?php
/**
* @package Phoca Gallery
* @author Jan Pavelka - https://www.phoca.cz
* @copyright Copyright (C) Jan Pavelka https://www.phoca.cz
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 and later
* @cms Joomla
* @copyright Copyright (C) Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Uri\Uri;
class PhocaGalleryPath extends CMSObject
{
public function __construct() {}
public static function &getInstance() {
static $instance;
if (!$instance) {
$instance = new PhocaGalleryPath();
//$baseFront = str_replace('/administrator', '', JUri::base(true));
$baseFront = Uri::root(true);
$instance->image_abs = JPATH_ROOT . '/images/phocagallery/';
$instance->image_rel = 'images/phocagallery/';
$instance->avatar_abs = JPATH_ROOT . '/images/phocagallery/avatars/';
$instance->avatar_rel = 'images/phocagallery/avatars/';
$instance->image_rel_full = $baseFront . '/' . $instance->image_rel;
$instance->image_rel_admin = 'media/com_phocagallery/images/administrator/';
$instance->image_rel_admin_full = $baseFront . '/' . $instance->image_rel_admin;
$instance->image_rel_front = 'media/com_phocagallery/images/';
$instance->image_rel_front_full = $baseFront . '/' . $instance->image_rel_front;
$instance->image_abs_front = JPATH_ROOT .'/media/com_phocagallery/images/';
$instance->media_css_abs = JPATH_ROOT .'/media/com_phocagallery/css/';
$instance->media_img_abs = JPATH_ROOT .'/media/com_phocagallery/images/';
$instance->media_js_abs = JPATH_ROOT .'/media/com_phocagallery/js/';
$instance->media_css_rel = 'media/com_phocagallery/css/';
$instance->media_img_rel = 'media/com_phocagallery/images/';
$instance->media_js_rel = 'media/com_phocagallery/js/';
$instance->media_css_rel_full = $baseFront . '/' . $instance->media_css_rel;
$instance->media_img_rel_full = $baseFront . '/' . $instance->media_img_rel;
$instance->media_js_rel_full = $baseFront . '/' . $instance->media_js_rel;
$instance->assets_abs = JPATH_ROOT . '/media/com_phocagallery/js/';
$instance->assets_rel = 'media/com_phocagallery/js/';
}
return $instance;
}
public static function getPath() {
$instance = PhocaGalleryPath::getInstance();
return $instance;
}
}
?>

View File

@ -0,0 +1,390 @@
<?php
/**
* @package Phoca Gallery
* @author Jan Pavelka - https://www.phoca.cz
* @copyright Copyright (C) Jan Pavelka https://www.phoca.cz
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 and later
* @cms Joomla
* @copyright Copyright (C) Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
use Joomla\CMS\Factory;
use Joomla\CMS\Menu\AbstractMenu;
jimport('joomla.application.component.helper');
class PhocaGalleryRoute
{
public static function getCategoriesRoute() {
// TEST SOLUTION
/* $app = Factory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
$activeId = 0;
if (isset($active->id)){
$activeId = $active->id;
}
$itemId = 0;
/* There cannot be $item->id yet
// 1) get standard item id if exists
if (isset($item->id)) {
$itemId = (int)$item->id;
}*//*
$option = $app->input->get( 'option', '', 'string' );
$view = $app->input->get( 'view', '', 'string' );
if ($option == 'com_phocagallery' && $view == 'category') {
if ((int)$activeId > 0) {
// 2) if there are two menu links, try to select the one active
$itemId = $activeId;
}
}*/
$needles = array(
'categories' => ''
);
$link = 'index.php?option=com_phocagallery&view=categories';
if($item = self::_findItem($needles, 1)) {
if(isset($item->query['layout'])) {
$link .= '&layout='.$item->query['layout'];
}
if (isset($item->id)) {
$link .= '&Itemid='.(int)$item->id;;
}
// TEST SOLUTION
/*if ((int)$itemId > 0) {
$link .= '&Itemid='.(int)$itemId;
} else if (isset($item->id) && ((int)$item->id > 0)) {
$link .= '&Itemid='.$item->id;
}*/
// $item->id should be a "categories view" and it should have preference to category view
// so first we check item->id then itemId
// 1) there can be two categories view, when yes, first set itemId then item->id
// 2) but when there is one category view, and one categories view - first select item->id (categories view)
// 3) then select itemid even we don't know if categories or category view
/*if ((int)$itemId > 0 && isset($active->query['view']) && $active->query['view'] == 'categories') {
$link .= '&Itemid='.(int)$itemId;
} else if (isset($item->id) && ((int)$item->id > 0)) {
$link .= '&Itemid='.$item->id;
} else if ((int)$itemId > 0) {
$link .= '&Itemid='.(int)$itemId;
}*/
};
return $link;
}
public static function getCategoryRoute($catid, $catidAlias = '') {
// TEST SOLUTION
/*$app = Factory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
$option = $app->input->get( 'option', '', 'string' );
$activeId = 0;
$notCheckId = 1;
if (isset($active->id)){
$activeId = $active->id;
}
if ((int)$activeId > 0 && $option == 'com_phocagallery') {
$needles = array(
'category' => (int)$catid,
'categories' => (int)$activeId
);
$notCheckId = 0;// when categories view, do not check id
// we need to check the ID - there can be more menu links (to categories, to category)
} else {
$needles = array(
'category' => (int)$catid,
'categories' => ''
);
$notCheckId = 0;
}
if ($catidAlias != '') {
$catid = $catid . ':' . $catidAlias;
}
//Create the link
$link = 'index.php?option=com_phocagallery&view=category&id='. $catid;
if($item = PhocaGalleryRoute::_findItem($needles, $notCheckId)) {
if(isset($item->query['layout'])) {
$link .= '&layout='.$item->query['layout'];
}
if (isset($item->id) && ((int)$item->id > 0)) {
$link .= '&Itemid='.$item->id;
}
};*/
$needles = array(
'category' => (int)$catid,
'categories' => ''
);
if ($catidAlias != '') {
$catid = $catid . ':' . $catidAlias;
}
//Create the link
$link = 'index.php?option=com_phocagallery&view=category&id='. $catid;
if($item = self::_findItem($needles)) {
if(isset($item->query['layout'])) {
$link .= '&layout='.$item->query['layout'];
}
if(isset($item->id)) {
$link .= '&Itemid='.$item->id;
}
};
return $link;
}
public static function getFeedRoute($view = 'categories', $catid = 0, $catidAlias = '') {
if ($view == 'categories') {
$needles = array(
'categories' => ''
);
$link = 'index.php?option=com_phocagallery&view=categories&format=feed';
} else if ($view == 'category') {
if ($catid > 0) {
$needles = array(
'category' => (int) $catid,
'categories' => ''
);
if ($catidAlias != '') {
$catid = (int)$catid . ':' . $catidAlias;
}
$link = 'index.php?option=com_phocagallery&view=category&format=feed&id='.$catid;
} else {
$needles = array(
'categories' => ''
);
$link = 'index.php?option=com_phocagallery&view=categories&format=feed';
}
} else {
$needles = array(
'categories' => ''
);
$link = 'index.php?option=com_phocagallery&view=feed&format=feed';
}
if($item = PhocaGalleryRoute::_findItem($needles, 1)) {
if(isset($item->query['layout'])) {
$link .= '&layout='.$item->query['layout'];
}
if (isset($item->id) && ((int)$item->id > 0)) {
$link .= '&Itemid='.$item->id;
}
};
return $link;
}
public static function getCategoryRouteByTag($tagId) {
$needles = array(
'category' => '',
//'section' => (int) $sectionid,
'categories' => ''
);
$db = Factory::getDBO();
$query = 'SELECT a.id, a.title, a.link_ext, a.link_cat'
.' FROM #__phocagallery_tags AS a'
.' WHERE a.id = '.(int)$tagId
.' ORDER BY a.id';
$db->setQuery($query, 0, 1);
$tag = $db->loadObject();
//Create the link
if (isset($tag->id)) {
$link = 'index.php?option=com_phocagallery&view=category&id=0:category&tagid='.(int)$tag->id;
} else {
$link = 'index.php?option=com_phocagallery&view=category&id=0:category&tagid=0';
}
if($item = self::_findItem($needles)) {
if(isset($item->query['layout'])) {
$link .= '&layout='.$item->query['layout'];
}
if (isset($item->id) && ((int)$item->id > 0)) {
$link .= '&Itemid='.$item->id;
}
};
return $link;
}
public static function getImageRoute($id, $catid = 0, $idAlias = '', $catidAlias = '', $type = 'detail', $suffix = '')
{
// TEST SOLUTION
/*$app = Factory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
$option = $app->input->get( 'option', '', 'string' );
$activeId = 0;
$notCheckId = 0;
if (isset($active->id)){
$activeId = $active->id;
}
if ((int)$activeId > 0 && $option == 'com_phocagallery') {
$needles = array(
'detail' => (int) $id,
'category' => (int) $catid,
'categories' => (int)$activeId
);
$notCheckId = 1;
} else {
$needles = array(
'detail' => (int) $id,
'category' => (int) $catid,
'categories' => ''
);
$notCheckId = 0;
}*/
$needles = array(
'detail' => (int) $id,
'category' => (int) $catid,
'categories' => ''
);
if ($idAlias != '') {
$id = $id . ':' . $idAlias;
}
if ($catidAlias != '') {
$catid = $catid . ':' . $catidAlias;
}
//Create the link
switch ($type)
{
case 'detail':
$link = 'index.php?option=com_phocagallery&view=detail&catid='. $catid .'&id='. $id;
break;
default:
$link = '';
break;
}
if ($item = self::_findItem($needles)) {
if (isset($item->id) && ((int)$item->id > 0)) {
$link .= '&Itemid='.$item->id;
}
}
if ($suffix != '') {
$link .= '&'.$suffix;
}
return $link;
}
protected static function _findItem($needles, $notCheckId = 0, $component = 'com_phocagallery') {
$app = Factory::getApplication();
//$menus = $app->getMenu('site', array()); // Problems in indexer
$menus = AbstractMenu::getInstance('site');
$items = $menus->getItems('component', $component);
//$menu = $menus;//$app->getMenu();
$active = $menus->getActive();
$option = $app->input->get( 'option', '', 'string' );
// Don't check ID for specific views. e.g. categories view does not have ID
$notCheckIdArray = array('categories');
if(!$items) {
$itemId = $app->input->get('Itemid', 0, 'int');
if ($itemId > 0) {
$item = new stdClass();
$item->id = $itemId;
return $item;
}
return null;
}
$match = null;
// FIRST - test active menu link
foreach($needles as $needle => $id) {
if (isset($active->query['option']) && $active->query['option'] == $component
&& isset($active->query['view']) && $active->query['view'] == $needle
&& (in_array($needle, $notCheckIdArray) || (isset($active->query['id']) && $active->query['id'] == $id ))
) {
$match = $active;
}
}
if(isset($match)) {
return $match;
}
// SECOND - if not find in active, try to run other items
// ordered by function which calls this function - e.g. file, category, categories
// as last the categories view should be checked, it has no ID so we skip the checking
// of ID for categories view with OR: in_array($needle, $notCheckIdArray) ||
foreach($needles as $needle => $id) {
foreach($items as $item) {
if (isset($item->query['option']) && $item->query['option'] == $component
&& isset($item->query['view']) && $item->query['view'] == $needle
&& (in_array($needle, $notCheckIdArray) || (isset($item->query['id']) && $item->query['id'] == $id ))
) {
$match = $item;
}
}
if(isset($match)) {
break;
}
}
return $match;
}
}
?>

View File

@ -0,0 +1,170 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_phocagallery
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die();
use Joomla\CMS\Component\Router\Rules\MenuRules;
use Joomla\CMS\Factory;
class PhocaGalleryRouterrules extends MenuRules
{
public function preprocess(&$query) {
parent::preprocess($query);
}
protected function buildLookup($language = '*') {
parent::buildLookup($language);
}
/*
* PHOCAEDIT
*/
public function parse(&$segments, &$vars) {
// SPECIFIC CASE TAG - tag search output in category view
// 1. components/com_phocagallery/router.php getCategorySegment() - BUILD
// 2. administrator/components/com_phocagallery/libraries/phocadownload/path/routerrules.php build() - BUILD
// 3. administrator/components/com_phocagallery/libraries/phocadownload/path/routerrules.php parse() - PARSE
$app = Factory::getApplication();
$tagId = $app->input->get('tagid', 0, 'int');
if ($segments[0] == 'category' && (int)$tagId > 0){
// We are in category view but tags output
$vars['view'] = 'category';
unset($segments[0]);
}
return parent::parse($segments, $vars);
}
/* EDIT of libraries/src/Component/Router/Rules/StandardRules.php build function
* Because we need to manage when categories view does not have any ID
* PHOCAEDIT
*/
public function build(&$query, &$segments) {
if (!isset($query['Itemid'], $query['view'])) {
return;
}
// Get the menu item belonging to the Itemid that has been found
$item = $this->router->menu->getItem($query['Itemid']);
if ($item === null || $item->component !== 'com_' . $this->router->getName() || !isset($item->query['view'])) {
return;
}
// PHOCAEDIT
if (!isset($item->query['id']) ){
$item->query['id'] = 0;
}
// Get menu item layout
$mLayout = isset($item->query['layout']) ? $item->query['layout'] : null;
// Get all views for this component
$views = $this->router->getViews();
// Return directly when the URL of the Itemid is identical with the URL to build
if ($item->query['view'] === $query['view']) {
$view = $views[$query['view']];
if (!$view->key) {
unset($query['view']);
if (isset($query['layout']) && $mLayout === $query['layout']) {
unset($query['layout']);
}
return;
}
if (isset($query[$view->key]) && $item->query[$view->key] == (int) $query[$view->key]) {
unset($query[$view->key]);
while ($view) {
unset($query[$view->parent_key]);
$view = $view->parent;
}
unset($query['view']);
if (isset($query['layout']) && $mLayout === $query['layout']) {
unset($query['layout']);
}
return;
}
}
// Get the path from the view of the current URL and parse it to the menu item
$path = array_reverse($this->router->getPath($query), true);
$found = false;
foreach ($path as $element => $ids) {
$view = $views[$element];
if ($found === false && $item->query['view'] === $element) {
if ($view->nestable) {
$found = true;
} elseif ($view->children) {
$found = true;
continue;
}
}
if ($found === false) {
// Jump to the next view
continue;
}
if ($ids) {
if ($view->nestable) {
$found2 = false;
foreach (array_reverse($ids, true) as $id => $segment) {
if ($found2) {
$segments[] = str_replace(':', '-', $segment);
} elseif ((int) $item->query[$view->key] === (int) $id) {
$found2 = true;
// SPECIFIC CASE TAG - tag search output in category view
// 1. components/com_phocagallery/router.php getCategorySegment() - BUILD
// 2. administrator/components/com_phocagallery/libraries/phocadownload/path/routerrules.php build() - BUILD
// 3. administrator/components/com_phocagallery/libraries/phocadownload/path/routerrules.php parse() - PARSE
if ((int)$query['id'] == 0 && $query['view'] == 'category' && isset($query['tagid']) && (int)$query['tagid'] > 0) {
$segments[] = 'category';
}
}
}
} elseif ($ids === true) {
$segments[] = $element;
} else {
$segments[] = str_replace(':', '-', current($ids));
}
}
if ($view->parent_key) {
// Remove parent key from query
unset($query[$view->parent_key]);
}
}
if ($found) {
unset($query[$views[$query['view']]->key], $query['view']);
if (isset($query['layout']) && $mLayout === $query['layout']) {
unset($query['layout']);
}
}
}
}