Current Path :
/
home
/
develito
/
public_html
/
components
/
com_sobipro
/
lib
/
ctrl
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/develito/public_html/components/com_sobipro/lib/ctrl/category.php
<?php /** * @package: SobiPro Library * * @author * Name: Sigrid Suski & Radek Suski, Sigsiu.NET GmbH * Email: sobi[at]sigsiu.net * Url: https://www.Sigsiu.NET * * @copyright Copyright (C) 2006 - 2020 Sigsiu.NET GmbH (https://www.sigsiu.net). All rights reserved. * @license GNU/LGPL Version 3 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3 * as published by the Free Software Foundation, and under the additional terms according section 7 of GPL v3. * See https://www.gnu.org/licenses/lgpl.html and https://www.sigsiu.net/licenses. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * * @created 10-Jan-2009 by Radek Suski * @modified 04 September 2020 by Sigrid Suski */ defined( 'SOBIPRO' ) || exit( 'Restricted access' ); use Sobi\Input\Input; use Sobi\FileSystem\FileSystem; SPLoader::loadController( 'section' ); /** * Class SPCategoryCtrl */ class SPCategoryCtrl extends SPSectionCtrl { /*** @var string */ protected $_defTask = 'view'; /*** @var string */ protected $_type = 'category'; /** * @return bool * @throws SPException * @throws \Sobi\Error\Exception */ public function execute() { $r = false; switch ( $this->_task ) { case 'chooser': case 'expand': SPLoader::loadClass( 'html.input' ); $r = true; $this->chooser( ( $this->_task == 'expand' ) ); break; case 'parents': $r = true; $this->parents(); break; case 'icon': $r = true; $this->iconChooser(); break; case 'iconFonts': $r = true; $this->iconFonts(); break; default: /* case parent didn't registered this task, it was an error */ if ( !( parent::execute() ) && $this->name() == __CLASS__ ) { Sobi::Error( $this->name(), SPLang::e( 'SUCH_TASK_NOT_FOUND', Input::Task() ), SPC::NOTICE, 404, __LINE__, __FILE__ ); } else { $r = true; } break; } return $r; } /** * @throws SPException */ protected function iconChooser() { if ( !( Sobi::Can( 'category.edit' ) ) ) { Sobi::Error( 'category', 'You have no (longer) permission to access this site', SPC::ERROR, 403, __LINE__, __FILE__ ); } if ( strlen( Input::Cmd( 'font' ) ) ) { return $this->iconFont(); } $folder = Input::String( 'iconFolder', 'request', null ); $callback = Input::Cmd( 'callback', 'request', 'SPSelectIcon' ); $dir = $folder ? Sobi::Cfg( 'images.category_icons' ) . str_replace( '.', '/', $folder ) . '/' : Sobi::Cfg( 'images.category_icons' ); $files = []; $dirs = []; if ( $folder ) { $up = explode( '.', $folder ); unset( $up[ count( $up ) - 1 ] ); $dirs[] = [ 'name' => Sobi::Txt( 'FOLEDR_UP' ), 'count' => ( count( scandir( $dir . '..' ) ) - 2 ), 'url' => Sobi::Url( [ 'task' => 'category.icon', 'out' => 'html', 'iconFolder' => ( count( $up ) ? implode( '.', $up ) : null ) ] ), ]; } $ext = [ 'png', 'jpg', 'jpeg', 'gif', 'webp' ]; if ( ( is_dir( $dir ) ) && ( $dh = opendir( $dir ) ) ) { while ( ( $file = readdir( $dh ) ) !== false ) { if ( ( filetype( $dir . $file ) == 'file' ) && in_array( strtolower( FileSystem::GetExt( $file ) ), $ext ) ) { $files[] = [ 'name' => $folder ? str_replace( '.', '/', $folder ) . '/' . $file : $file, 'path' => str_replace( '\\', '/', str_replace( SOBI_ROOT, Sobi::Cfg( 'live_site' ), str_replace( '//', '/', $dir . $file ) ) ), ]; } elseif ( filetype( $dir . $file ) == 'dir' && !( $file == '.' || $file == '..' ) ) { $dirs[] = [ 'name' => $file, 'count' => ( count( scandir( $dir . $file ) ) - 2 ), 'path' => str_replace( '\\', '/', str_replace( SOBI_ROOT, Sobi::Cfg( 'live_site' ), str_replace( '//', '/', $dir . $file ) ) ), 'url' => Sobi::Url( [ 'task' => 'category.icon', 'out' => 'html', 'iconFolder' => ( $folder ? $folder . '.' . $file : $file ) ] ), ]; } } closedir( $dh ); } sort( $files ); sort( $dirs ); $view = SPFactory::View( 'category' ); $view->setTemplate( 'category.icon' ); $view->assign( $this->_task, 'task' ); $view->assign( $callback, 'callback' ); $view->assign( $files, 'files' ); $symbol = Sobi::Cfg( 'image.folder_symbol', 'icon-folder-close' ); $view->assign( $symbol, 'symbol' ); $view->assign( $dirs, 'directories' ); $view->icon(); } /** * @throws SPException */ protected function iconFonts() { SPFactory::mainframe() ->cleanBuffer() ->customHeader(); $fonts = Sobi::Cfg( 'template.icon_fonts_arr', [] ); $keyFA4 = array_search( 'font-awesome-4', $fonts ); $keyFA5 = array_search( 'font-awesome-5', $fonts ); $selected = Input::String( 'selected' ); /* do not unload an selected font */ if ( $selected == 'font-awesome-4' ) { if ( $keyFA5 !== false ) { unset ( $fonts[ $keyFA5 ] ); $keyFA5 = false; } } if ( $selected == 'font-awesome-5' ) { if ( $keyFA4 !== false ) { unset ( $fonts[ $keyFA4 ] ); $keyFA4 = false; } } if ( ( $keyFA4 !== false ) && ( $keyFA5 !== false ) ) { unset ( $fonts[ $keyFA4 ] ); // if Font Awesome 4 and 5 are selected, only 5 will be loaded } if ( count( $fonts ) ) { foreach ( $fonts as $i => $font ) { if ( strstr( $font, '-local' ) ) { $fonts[ $i ] = str_replace( '-local', null, $font ); } } } exit( json_encode( $fonts ) ); } /** * @throws SPException */ protected function iconFont() { $font = Input::Cmd( 'font' ); if ( strstr( $font, 'font-' ) ) { SPFactory::mainframe() ->cleanBuffer() ->customHeader(); exit( FileSystem::Read( SPLoader::translatePath( 'etc.fonts.' . $font, 'front', true, 'json' ) ) ); } } /** * Shows the category chooser. * * @param bool $menu * * @throws SPException * @throws \Sobi\Error\Exception */ protected function chooser( $menu = false ) { $out = Input::Cmd( 'out', 'request', null ); $exp = Input::Int( 'expand', 'request', 0 ); $multi = Input::Int( 'multiple', 'request', 0 ); $tpl = Input::Word( 'treetpl', 'request', null ); /* load the SigsiuTree class */ $tree = SPLoader::loadClass( 'mlo.tree' ); $ordering = defined( 'SOBI_ADM_PATH' ) ? Sobi::GetUserState( 'categories.order', 'corder', 'position.asc' ) : Sobi::Cfg( 'list.categories_ordering' ); /* create new instance */ $tree = new $tree( $ordering ); /* set link */ if ( $menu ) { $tree->setId( 'menuTree' ); if ( defined( 'SOBIPRO_ADM' ) ) { $link = Sobi::Url( [ 'sid' => '{sid}' ], false, false, true ); } else { $link = Sobi::Url( [ 'sid' => '{sid}' ] ); } } else { $link = "javascript:SP_selectCat( '{sid}' )"; } $tree->setHref( $link ); /* set the task to expand the tree */ $tree->setTask( 'category.chooser' ); /* disable the category which is currently edited - category cannot be within it self */ if ( !$multi ) { if ( Input::Sid() != Sobi::Section() ) { $tree->disable( Input::Sid() ); } $tree->setPid( Input::Sid() ); } else { $tree->disable( Sobi::Reg( 'current_section' ) ); } /* case we are extending the existing tree */ if ( $out == 'xml' && $exp ) { $pid = Input::Int( 'pid', 'request', 0 ); $pid = $pid ? $pid : Input::Sid(); $tree->setPid( $pid ); $tree->disable( $pid ); $tree->extend( $exp ); } /* otherwise we are creating a new tree */ else { /* init the tree for the current section */ $tree->init( Sobi::Reg( 'current_section' ) ); /* load model */ if ( !$this->_model ) { $this->setModel( SPLoader::loadModel( 'category' ) ); } /* create new view */ $class = SPLoader::loadView( 'category' ); $view = new $class(); /* assign the task and the tree */ $view->assign( $this->_task, 'task' ); $view->assign( $tree, 'tree' ); $view->assign( $this->_model, 'category' ); /* select template to show */ if ( $tpl ) { $view->setTemplate( 'category.' . $tpl ); } elseif ( $multi ) { $view->setTemplate( 'category.mchooser' ); } else { $view->setTemplate( 'category.chooser' ); } Sobi::Trigger( 'Category', 'ChooserView', [ &$view ] ); $view->chooser(); } } /** * @throws SPException * @throws \Sobi\Error\Exception */ private function parents() { // sleep( 5 ); $sid = Input::Sid(); $out = Input::Cmd( 'out', 'request', 'json' ); $path = SPFactory::config()->getParentPath( $sid, true, false, true ); $cats = []; if ( count( $path ) ) { $childs = 0; foreach ( $path as $category ) { if ( $category[ 'id' ] == $sid ) { $childs = count( SPFactory::Category( $sid )->getChilds( 'category', false, 1 ) ); } $cats[] = [ 'id' => $category[ 'id' ], 'name' => $category[ 'name' ], 'childsCount' => $childs ]; } } switch ( $out ) { case 'json': SPFactory::mainframe() ->cleanBuffer() ->customHeader(); echo json_encode( [ 'id' => $sid, 'categories' => $cats ] ); exit; } } /** * @param $sid * @param bool $redirect * * @throws SPException */ protected function checkIn( $sid, $redirect = true ) { parent::checkIn( Input::Int( 'category_id' ), $redirect ); } }