2015-11-30 21:30:54 +00:00
< ? php
2021-08-16 17:11:22 +00:00
/*-------------------------------------------------------------------------------------------------------------| www . vdm . io |------/
____ ____ __ __ __
/ \ _ `\ /\ _` \ __ / \ \__ __ / \ \ / \ \__
\ \ , \L\_\ __ _ __ ___ ___ ___ ___ \ \ \ / \ \ / \_\ ____\ \ , _\ _ __ / \_\ \ \____ __ __\ \ , _\ ___ _ __
\ / _\__ \ / '__`\/\`' __\ / ' __` __`\ / __`\ /' _ `\ \ \ \ \ \/\ \ /',__\\ \ \/ /\`'__\/\ \ \ '__` \ / \ \ / \ \\ \ \ / / __ ` \ / \ ` ' __\
/ \ \L\ \ / \ __ / \ \ \ / / \ \ / \ \ / \ \ / \ \L\ \ / \ \ / \ \ \ \ \_\ \ \ \ / \__ , ` \\ \ \_\ \ \ / \ \ \ \ \L\ \ \ \_\ \\ \ \_ / \ \L\ \ \ \ /
\ ` \____\ \____\\ \_\ \ \_\ \_\ \_\ \____ / \ \_\ \_\ \ \____ / \ \_\ / \____ / \ \__\\ \_\ \ \_\ \_ , __ / \ \____ / \ \__\ \____ / \ \_\
\ / _____ / \ / ____ / \ / _ / \ / _ / \ / _ / \ / _ / \ / ___ / \ / _ / \ / _ / \ / ___ / \ / _ / \ / ___ / \ / __ / \ / _ / \ / _ / \ / ___ / \ / ___ / \ / __ / \ / ___ / \ / _ /
/------------------------------------------------------------------------------------------------------------------------------------/
2024-02-10 09:13:31 +00:00
@ version 3.0 . x
2021-08-16 17:11:22 +00:00
@ created 22 nd October , 2015
@ package Sermon Distributor
@ subpackage sermondistributor . php
@ author Llewellyn van der Merwe < https :// www . vdm . io />
@ copyright Copyright ( C ) 2015. All Rights Reserved
@ license GNU / GPL Version 2 or later - http :// www . gnu . org / licenses / gpl - 2.0 . html
A sermon distributor that links to Dropbox .
/----------------------------------------------------------------------------------------------------------------------------------*/
// No direct access to this file
defined ( '_JEXEC' ) or die ( 'Restricted access' );
2024-02-10 09:13:31 +00:00
// register additional namespace
\spl_autoload_register ( function ( $class ) {
// project-specific base directories and namespace prefix
$search = [
'libraries/jcb_powers/VDM.Joomla.FOF' => 'VDM\\Joomla\\FOF' ,
'libraries/jcb_powers/VDM.Joomla' => 'VDM\\Joomla'
];
// Start the search and load if found
$found = false ;
$found_base_dir = " " ;
$found_len = 0 ;
foreach ( $search as $base_dir => $prefix )
{
// does the class use the namespace prefix?
$len = strlen ( $prefix );
if ( strncmp ( $prefix , $class , $len ) === 0 )
{
// we have a match so load the values
$found = true ;
$found_base_dir = $base_dir ;
$found_len = $len ;
// done here
break ;
}
}
// check if we found a match
if ( ! $found )
{
// not found so move to the next registered autoloader
return ;
}
// get the relative class name
$relative_class = substr ( $class , $found_len );
// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = JPATH_ROOT . '/' . $found_base_dir . '/src' . str_replace ( '\\' , '/' , $relative_class ) . '.php' ;
// if the file exists, require it
if ( file_exists ( $file ))
{
require $file ;
}
});
use Joomla\CMS\Factory ;
use Joomla\CMS\Language\Text ;
use Joomla\CMS\Access\Access ;
use Joomla\CMS\Access\Rules as AccessRules ;
use Joomla\CMS\Component\ComponentHelper ;
2023-05-29 12:21:45 +00:00
use Joomla\CMS\Filesystem\File ;
2020-12-31 11:53:20 +00:00
use Joomla\CMS\Language\Language ;
2024-02-10 09:13:31 +00:00
use Joomla\CMS\MVC\Model\BaseDatabaseModel ;
use Joomla\CMS\Object\CMSObject ;
use Joomla\CMS\Table\Table ;
use Joomla\CMS\Uri\Uri ;
use Joomla\CMS\Version ;
2020-12-31 11:53:20 +00:00
use Joomla\Registry\Registry ;
use Joomla\String\StringHelper ;
2020-05-30 21:39:43 +00:00
use Joomla\Utilities\ArrayHelper ;
use PhpOffice\PhpSpreadsheet\IOFactory ;
use PhpOffice\PhpSpreadsheet\Spreadsheet ;
2021-08-16 17:11:22 +00:00
use PhpOffice\PhpSpreadsheet\Writer\Xlsx ;
use Joomla\CMS\Filesystem\Folder ;
2024-02-10 09:13:31 +00:00
use VDM\Joomla\Utilities\FileHelper ;
use VDM\Joomla\Utilities\MimeHelper ;
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper ;
use VDM\Joomla\Utilities\StringHelper as UtilitiesStringHelper ;
use VDM\Joomla\Utilities\ObjectHelper ;
use VDM\Joomla\FOF\Encrypt\AES ;
use VDM\Joomla\Utilities\GetHelper ;
use VDM\Joomla\Utilities\JsonHelper ;
use VDM\Joomla\Utilities\FormHelper ;
2021-08-16 17:11:22 +00:00
/**
* Sermondistributor component helper .
*/
abstract class SermondistributorHelper
{
/**
* Composer Switch
2024-02-10 09:13:31 +00:00
*
2021-08-16 17:11:22 +00:00
* @ var array
*/
2024-02-10 09:13:31 +00:00
protected static $composer = [];
2021-08-16 17:11:22 +00:00
/**
* The Main Active Language
2024-02-10 09:13:31 +00:00
*
2021-08-16 17:11:22 +00:00
* @ var string
*/
2020-01-05 22:53:13 +00:00
public static $langTag ;
2016-11-27 04:20:48 +00:00
2017-08-24 17:34:17 +00:00
/**
* The global params
**/
protected static $params = false ;
2018-03-03 16:43:27 +00:00
/**
* Update Watcher
**/
public static $updateWatch = 1 ;
/**
* Update Watcher ( if array is only one value )
**/
public static $updateWatch_ = 0 ;
2016-11-27 04:20:48 +00:00
/**
* The external source links auto
**/
protected static $links_externalsource_auto ;
2018-05-04 16:36:08 +00:00
2016-11-27 04:20:48 +00:00
/**
* The external source links manual
**/
protected static $links_externalsource_manual ;
2015-11-30 21:30:54 +00:00
/**
2016-11-27 04:20:48 +00:00
* The external source selection auto
2015-11-30 21:30:54 +00:00
**/
2016-11-27 04:20:48 +00:00
protected static $select_externalsource_auto ;
2018-05-04 16:36:08 +00:00
2015-11-30 21:30:54 +00:00
/**
2016-11-27 04:20:48 +00:00
* The external source selection manual
2015-11-30 21:30:54 +00:00
**/
2016-11-27 04:20:48 +00:00
protected static $select_externalsource_manual ;
2015-11-30 21:30:54 +00:00
/**
2016-11-27 04:20:48 +00:00
* The update errors
2015-11-30 21:30:54 +00:00
**/
2016-11-27 04:20:48 +00:00
protected static $updateErrors = array ();
2018-03-03 16:43:27 +00:00
2023-05-29 12:21:45 +00:00
/**
* prepare base64 string for url
*
* @ deprecate Use urlencode ();
*/
public static function base64_urlencode ( $string , $encode = false )
{
if ( $encode )
{
$string = base64_encode ( $string );
}
return str_replace ( array ( '+' , '/' ), array ( '-' , '_' ), $string );
}
/**
* prepare base64 string form url
*
* @ deprecate
*/
public static function base64_urldecode ( $string , $decode = false )
{
$string = str_replace ( array ( '-' , '_' ), array ( '+' , '/' ), $string );
if ( $decode )
{
$string = base64_decode ( $string );
}
return $string ;
}
2018-03-03 16:43:27 +00:00
2015-11-30 21:30:54 +00:00
/**
2016-11-27 04:20:48 +00:00
* get Download links of a sermon
2015-11-30 21:30:54 +00:00
**/
public static function getDownloadLinks ( & $sermon )
{
$links = array ();
// Get local key
$localkey = self :: getLocalKey ();
// decrypt the urls
2016-11-02 00:18:26 +00:00
$safe = new FOFEncryptAes ( $localkey , 128 );
2015-11-30 21:30:54 +00:00
// internal download url
2024-02-10 09:13:31 +00:00
$keyCounter = new \stdClass ;
2015-11-30 21:30:54 +00:00
$keyCounter -> sermon = $sermon -> id ;
if ( $sermon -> preacher )
{
$keyCounter -> preacher = $sermon -> preacher ;
}
if ( $sermon -> series )
{
$keyCounter -> series = $sermon -> series ;
}
2016-11-27 04:20:48 +00:00
$keyCounterRAW = $safe -> encryptString ( json_encode ( $keyCounter ));
$keyCounter = self :: base64_urlencode ( $keyCounterRAW );
2015-11-30 21:30:54 +00:00
$token = JSession :: getFormToken ();
2024-02-10 09:13:31 +00:00
$downloadURL = Uri :: root () . 'index.php?option=com_sermondistributor&task=download.file&key=' . $keyCounter . '&token=' . $token ;
2015-11-30 21:30:54 +00:00
// check if local .htaccess should be set
$setHtaccess = false ;
2016-11-27 04:20:48 +00:00
$onclick = ' onclick="sermonCounter(\'' . $keyCounterRAW . '\',\'FILENAME\');"' ;
2015-11-30 21:30:54 +00:00
// check what source of our link
switch ( $sermon -> source )
{
case 1 :
// local file get local folder and check if outside root (if not then allow direct)
$localFolder = JComponentHelper :: getParams ( 'com_sermondistributor' ) -> get ( 'localfolder' , JPATH_ROOT . '/images' ) . '/' ;
// should we allow direct downloads
$allowDirect = false ;
if ( 2 == $sermon -> link_type && strpos ( $localFolder , JPATH_ROOT ) !== false )
{
$allowDirect = true ;
2024-02-10 09:13:31 +00:00
$localFolderURL = Uri :: root () . str_replace ( JPATH_ROOT , '' , $localFolder );
2015-11-30 21:30:54 +00:00
// insure no double // is in the URL
$localFolderURL = str_replace ( '//' , '/' , $localFolderURL );
$localFolderURL = str_replace ( ':/' , '://' , $localFolderURL );
}
// insure no double // is in the path name
$localFolder = str_replace ( '//' , '/' , $localFolder );
$localFolder = str_replace ( ':/' , '://' , $localFolder );
if ( self :: checkArray ( $sermon -> local_files ))
{
foreach ( $sermon -> local_files as $key )
{
if ( 1 == $sermon -> link_type || ! $allowDirect )
{
// get the file name use the same method as the auto
$filename = self :: getDownloadFileName ( $sermon , $key , 'local' );
2016-11-27 04:20:48 +00:00
$lockedFolderPath = $safe -> encryptString ( $localFolder . $key );
$sermon -> download_links [ $filename ] = $downloadURL . '&link=' . self :: base64_urlencode ( $lockedFolderPath ) . '&filename=' . $filename ;
2015-11-30 21:30:54 +00:00
$sermon -> onclick [ $filename ] = '' ;
}
elseif ( 2 == $sermon -> link_type && $allowDirect )
{
$filename = $key ;
$sermon -> download_links [ $filename ] = $localFolderURL . $key ;
$sermon -> onclick [ $filename ] = str_replace ( 'FILENAME' , $filename , $onclick );
$setHtaccess = true ;
}
}
}
break ;
case 2 :
// Dropbox get global dropbox switch
2016-11-27 04:20:48 +00:00
$addToButton = JComponentHelper :: getParams ( 'com_sermondistributor' ) -> get ( 'add_to_button' , 0 );
2015-11-30 21:30:54 +00:00
if ( 1 == $sermon -> build )
{
if ( self :: checkArray ( $sermon -> manual_files ))
{
// manual dropbox
foreach ( $sermon -> manual_files as $key )
{
// get the link
2016-11-27 04:20:48 +00:00
$dropURL = self :: getExternalSourceLink ( 'manual' , 1 , $key );
2015-11-30 21:30:54 +00:00
if ( 1 == $sermon -> link_type && $dropURL )
{
// get the file name use the same method as the auto
$filename = self :: getDownloadFileName ( $sermon , $key , 'dropbox_manual' );
2016-11-27 04:20:48 +00:00
// should we encrypt string this string
if ( 'localKey34fdWEkl' == $localkey || ( base64_encode ( base64_decode ( $dropURL , true )) !== $dropURL )) // hmmm no global key has been set
{
$dropURL = $safe -> encryptString ( $dropURL );
}
2018-03-03 23:35:30 +00:00
// lock the info key
$infoKey = $safe -> encryptString ( $key );
$sermon -> download_links [ $filename ] = $downloadURL . '&info=' . self :: base64_urlencode ( $infoKey ) . '&link=' . self :: base64_urlencode ( $dropURL ) . '&filename=' . $filename ;
2015-11-30 21:30:54 +00:00
$sermon -> onclick [ $filename ] = '' ;
}
elseif ( 2 == $sermon -> link_type && $dropURL )
{
$filename = str_replace ( 'VDM_pLeK_h0uEr/' , '' , $key );
2016-11-27 04:20:48 +00:00
if ( 'localKey34fdWEkl' == $localkey ) // hmmm no global key has been set (so don't decrypt)
{
$sermon -> download_links [ $filename ] = $dropURL ;
}
else
{
$sermon -> download_links [ $filename ] = rtrim ( $safe -> decryptString ( $dropURL ), " \0 " );
}
2015-11-30 21:30:54 +00:00
$sermon -> onclick [ $filename ] = str_replace ( 'FILENAME' , $filename , $onclick );
}
// build dropbox switch if needed
2016-11-27 04:20:48 +00:00
if ( 1 == $addToButton && $dropURL )
2015-11-30 21:30:54 +00:00
{
2016-11-27 04:20:48 +00:00
if ( 'localKey34fdWEkl' == $localkey ) // hmmm no global key has been set (so don't decrypt)
{
$sermon -> dropbox_buttons [ $filename ] = str_replace ( '?dl=1' , '?dl=0' , $dropURL );
}
else
{
$sermon -> dropbox_buttons [ $filename ] = str_replace ( '?dl=1' , '?dl=0' , rtrim ( $safe -> decryptString ( $dropURL ), " \0 " ));
}
2015-11-30 21:30:54 +00:00
$sermon -> onclick_drobox [ $filename ] = str_replace ( 'FILENAME' , $filename , $onclick );
}
}
}
}
elseif ( 2 == $sermon -> build )
{
if ( self :: checkArray ( $sermon -> auto_sermons ))
{
// automatic dropbox
foreach ( $sermon -> auto_sermons as $filename => $key )
{
// get the link
2016-11-27 04:20:48 +00:00
$dropURL = self :: getExternalSourceLink ( 'auto' , 1 , $key );
2015-11-30 21:30:54 +00:00
if ( 1 == $sermon -> link_type && $dropURL )
{
2016-11-27 04:20:48 +00:00
// should we encrypt string this string
if ( 'localKey34fdWEkl' == $localkey || ( base64_encode ( base64_decode ( $dropURL , true )) !== $dropURL )) // hmmm no global key has been set
{
$dropURL = $safe -> encryptString ( $dropURL );
}
2018-03-03 23:35:30 +00:00
// lock the info key
$infoKey = $safe -> encryptString ( $key );
$sermon -> download_links [ $filename ] = $downloadURL . '&info=' . self :: base64_urlencode ( $infoKey ) . '&link=' . self :: base64_urlencode ( $dropURL ) . '&filename=' . $filename ;
2015-11-30 21:30:54 +00:00
$sermon -> onclick [ $filename ] = '' ;
}
elseif ( 2 == $sermon -> link_type && $dropURL )
{
2016-11-27 04:20:48 +00:00
if ( 'localKey34fdWEkl' == $localkey ) // hmmm no global key has been set (so don't decrypt)
{
$sermon -> download_links [ $filename ] = $dropURL ;
}
else
{
$sermon -> download_links [ $filename ] = rtrim ( $safe -> decryptString ( $dropURL ), " \0 " );
}
2015-11-30 21:30:54 +00:00
$sermon -> onclick [ $filename ] = str_replace ( 'FILENAME' , $filename , $onclick );
}
// build dropbox switch if needed
2016-11-27 04:20:48 +00:00
if ( 1 == $addToButton && $dropURL )
2015-11-30 21:30:54 +00:00
{
2016-11-27 04:20:48 +00:00
if ( 'localKey34fdWEkl' == $localkey ) // hmmm no global key has been set (so don't decrypt)
{
$sermon -> dropbox_buttons [ $filename ] = str_replace ( '?dl=1' , '?dl=0' , $dropURL );
}
else
{
$sermon -> dropbox_buttons [ $filename ] = str_replace ( '?dl=1' , '?dl=0' , rtrim ( $safe -> decryptString ( $dropURL ), " \0 " ));
}
2015-11-30 21:30:54 +00:00
$sermon -> onclick_drobox [ $filename ] = str_replace ( 'FILENAME' , $filename , $onclick );
}
}
}
}
break ;
case 3 :
// url get the file name use the same method as the auto
$filename = self :: getDownloadFileName ( $sermon , $sermon -> url , 'url' );
if ( 1 == $sermon -> link_type )
{
2016-11-27 04:20:48 +00:00
$lockedURL = $safe -> encryptString ( $sermon -> url );
$sermon -> download_links [ $filename ] = $downloadURL . '&link=' . self :: base64_urlencode ( $lockedURL ) . '&filename=' . $filename ;
2015-11-30 21:30:54 +00:00
$sermon -> onclick [ $filename ] = '' ;
}
elseif ( 2 == $sermon -> link_type )
{
$sermon -> download_links [ $filename ] = $sermon -> url ;
$sermon -> onclick [ $filename ] = str_replace ( 'FILENAME' , $filename , $onclick );
}
break ;
}
// remove the values no longer needed
unset ( $sermon -> local_files );
unset ( $sermon -> manual_files );
unset ( $sermon -> auto_sermons );
unset ( $sermon -> url );
// should we set the local .htaccess for the download folder
if ( $setHtaccess )
{
// TODO we may need to add this latter to enforce download of files.
}
return true ;
}
2016-11-27 04:20:48 +00:00
2018-03-03 16:43:27 +00:00
public static function getNextUpdateValues ( $asArray = false )
2016-12-05 07:40:19 +00:00
{
2018-03-03 16:43:27 +00:00
// find the next value
$next = false ;
2016-12-05 07:40:19 +00:00
// get actual update values
$updates = self :: getExternalListingUpdateKeys ();
// get last update
2017-08-24 17:34:17 +00:00
$updatePath = self :: getFilePath ( 'path' , 'updatelast' , 'txt' , 'vDm' , JPATH_COMPONENT_ADMINISTRATOR );
2016-12-05 07:40:19 +00:00
if (( $lastUpdate = @ file_get_contents ( $updatePath )) !== FALSE && self :: checkArray ( $updates ))
{
2018-03-03 16:43:27 +00:00
// is it time to watch
if ( self :: $updateWatch_ > 0 )
{
// increment the watch, as this is the start of new round
self :: $updateWatch ++ ;
// new round has started
self :: $updateWatch_ = 0 ;
}
2016-12-05 07:40:19 +00:00
// now check what is next
$lastKey = array_search ( $lastUpdate , $updates );
if ( ! is_null ( $lastKey ))
{
$nextKey = $lastKey + 1 ;
if ( isset ( $updates [ $nextKey ]))
{
2018-03-03 16:43:27 +00:00
$next = $updates [ $nextKey ];
}
else
{
// last item in array, so next round about to start
self :: $updateWatch_ ++ ;
2016-12-05 07:40:19 +00:00
}
}
}
// rest and start with the first key
2018-03-03 16:43:27 +00:00
if ( ! $next && self :: checkArray ( $updates ))
2016-12-05 07:40:19 +00:00
{
// save the first set
$start = reset ( $updates );
2018-03-03 16:43:27 +00:00
$next = $start ;
2016-12-05 07:40:19 +00:00
}
2018-03-03 16:43:27 +00:00
// save to file if next is found
if ( $next )
{
self :: writeFile ( $updatePath , $next );
// convert to array of needed
if ( $asArray )
{
if ( strpos ( $next , ',' ) !== false )
{
$next = array_map ( 'trim' , explode ( ',' , $next ));
}
else
{
return false ;
}
}
}
return $next ;
2016-12-05 07:40:19 +00:00
}
2018-03-03 16:43:27 +00:00
2017-08-24 17:34:17 +00:00
/**
2024-02-10 09:13:31 +00:00
* Get the file path or url
*
* @ param string $type The ( url / path ) type to return
* @ param string $target The Params Target name ( if set )
* @ param string $fileType The kind of filename to generate ( if not set no file name is generated )
* @ param string $key The key to adjust the filename ( if not set ignored )
* @ param string $default The default path if not set in Params ( fallback path )
* @ param bool $createIfNotSet The switch to create the folder if not found
*
* @ return string On success the path or url is returned based on the type requested
* @ deprecated 3.3 Use FileHelper :: getPath ( ... );
*/
2018-09-06 08:34:13 +00:00
public static function getFilePath ( $type = 'path' , $target = 'filepath' , $fileType = null , $key = '' , $default = '' , $createIfNotSet = true )
2017-08-24 17:34:17 +00:00
{
2024-02-10 09:13:31 +00:00
// Get the file path or url
return FileHelper :: getPath ( $type , $target , $fileType , $key , $default , $createIfNotSet );
2018-03-03 16:43:27 +00:00
}
/**
2024-02-10 09:13:31 +00:00
* Write a file to the server
*
* @ param string $path The path and file name where to safe the data
* @ param string $data The data to safe
*
* @ return bool true On success
* @ deprecated 3.3 Use FileHelper :: write ( ... );
*/
2018-03-03 16:43:27 +00:00
public static function writeFile ( $path , $data )
2016-12-05 07:40:19 +00:00
{
2024-02-10 09:13:31 +00:00
return FileHelper :: write ( $path , $data );
2018-03-03 16:43:27 +00:00
}
protected static function saveFile ( $data , $path_filename )
{
return self :: writeFile ( $path_filename , $data );
2016-12-05 07:40:19 +00:00
}
2016-11-27 04:20:48 +00:00
public static function getExternalListingUpdateKeys ( $id = null , $updateMethod = 2 , $returnType = 1 )
{
// first check if this file already has statistics
$db = JFactory :: getDbo ();
$query = $db -> getQuery ( true );
$query -> select ( $db -> quoteName ( array ( 'id' , 'sharedurl' , 'folder' , 'permissiontype' , 'dropboxoptions' , 'build' )));
$query -> from ( $db -> quoteName ( '#__sermondistributor_external_source' ));
2016-12-05 07:40:19 +00:00
if ( $updateMethod && is_numeric ( $updateMethod ))
{
$query -> where ( $db -> quoteName ( 'update_method' ) . ' = ' . ( int ) $updateMethod );
}
2016-11-27 04:20:48 +00:00
if ( $id && is_numeric ( $id ))
{
$query -> where ( $db -> quoteName ( 'id' ) . ' = ' . ( int ) $id );
}
elseif ( $id && self :: checkArray ( $id ))
{
$ids = implode ( ',' , array_map ( 'intval' , $id ));
$query -> where ( $db -> quoteName ( 'id' ) . ' IN (' . $ids . ')' );
}
$query -> where ( $db -> quoteName ( 'published' ) . ' = 1' );
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
{
$results = $db -> loadObjectList ();
$updates = array ();
foreach ( $results as $result )
{
if ( 'full' == $result -> permissiontype )
{
// load folder or urls
switch ( $result -> dropboxoptions )
{
case 1 : // sharedurl
if ( self :: checkJson ( $result -> sharedurl ))
{
$targets = json_decode ( $result -> sharedurl ) -> tsharedurl ;
}
break ;
case 2 : // folders
if ( self :: checkJson ( $result -> folder ))
{
$targets = json_decode ( $result -> folder ) -> tfolder ;
}
break ;
}
if ( self :: checkArray ( $targets ))
{
foreach ( $targets as $key => $value )
{
$nr = $key + 1 ;
// id, target, type
if ( 1 == $returnType )
{
$updates [] = $result -> id . ', ' . $nr . ', ' . $result -> build ;
}
else // only return the targets
{
$updates [] = $nr ;
}
}
}
}
else
{
// id, target, type
if ( 1 == $returnType )
{
$updates [] = $result -> id . ', 1, ' . $result -> build ;
}
else // only return the targets
{
$updates [] = 1 ;
}
}
}
return $updates ;
}
return false ;
}
2018-05-04 16:36:08 +00:00
2016-11-27 04:20:48 +00:00
public static function getExternalSourceLink ( $type , $return = 7 , $get = false , $target = 'links' )
2015-11-30 21:30:54 +00:00
{
// make sure all defaults are set
2016-11-27 04:20:48 +00:00
$found = self :: checkExternalSourceLocalListing ( $type , $target );
2015-11-30 21:30:54 +00:00
if ( $found )
{
switch ( $return )
{
case 1 :
// return a link
2016-11-27 04:20:48 +00:00
if ( isset ( self :: $ { $target . '_externalsource_' . $type }[ $get ]))
2015-11-30 21:30:54 +00:00
{
2016-11-27 04:20:48 +00:00
return self :: $ { $target . '_externalsource_' . $type }[ $get ];
2015-11-30 21:30:54 +00:00
}
break ;
case 2 :
// return all links
2016-11-27 04:20:48 +00:00
return self :: $ { $target . '_externalsource_' . $type };
2015-11-30 21:30:54 +00:00
break ;
default :
// just confirm that it is set
return true ;
break ;
}
}
return false ;
}
2018-03-03 23:35:30 +00:00
public static function countDownload ( $counter , $filename )
2015-11-30 21:30:54 +00:00
{
// Get local key
$localkey = self :: getLocalKey ();
2016-11-02 00:18:26 +00:00
$opener = new FOFEncryptAes ( $localkey , 128 );
2016-11-27 04:20:48 +00:00
$counter = json_decode ( rtrim ( $opener -> decryptString ( $counter ), " \0 " ));
2015-11-30 21:30:54 +00:00
if ( self :: checkObject ( $counter ))
{
$counter -> filename = $filename ;
// set the date object
$date = JFactory :: getDate ();
// first check if this file already has statistics
$db = JFactory :: getDbo ();
$query = $db -> getQuery ( true );
$query -> select ( $db -> quoteName ( array ( 'id' , 'counter' )));
$query -> from ( $db -> quoteName ( '#__sermondistributor_statistic' ));
$query -> where ( $db -> quoteName ( 'sermon' ) . ' = ' . ( int ) $counter -> sermon );
$query -> where ( $db -> quoteName ( 'filename' ) . ' = ' . $db -> quote ( $counter -> filename ));
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
{
$statistic = $db -> loadObject ();
// already has an entry
$statistic -> counter ++ ;
$statistic -> modified = $date -> toSql ();
// update the entry
return $db -> updateObject ( '#__sermondistributor_statistic' , $statistic , 'id' );
}
else
{
// set a new entry
$counter -> counter = 1 ;
$counter -> published = 1 ;
$counter -> created = $date -> toSql ();
$counter -> access = 1 ;
$counter -> version = 1 ;
// set a new entry
$done = $db -> insertObject ( '#__sermondistributor_statistic' , $counter );
// if done return last used id
if ( $done )
{
$newId = $db -> insertid ();
// make sure the access of asset is set
return self :: setAsset ( $newId , 'statistic' );
}
}
}
return false ;
}
2018-03-03 23:35:30 +00:00
public static function getFileInfo ( $key )
{
if ( self :: checkString ( $key ) && ( base64_encode ( base64_decode ( $key , true )) === $key ))
{
// Get local key
$localkey = self :: getLocalKey ();
$opener = new FOFEncryptAes ( $localkey , 128 );
$key = rtrim ( $opener -> decryptString ( $key ), " \0 " );
// load the links from the database
$db = JFactory :: getDbo ();
// Create a new query object.
$query = $db -> getQuery ( true );
$query -> select ( 'size' );
$query -> from ( $db -> quoteName ( '#__sermondistributor_local_listing' ));
$query -> where ( $db -> quoteName ( 'key' ) . ' = ' . $db -> quote ( $key ));
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
{
$info = array ();
// get the size of the file
$info [ 'filesize' ] = $db -> loadResult ();
// get the mime type
2024-02-10 09:13:31 +00:00
$info [ 'type' ] = MimeHelper :: mimeType ( $key );
2018-03-03 23:35:30 +00:00
// return info
return $info ;
}
}
return false ;
}
2020-01-05 22:53:13 +00:00
2018-03-03 23:35:30 +00:00
protected static function getDownloadFileName ( & $sermon , $file , $type )
2015-11-30 21:30:54 +00:00
{
// first get file name and file type
$file = str_replace ( 'VDM_pLeK_h0uEr/' , '' , $file );
$fileType = pathinfo ( $file , PATHINFO_EXTENSION );
if ( $fileType )
{
$file = str_replace ( '.' . $fileType , '' , $file );
}
else
{
$fileType = 'error' ;
}
// now build download name
$downloadName = array ();
// build the Download File Name - first add the preacher name if set
if ( $sermon -> preacher )
{
$downloadName [] = self :: safeString ( $sermon -> preacher_name , 'U' );
}
// add the series name if set
if ( $sermon -> series )
{
$downloadName [] = self :: safeString ( $sermon -> series_name , 'F' );
}
// add the category name if set
if ( $sermon -> catid && self :: checkString ( $sermon -> category ))
{
$downloadName [] = self :: safeString ( $sermon -> category , 'F' );
}
if ( 'dropbox_manual' == $type || 'local' == $type )
{
// add the main file name
$downloadName [] = self :: safeString ( $sermon -> name , 'F' );
$downloadName [] = self :: safeString ( $file , 'F' );
}
else
{
$downloadName [] = self :: safeString ( $sermon -> name , 'F' );
if ( 'error' == $fileType || strpos ( '?' , $fileType ) !== false || strpos ( '&' , $fileType ) !== false )
{
$fileType = 'mp3' ; // TODO we don't know the url filetype (setting to mp3 but this could be wrong)
}
}
// now build the download file name
return implode ( '__' , $downloadName ) . '.' . $fileType ;
}
/**
2016-11-27 04:20:48 +00:00
* check External Source Local Listing ( do we have the files )
2015-11-30 21:30:54 +00:00
**/
2016-11-27 04:20:48 +00:00
public static function checkExternalSourceLocalListing ( $type , $get = 'links' )
2015-11-30 21:30:54 +00:00
{
// get the local links
2016-11-27 04:20:48 +00:00
if ( isset ( self :: $ { $get . '_externalsource_' . $type }) && self :: checkArray ( self :: $ { $get . '_externalsource_' . $type }))
2015-11-30 21:30:54 +00:00
{
// return true we have links loaded
return true ;
}
2016-11-27 04:20:48 +00:00
else
{
$target = array ( 'links' => 'url' , 'select' => 'name' );
$build = array ( 'auto' => 2 , 'manual' => 1 );
if ( isset ( $build [ $type ]))
2015-11-30 21:30:54 +00:00
{
2016-11-27 04:20:48 +00:00
// load the links from the database
$db = JFactory :: getDbo ();
// Create a new query object.
$query = $db -> getQuery ( true );
$query -> select ( $db -> quoteName ( array ( 'key' , $target [ $get ])));
$query -> from ( $db -> quoteName ( '#__sermondistributor_local_listing' ));
$query -> where ( $db -> quoteName ( 'build' ) . ' = ' . ( int ) $build [ $type ]);
$query -> where ( $db -> quoteName ( 'published' ) . ' = 1' ); // TODO we can now limit the links to access groups
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
2015-11-30 21:30:54 +00:00
{
2016-11-27 04:20:48 +00:00
self :: $ { $get . '_externalsource_' . $type } = $db -> loadAssocList ( 'key' , $target [ $get ]);
// return true we have links loaded
2015-11-30 21:30:54 +00:00
return true ;
}
}
}
return false ;
}
/**
* get the localkey
**/
2016-11-27 04:20:48 +00:00
protected static $localkey = array ();
2015-11-30 21:30:54 +00:00
2016-11-27 04:20:48 +00:00
public static function getLocalKey ( $type = 'basic_key' )
2015-11-30 21:30:54 +00:00
{
2016-11-27 04:20:48 +00:00
if ( ! isset ( self :: $localkey [ $type ]))
2015-11-30 21:30:54 +00:00
{
// get the main key
2016-11-27 04:20:48 +00:00
self :: $localkey [ $type ] = JComponentHelper :: getParams ( 'com_sermondistributor' ) -> get ( $type , 'localKey34fdWEkl' );
2015-11-30 21:30:54 +00:00
}
2016-11-27 04:20:48 +00:00
return self :: $localkey [ $type ];
2015-11-30 21:30:54 +00:00
}
2016-11-27 04:20:48 +00:00
public static function updateExternalSource ( $id , $target = 0 , $type = false , $force = false , $sleutel = null )
2015-11-30 21:30:54 +00:00
{
2016-11-27 04:20:48 +00:00
$source = self :: getVar ( 'external_source' , ( int ) $id , 'id' , 'externalsources' );
if ( 1 == $source ) // Dropbox is the source
2015-11-30 21:30:54 +00:00
{
2016-11-27 04:20:48 +00:00
// load the file
JLoader :: import ( 'dropboxupdater' , JPATH_COMPONENT_SITE . '/helpers' );
// update types
$types = array ( 'manual' , 'auto' );
// okay now update this type
if ( self :: checkString ( $type ) && in_array ( $type , $types ))
{
$dropbox = new Dropboxupdater ();
if ( $dropbox -> update ( $id , $target , $type , $force , $sleutel ))
{
return true ;
}
self :: setUpdateError ( $id , $dropbox -> getErrors ());
return false ;
}
2015-11-30 21:30:54 +00:00
}
2016-11-27 04:20:48 +00:00
self :: setUpdateError ( $id , array ( JText :: _ ( 'COM_SERMONDISTRIBUTOR_THE_EXTERNAL_SOURCE_COULD_NOT_BE_FOUND' )));
2015-11-30 21:30:54 +00:00
return false ;
}
2016-12-05 07:40:19 +00:00
public static function getSourceStatus ( $id )
{
// fist get errors if any is found
$errors = array ();
if ( $targets = self :: getExternalListingUpdateKeys ( $id , null , 1 ))
{
foreach ( $targets as $target )
{
$key = preg_replace ( '/[ ,]+/' , '' , trim ( $target ));
if ( $error = self :: getUpdateError ( 0 , $key ))
{
$errors [] = $error ;
}
}
}
// check when was the last update
$updateInfo = self :: updateInfo ( $id );
if ( ! $updateInfo )
{
$errors [] = JText :: _ ( 'COM_SERMONDISTRIBUTOR_THIS_SOURCE_HAS_NO_LOCAL_LISTING_SET' );
}
// build the return string
if ( isset ( $updateInfo [ 'last' ]) || self :: checkArray ( $errors ))
{
$body = array ();
// great we have source status
if ( isset ( $updateInfo [ 'last' ]))
{
$body [] = '<h3>' . JText :: _ ( 'COM_SERMONDISTRIBUTOR_LISTING_INFO' ) . '</h3>' ;
$body [] = '<p><b>' . JText :: _ ( 'COM_SERMONDISTRIBUTOR_LAST_UPDATE' ) . ':</b> <em>' . $updateInfo [ 'last' ];
$body [] = '</em><br /><b>' . JText :: _ ( 'COM_SERMONDISTRIBUTOR_NUMBER_OF_FILES_LISTED' ) . ':</b> <em>' . $updateInfo [ 'qty' ];
$body [] = '</em></p>' ;
}
// now set any errors found
if ( self :: checkArray ( $errors ))
{
$body [] = '<h3>' . JText :: _ ( 'COM_SERMONDISTRIBUTOR_NOTICE' ) . '</h3>' ;
$body [] = implode ( '' , $errors );
}
return '<a class="btn btn-small btn-success" href="#source-status' . $id . '" data-toggle="modal">' . JText :: _ ( 'COM_SERMONDISTRIBUTOR_VIEW_UPDATE_STATUS' ) . '</a>'
. JHtml :: _ ( 'bootstrap.renderModal' , 'source-status' . $id , array ( 'title' => JText :: _ ( 'COM_SERMONDISTRIBUTOR_SOURCE_STATUS_REPORT' )), implode ( '' , $body ));
}
// no status found
return false ;
}
public static function updateInfo ( $id )
{
$db = JFactory :: getDbo ();
// Create a new query object.
$query = $db -> getQuery ( true );
$query -> select ( $db -> quoteName ( array ( 'a.created' , 'a.modified' )));
$query -> from ( $db -> quoteName ( '#__sermondistributor_local_listing' , 'a' ));
$query -> where ( $db -> quoteName ( 'a.external_source' ) . ' = ' . ( int ) $id );
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$db -> execute ();
if ( $qty = $db -> getNumRows ())
{
$data = $db -> loadRowList ();
$last = 0 ;
foreach ( $data as $dates )
{
foreach ( $dates as $date )
{
$time = strtotime ( $date );
if ( $time > $last )
{
$last = $time ;
}
}
}
$info [ 'qty' ] = ( int ) $qty ;
$info [ 'last' ] = self :: fancyDate ( $last );
return $info ;
}
return false ;
}
2018-05-04 16:36:08 +00:00
2016-11-27 04:20:48 +00:00
public static function getUpdateError ( $id , $fileKey = null )
2015-11-30 21:30:54 +00:00
{
2016-11-27 04:20:48 +00:00
// get update error from file
if ( $fileKey )
{
2017-08-24 17:34:17 +00:00
$file_path = self :: getFilePath ( 'path' , 'updateerror' , 'txt' , $fileKey , JPATH_COMPONENT_ADMINISTRATOR );
2016-11-27 04:20:48 +00:00
// check if it is set
if (( $text = @ file_get_contents ( $file_path )) !== FALSE )
2015-11-30 21:30:54 +00:00
{
2016-11-27 04:20:48 +00:00
// no error on success
if ( 'success' != $text )
2015-11-30 21:30:54 +00:00
{
2016-11-27 04:20:48 +00:00
return $text ;
2015-11-30 21:30:54 +00:00
}
}
2016-11-27 04:20:48 +00:00
return false ;
}
2016-12-05 07:40:19 +00:00
elseif ( isset ( self :: $updateErrors [ $id ]) && self :: checkArray ( self :: $updateErrors [ $id ]))
2016-11-27 04:20:48 +00:00
{
2016-12-05 07:40:19 +00:00
return '<ul><li>' . implode ( '</li><li>' , self :: $updateErrors [ $id ]) . '</li></ul>' ;
2016-11-27 04:20:48 +00:00
}
return JText :: _ ( 'COM_SERMONDISTRIBUTOR_UNKNOWN_ERROR_HAS_OCCURRED' );
}
2018-05-04 16:36:08 +00:00
2016-11-27 04:20:48 +00:00
protected static function setUpdateError ( $id , $errorArray )
{
if ( self :: checkArray ( $errorArray ) && $id > 0 )
{
foreach ( $errorArray as $error )
{
if ( ! isset ( self :: $updateErrors [ $id ]))
{
self :: $updateErrors [ $id ] = array ();
}
self :: $updateErrors [ $id ][] = $error ;
}
2015-11-30 21:30:54 +00:00
}
}
2018-03-03 16:43:27 +00:00
2016-12-05 07:40:19 +00:00
/**
2020-05-30 21:39:43 +00:00
* Change to nice fancy date
2016-12-05 07:40:19 +00:00
*/
2020-11-30 16:57:29 +00:00
public static function fancyDate ( $date , $check_stamp = true )
2016-12-05 07:40:19 +00:00
{
2020-11-30 16:57:29 +00:00
if ( $check_stamp && ! self :: isValidTimeStamp ( $date ))
2016-12-05 07:40:19 +00:00
{
$date = strtotime ( $date );
}
return date ( 'jS \o\f F Y' , $date );
}
2019-04-04 11:52:38 +00:00
/**
2020-05-30 21:39:43 +00:00
* get date based in period past
2019-04-04 11:52:38 +00:00
*/
2020-11-30 16:57:29 +00:00
public static function fancyDynamicDate ( $date , $check_stamp = true )
2019-04-04 11:52:38 +00:00
{
2020-11-30 16:57:29 +00:00
if ( $check_stamp && ! self :: isValidTimeStamp ( $date ))
2019-04-04 11:52:38 +00:00
{
$date = strtotime ( $date );
}
// older then year
$lastyear = date ( " Y " , strtotime ( " -1 year " ));
$tragetyear = date ( " Y " , $date );
if ( $tragetyear <= $lastyear )
{
return date ( 'm/d/y' , $date );
}
// same day
$yesterday = strtotime ( " -1 day " );
if ( $date > $yesterday )
{
return date ( 'g:i A' , $date );
}
// just month day
return date ( 'M j' , $date );
}
2017-02-17 20:21:37 +00:00
/**
2020-05-30 21:39:43 +00:00
* Change to nice fancy day time and date
2017-02-17 20:21:37 +00:00
*/
2020-11-30 16:57:29 +00:00
public static function fancyDayTimeDate ( $time , $check_stamp = true )
2017-02-17 20:21:37 +00:00
{
2020-11-30 16:57:29 +00:00
if ( $check_stamp && ! self :: isValidTimeStamp ( $time ))
2017-02-17 20:21:37 +00:00
{
$time = strtotime ( $time );
}
return date ( 'D ga jS \o\f F Y' , $time );
}
2016-12-05 07:40:19 +00:00
/**
2020-05-30 21:39:43 +00:00
* Change to nice fancy time and date
2016-12-05 07:40:19 +00:00
*/
2020-11-30 16:57:29 +00:00
public static function fancyDateTime ( $time , $check_stamp = true )
2016-12-05 07:40:19 +00:00
{
2020-11-30 16:57:29 +00:00
if ( $check_stamp && ! self :: isValidTimeStamp ( $time ))
2016-12-05 07:40:19 +00:00
{
$time = strtotime ( $time );
}
return date ( '(G:i) jS \o\f F Y' , $time );
}
/**
2020-05-30 21:39:43 +00:00
* Change to nice hour : minutes time
2016-12-05 07:40:19 +00:00
*/
2020-11-30 16:57:29 +00:00
public static function fancyTime ( $time , $check_stamp = true )
2016-12-05 07:40:19 +00:00
{
2020-11-30 16:57:29 +00:00
if ( $check_stamp && ! self :: isValidTimeStamp ( $time ))
2016-12-05 07:40:19 +00:00
{
$time = strtotime ( $time );
}
return date ( 'G:i' , $time );
}
2020-05-30 21:39:43 +00:00
/**
* set the date day as Sunday through Saturday
*/
2020-11-30 16:57:29 +00:00
public static function setDayName ( $date , $check_stamp = true )
2020-05-30 21:39:43 +00:00
{
2020-11-30 16:57:29 +00:00
if ( $check_stamp && ! self :: isValidTimeStamp ( $date ))
2020-05-30 21:39:43 +00:00
{
$date = strtotime ( $date );
}
return date ( 'l' , $date );
}
/**
* set the date month as January through December
*/
2020-11-30 16:57:29 +00:00
public static function setMonthName ( $date , $check_stamp = true )
2020-05-30 21:39:43 +00:00
{
2020-11-30 16:57:29 +00:00
if ( $check_stamp && ! self :: isValidTimeStamp ( $date ))
2020-05-30 21:39:43 +00:00
{
$date = strtotime ( $date );
}
return date ( 'F' , $date );
}
/**
* set the date day as 1 st
*/
2020-11-30 16:57:29 +00:00
public static function setDay ( $date , $check_stamp = true )
2020-05-30 21:39:43 +00:00
{
2020-11-30 16:57:29 +00:00
if ( $check_stamp && ! self :: isValidTimeStamp ( $date ))
2020-05-30 21:39:43 +00:00
{
$date = strtotime ( $date );
}
return date ( 'jS' , $date );
}
/**
* set the date month as 5
*/
2020-11-30 16:57:29 +00:00
public static function setMonth ( $date , $check_stamp = true )
2020-05-30 21:39:43 +00:00
{
2020-11-30 16:57:29 +00:00
if ( $check_stamp && ! self :: isValidTimeStamp ( $date ))
2020-05-30 21:39:43 +00:00
{
$date = strtotime ( $date );
}
return date ( 'n' , $date );
}
/**
* set the date year as 2004 ( for charts )
*/
2020-11-30 16:57:29 +00:00
public static function setYear ( $date , $check_stamp = true )
2020-05-30 21:39:43 +00:00
{
2020-11-30 16:57:29 +00:00
if ( $check_stamp && ! self :: isValidTimeStamp ( $date ))
2020-05-30 21:39:43 +00:00
{
$date = strtotime ( $date );
}
return date ( 'Y' , $date );
}
2019-04-04 11:52:38 +00:00
/**
* set the date as 2004 / 05 ( for charts )
*/
2020-11-30 16:57:29 +00:00
public static function setYearMonth ( $date , $spacer = '/' , $check_stamp = true )
2019-04-04 11:52:38 +00:00
{
2020-11-30 16:57:29 +00:00
if ( $check_stamp && ! self :: isValidTimeStamp ( $date ))
2019-04-04 11:52:38 +00:00
{
$date = strtotime ( $date );
}
2020-05-30 21:39:43 +00:00
return date ( 'Y' . $spacer . 'm' , $date );
2019-04-04 11:52:38 +00:00
}
/**
* set the date as 2004 / 05 / 03 ( for charts )
*/
2020-11-30 16:57:29 +00:00
public static function setYearMonthDay ( $date , $spacer = '/' , $check_stamp = true )
2019-04-04 11:52:38 +00:00
{
2020-11-30 16:57:29 +00:00
if ( $check_stamp && ! self :: isValidTimeStamp ( $date ))
2019-04-04 11:52:38 +00:00
{
$date = strtotime ( $date );
}
2020-05-30 21:39:43 +00:00
return date ( 'Y' . $spacer . 'm' . $spacer . 'd' , $date );
2019-04-04 11:52:38 +00:00
}
2020-11-30 16:57:29 +00:00
/**
* set the date as 03 / 05 / 2004
*/
public static function setDayMonthYear ( $date , $spacer = '/' , $check_stamp = true )
{
if ( $check_stamp && ! self :: isValidTimeStamp ( $date ))
{
$date = strtotime ( $date );
}
return date ( 'd' . $spacer . 'm' . $spacer . 'Y' , $date );
}
2016-12-05 07:40:19 +00:00
/**
2020-05-30 21:39:43 +00:00
* Check if string is a valid time stamp
2016-12-05 07:40:19 +00:00
*/
public static function isValidTimeStamp ( $timestamp )
{
return (( int ) $timestamp === $timestamp )
&& ( $timestamp <= PHP_INT_MAX )
&& ( $timestamp >= ~ PHP_INT_MAX );
}
2018-03-03 16:43:27 +00:00
2020-11-30 16:57:29 +00:00
/**
* Check if string is a valid date
* https :// www . php . net / manual / en / function . checkdate . php #113205
*/
public static function isValidateDate ( $date , $format = 'Y-m-d H:i:s' )
{
$d = DateTime :: createFromFormat ( $format , $date );
return $d && $d -> format ( $format ) == $date ;
}
2018-03-03 16:43:27 +00:00
/**
2024-02-10 09:13:31 +00:00
* Workers to load tasks
*
* @ var array
* @ since 3.1
*/
protected static array $worker = [];
2018-03-03 16:43:27 +00:00
/**
2024-02-10 09:13:31 +00:00
* Set a worker dynamic URLs
*
* @ var array
* @ since 3.1
*/
protected static array $workerURL = [];
2018-03-03 16:43:27 +00:00
/**
2024-02-10 09:13:31 +00:00
* Set a worker dynamic HEADERs
*
* @ var array
* @ since 3.1
*/
protected static array $workerHEADER = [];
2018-03-03 16:43:27 +00:00
/**
2024-02-10 09:13:31 +00:00
* Curl Error Notice
*
* @ var bool
* @ since 3.1
*/
protected static bool $curlErrorLoaded = false ;
2018-03-03 16:43:27 +00:00
2018-05-04 16:36:08 +00:00
/**
2024-02-10 09:13:31 +00:00
* check if a worker has more work
*
* @ param string $function The function to target to perform the task
*
* @ return bool
* @ since 3.1
*/
public static function hasWork ( string $function ) : bool
2018-05-04 16:36:08 +00:00
{
2024-02-10 09:13:31 +00:00
if ( isset ( self :: $worker [ $function ]) && UtilitiesArrayHelper :: check ( self :: $worker [ $function ]))
2018-05-04 16:36:08 +00:00
{
return count ( ( array ) self :: $worker [ $function ]);
}
return false ;
}
2018-03-03 16:43:27 +00:00
/**
2024-02-10 09:13:31 +00:00
* Set a worker url
*
* @ param string $function The function to target to perform the task
* @ param string $url The url of where the task is to be performed
*
* @ return void
* @ since 3.1
*/
public static function setWorkerUrl ( string $function , string $url ) : void
2018-03-03 16:43:27 +00:00
{
// set the URL if found
2024-02-10 09:13:31 +00:00
if ( UtilitiesStringHelper :: check ( $url ))
2018-03-03 16:43:27 +00:00
{
// make sure task function url is up
self :: $workerURL [ $function ] = $url ;
}
}
/**
2024-02-10 09:13:31 +00:00
* Set a worker headers
*
* @ param string $function The function to target to perform the task
* @ param array | null $headers The headers needed for these workers / function
*
* @ return void
* @ since 3.1
*/
public static function setWorkerHeaders ( string $function , ? array $headers ) : void
2018-03-03 16:43:27 +00:00
{
// set the Headers if found
2024-02-10 09:13:31 +00:00
if ( UtilitiesArrayHelper :: check ( $headers ))
2018-03-03 16:43:27 +00:00
{
// make sure task function headers are set
self :: $workerHEADER [ $function ] = $headers ;
}
}
/**
2024-02-10 09:13:31 +00:00
* Set a worker that needs to perform a task
*
* @ param mixed $data The data to pass to the task
* @ param string $function The function to target to perform the task
* @ param string $url The url of where the task is to be performed
* @ param array $headers The headers needed for these workers / function
*
* @ return void
* @ since 3.1
*/
public static function setWorker ( $data , string $function , ? string $url = null , ? array $headers = null )
2018-03-03 16:43:27 +00:00
{
// make sure task function is up
if ( ! isset ( self :: $worker [ $function ]))
{
2024-02-10 09:13:31 +00:00
self :: $worker [ $function ] = [];
2018-03-03 16:43:27 +00:00
}
2024-02-10 09:13:31 +00:00
2018-03-03 16:43:27 +00:00
// load the task
self :: $worker [ $function ][] = self :: lock ( $data );
2024-02-10 09:13:31 +00:00
2018-03-03 16:43:27 +00:00
// set the Headers if found
if ( $headers && ! isset ( self :: $workerHEADER [ $function ]))
{
self :: setWorkerHeaders ( $function , $headers );
}
2024-02-10 09:13:31 +00:00
2018-03-03 16:43:27 +00:00
// set the URL if found
if ( $url && ! isset ( self :: $workerURL [ $function ]))
{
self :: setWorkerUrl ( $function , $url );
}
}
/**
2024-02-10 09:13:31 +00:00
* Run set Workers
*
* @ param string $function The function to target to perform the task
* @ param string $perTask The amount of task per worker
* @ param function $callback The option to do a call back when task is completed
* @ param int $threadSize The size of the thread
*
* @ return bool true On success
* @ since 3.1
*/
public static function runWorker ( string $function , $perTask = 50 , $callback = null , $threadSize = 20 ) : bool
2018-03-03 16:43:27 +00:00
{
// set task
$task = self :: lock ( $function );
// build headers
$headers = array ( 'VDM-TASK: ' . $task );
// build dynamic headers
2024-02-10 09:13:31 +00:00
if ( isset ( self :: $workerHEADER [ $function ]) && UtilitiesArrayHelper :: check ( self :: $workerHEADER [ $function ]))
2018-03-03 16:43:27 +00:00
{
foreach ( self :: $workerHEADER [ $function ] as $header )
{
$headers [] = $header ;
}
}
// build worker options
$options = array ();
// make sure worker is up
2024-02-10 09:13:31 +00:00
if ( isset ( self :: $worker [ $function ]) && UtilitiesArrayHelper :: check ( self :: $worker [ $function ]))
2018-03-03 16:43:27 +00:00
{
// this load method is for each
if ( 1 == $perTask )
{
// working with a string = 1
$headers [] = 'VDM-VALUE-TYPE: ' . self :: lock ( 1 );
// now load the options
foreach ( self :: $worker [ $function ] as $data )
{
$options [] = array ( CURLOPT_HTTPHEADER => $headers , CURLOPT_POST => 1 , CURLOPT_POSTFIELDS => 'VDM_DATA=' . $data );
}
}
// this load method is for bundles
else
{
// working with an array = 2
$headers [] = 'VDM-VALUE-TYPE: ' . self :: lock ( 2 );
// now load the options
$work = array_chunk ( self :: $worker [ $function ], $perTask );
foreach ( $work as $data )
{
$options [] = array ( CURLOPT_HTTPHEADER => $headers , CURLOPT_POST => 1 , CURLOPT_POSTFIELDS => 'VDM_DATA=' . implode ( '___VDM___' , $data ));
}
}
// relieve worker of task/function
self :: $worker [ $function ] = array ();
}
// do the execution
2024-02-10 09:13:31 +00:00
if ( UtilitiesArrayHelper :: check ( $options ))
2018-03-03 16:43:27 +00:00
{
if ( isset ( self :: $workerURL [ $function ]))
{
$url = self :: $workerURL [ $function ];
}
else
{
2024-02-10 09:13:31 +00:00
$url = Uri :: root () . '/index.php?option=com_sermondistributor&task=api.worker' ;
2018-03-03 16:43:27 +00:00
}
return self :: curlMultiExec ( $url , $options , $callback , $threadSize );
}
return false ;
}
/**
2024-02-10 09:13:31 +00:00
* Do a multi curl execution of tasks
*
* @ param string $url The url of where the task is to be performed
* @ param array $_options The array of curl options / headers to set
* @ param function $callback The option to do a call back when task is completed
* @ param int $threadSize The size of the thread
*
* @ return bool true On success
* @ since 3.1
*/
2018-03-03 16:43:27 +00:00
public static function curlMultiExec ( & $url , & $_options , $callback = null , $threadSize = 20 )
{
// make sure we have curl available
if ( ! function_exists ( 'curl_version' ))
{
if ( ! self :: $curlErrorLoaded )
{
// set the notice
2024-02-10 09:13:31 +00:00
Factory :: getApplication () -> enqueueMessage ( Text :: _ ( 'COM_SERMONDISTRIBUTOR_HTWOCURL_NOT_FOUNDHTWOPPLEASE_SETUP_CURL_ON_YOUR_SYSTEM_OR_BSERMONDISTRIBUTORB_WILL_NOT_FUNCTION_CORRECTLYP' ), 'Error' );
2018-03-03 16:43:27 +00:00
// load the notice only once
self :: $curlErrorLoaded = true ;
}
return false ;
}
// make sure we have an url
2024-02-10 09:13:31 +00:00
if ( UtilitiesStringHelper :: check ( $url ))
2018-03-03 16:43:27 +00:00
{
// make sure the thread size isn't greater than the # of _options
$threadSize = ( count ( $_options ) < $threadSize ) ? count ( $_options ) : $threadSize ;
// set the options
$options = array ();
$options [ CURLOPT_URL ] = $url ;
$options [ CURLOPT_USERAGENT ] = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12' ;
$options [ CURLOPT_RETURNTRANSFER ] = TRUE ;
$options [ CURLOPT_SSL_VERIFYPEER ] = FALSE ;
// start multi threading :)
$handle = curl_multi_init ();
// start the first batch of requests
for ( $i = 0 ; $i < $threadSize ; $i ++ )
{
if ( isset ( $_options [ $i ]))
{
$ch = curl_init ();
foreach ( $_options [ $i ] as $curlopt => $string )
{
$options [ $curlopt ] = $string ;
}
curl_setopt_array ( $ch , $options );
curl_multi_add_handle ( $handle , $ch );
}
}
// we wait for all the calls to finish (should not take long)
do {
while (( $execrun = curl_multi_exec ( $handle , $working )) == CURLM_CALL_MULTI_PERFORM );
if ( $execrun != CURLM_OK )
break ;
// a request was just completed -- find out which one
while ( $done = curl_multi_info_read ( $handle ))
{
if ( is_callable ( $callback ))
{
// $info = curl_getinfo($done['handle']);
// request successful. process output using the callback function.
$output = curl_multi_getcontent ( $done [ 'handle' ]);
$callback ( $output );
}
$key = $i + 1 ;
if ( isset ( $_options [ $key ]))
{
// start a new request (it's important to do this before removing the old one)
$ch = curl_init (); $i ++ ;
// add options
foreach ( $_options [ $key ] as $curlopt => $string )
{
$options [ $curlopt ] = $string ;
}
curl_setopt_array ( $ch , $options );
curl_multi_add_handle ( $handle , $ch );
// remove options again
foreach ( $_options [ $key ] as $curlopt => $string )
{
unset ( $options [ $curlopt ]);
}
}
// remove the curl handle that just completed
curl_multi_remove_handle ( $handle , $done [ 'handle' ]);
}
// stop wasting CPU cycles and rest for a couple ms
usleep ( 10000 );
} while ( $working );
// close the curl multi thread
curl_multi_close ( $handle );
// okay done
return true ;
}
return false ;
}
/**
2024-02-10 09:13:31 +00:00
* the locker
*
* @ var array
* @ since 3.1
*/
protected static array $locker = [];
2018-03-03 16:43:27 +00:00
/**
2024-02-10 09:13:31 +00:00
* the dynamic replacement salt
*
* @ var array
* @ since 3.1
*/
protected static array $globalSalt = [];
2018-03-03 16:43:27 +00:00
/**
2024-02-10 09:13:31 +00:00
* the timer
*
* @ var object
* @ since 3.1
*/
2018-03-03 16:43:27 +00:00
protected static $keytimer ;
/**
2024-02-10 09:13:31 +00:00
* To Lock string
*
* @ param string $string The string / array to lock
* @ param string | null $key The custom key to use
* @ param int $salt The switch to add salt and type of salt
* @ param int | null $dynamic The dynamic replacement array of salt build string
* @ param int $urlencode The switch to control url encoding
*
* @ return string Encrypted String
* @ since 3.1
*/
public static function lock ( string $string , ? string $key = null , int $salt = 2 , ? int $dynamic = null , $urlencode = true ) : string
2018-03-03 16:43:27 +00:00
{
// get the global settings
2024-02-10 09:13:31 +00:00
if ( ! $key || ! UtilitiesStringHelper :: check ( $key ))
2018-03-03 16:43:27 +00:00
{
// set temp timer
$timer = 2 ;
// if we have a timer use it
if ( $salt > 0 )
{
$timer = $salt ;
}
2018-09-06 08:34:13 +00:00
// set the default key
$key = self :: salt ( $timer , $dynamic );
// try getting the system key
2018-03-03 16:43:27 +00:00
if ( method_exists ( get_called_class (), " getCryptKey " ))
{
2018-09-06 08:34:13 +00:00
// try getting the medium key first the fall back to basic, and then default
$key = self :: getCryptKey ( 'medium' , self :: getCryptKey ( 'basic' , $key ));
2018-03-03 16:43:27 +00:00
}
}
// check if we have a salt timer
if ( $salt > 0 )
{
$key .= self :: salt ( $salt , $dynamic );
}
// get the locker settings
2024-02-10 09:13:31 +00:00
if ( ! isset ( self :: $locker [ $key ]) || ! ObjectHelper :: check ( self :: $locker [ $key ]))
2018-03-03 16:43:27 +00:00
{
2024-02-10 09:13:31 +00:00
self :: $locker [ $key ] = new AES ( $key , 128 );
2018-03-03 16:43:27 +00:00
}
2018-05-04 16:36:08 +00:00
// convert array or object to string
2024-02-10 09:13:31 +00:00
if ( UtilitiesArrayHelper :: check ( $string ) || ObjectHelper :: check ( $string ))
2018-03-03 16:43:27 +00:00
{
$string = serialize ( $string );
}
// prep for url
2018-09-06 08:34:13 +00:00
if ( $urlencode && method_exists ( get_called_class (), " base64_urlencode " ))
2018-03-03 16:43:27 +00:00
{
return self :: base64_urlencode ( self :: $locker [ $key ] -> encryptString ( $string ));
}
return self :: $locker [ $key ] -> encryptString ( $string );
}
/**
2024-02-10 09:13:31 +00:00
* To un - Lock string
*
* @ param string $string The string to unlock
* @ param string $key The custom key to use
* @ param int $salt The switch to add salt and type of salt
* @ param int $dynamic The dynamic replacement array of salt build string
* @ param int $urlencode The switch to control url decoding
*
* @ return string Decrypted String
* @ since 3.1
*/
public static function unlock ( $string , $key = null , $salt = 2 , $dynamic = null , $urlencode = true ) : string
2018-03-03 16:43:27 +00:00
{
// get the global settings
2024-02-10 09:13:31 +00:00
if ( ! $key || ! UtilitiesStringHelper :: check ( $key ))
2018-03-03 16:43:27 +00:00
{
// set temp timer
$timer = 2 ;
// if we have a timer use it
if ( $salt > 0 )
{
$timer = $salt ;
}
2018-09-06 08:34:13 +00:00
// set the default key
$key = self :: salt ( $timer , $dynamic );
// try getting the system key
2018-03-03 16:43:27 +00:00
if ( method_exists ( get_called_class (), " getCryptKey " ))
{
2018-09-06 08:34:13 +00:00
// try getting the medium key first the fall back to basic, and then default
$key = self :: getCryptKey ( 'medium' , self :: getCryptKey ( 'basic' , $key ));
2018-03-03 16:43:27 +00:00
}
}
// check if we have a salt timer
if ( $salt > 0 )
{
$key .= self :: salt ( $salt , $dynamic );
}
// get the locker settings
2024-02-10 09:13:31 +00:00
if ( ! isset ( self :: $locker [ $key ]) || ! ObjectHelper :: check ( self :: $locker [ $key ]))
2018-03-03 16:43:27 +00:00
{
2024-02-10 09:13:31 +00:00
self :: $locker [ $key ] = new AES ( $key , 128 );
2018-03-03 16:43:27 +00:00
}
// make sure we have real base64
2018-09-06 08:34:13 +00:00
if ( $urlencode && method_exists ( get_called_class (), " base64_urldecode " ))
2018-03-03 16:43:27 +00:00
{
$string = self :: base64_urldecode ( $string );
}
// basic decrypt string.
if ( ! empty ( $string ) && ! is_numeric ( $string ) && $string === base64_encode ( base64_decode ( $string , true )))
{
$string = rtrim ( self :: $locker [ $key ] -> decryptString ( $string ), " \0 " );
// convert serial string to array
if ( self :: is_serial ( $string ))
{
$string = unserialize ( $string );
}
}
2024-02-10 09:13:31 +00:00
2018-03-03 16:43:27 +00:00
return $string ;
}
/**
2024-02-10 09:13:31 +00:00
* The Salt
*
* @ param int $type The type of length the salt should be valid
* @ param int $dynamic The dynamic replacement array of salt build string
*
* @ return string
* @ since 3.1
*/
public static function salt ( int $type = 1 , $dynamic = null ) : string
2018-03-03 16:43:27 +00:00
{
// get dynamic replacement salt
$dynamic = self :: getDynamicSalt ( $dynamic );
// get the key timer
2024-02-10 09:13:31 +00:00
if ( ! ObjectHelper :: check ( self :: $keytimer ))
2018-03-03 16:43:27 +00:00
{
// load the date time object
self :: $keytimer = new DateTime ;
// set the correct time stamp
$vdmLocalTime = new DateTimeZone ( 'Africa/Windhoek' );
self :: $keytimer -> setTimezone ( $vdmLocalTime );
}
// set type
if ( $type == 2 )
{
// hour
$format = 'Y-m-d \o\n ' . self :: periodFix ( self :: $keytimer -> format ( 'H' ));
}
elseif ( $type == 3 )
{
// day
$format = 'Y-m-' . self :: periodFix ( self :: $keytimer -> format ( 'd' ));
}
elseif ( $type == 4 )
{
// month
$format = 'Y-' . self :: periodFix ( self :: $keytimer -> format ( 'm' ));
}
else
{
// minute
$format = 'Y-m-d \o\n H:' . self :: periodFix ( self :: $keytimer -> format ( 'i' ));
}
// get key
2024-02-10 09:13:31 +00:00
if ( UtilitiesArrayHelper :: check ( $dynamic ))
2018-03-03 16:43:27 +00:00
{
return md5 ( str_replace ( array_keys ( $dynamic ), array_values ( $dynamic ), self :: $keytimer -> format ( $format ) . ' @ VDM.I0' ));
}
return md5 ( self :: $keytimer -> format ( $format ) . ' @ VDM.I0' );
}
/**
2024-02-10 09:13:31 +00:00
* The function to insure the salt is valid within the given period ( third try )
*
* @ param int $main The main number
* @ since 3.1
*/
protected static function periodFix ( int $main ) : int
2018-03-03 16:43:27 +00:00
{
return round ( $main / 3 ) * 3 ;
}
/**
2024-02-10 09:13:31 +00:00
* Check if a string is serialized
*
* @ param string $string
*
* @ return Boolean
* @ since 3.1
*/
public static function is_serial ( string $string ) : bool
2018-03-03 16:43:27 +00:00
{
return ( @ unserialize ( $string ) !== false );
}
/**
2024-02-10 09:13:31 +00:00
* Get dynamic replacement salt
* @ since 3.1
*/
2018-03-03 16:43:27 +00:00
public static function getDynamicSalt ( $dynamic = null )
{
// load global if not manually set
2024-02-10 09:13:31 +00:00
if ( ! UtilitiesArrayHelper :: check ( $dynamic ))
2018-03-03 16:43:27 +00:00
{
return self :: getGlobalSalt ();
}
// return manual values if set
else
{
return $dynamic ;
}
}
/**
2024-02-10 09:13:31 +00:00
* The random or dynamic secret salt
* @ since 3.1
*/
2018-03-03 16:43:27 +00:00
public static function getSecretSalt ( $string = null , $size = 9 )
{
// set the string
if ( ! $string )
{
// get random string
$string = self :: randomkey ( $size );
}
// convert string to array
2024-02-10 09:13:31 +00:00
$string = UtilitiesStringHelper :: safe ( $string );
2018-03-03 16:43:27 +00:00
// convert string to array
$array = str_split ( $string );
// insure only unique values are used
$array = array_unique ( $array );
// set the size
$size = ( $size <= count ( $array )) ? $size : count ( $array );
// down size the
return array_slice ( $array , 0 , $size );
}
/**
2024-02-10 09:13:31 +00:00
* Get global replacement salt
* @ since 3.1
*/
2018-03-03 16:43:27 +00:00
public static function getGlobalSalt ()
{
// load from memory if found
2024-02-10 09:13:31 +00:00
if ( ! UtilitiesArrayHelper :: check ( self :: $globalSalt ))
2018-03-03 16:43:27 +00:00
{
// get the global settings
2024-02-10 09:13:31 +00:00
if ( ! ObjectHelper :: check ( self :: $params ))
2018-03-03 16:43:27 +00:00
{
2024-02-10 09:13:31 +00:00
self :: $params = ComponentHelper :: getParams ( 'com_sermondistributor' );
2018-03-03 16:43:27 +00:00
}
// check if we have a global dynamic replacement array available (format --> ' 1->!,3->E,4->A')
$tmp = self :: $params -> get ( 'dynamic_salt' , null );
2024-02-10 09:13:31 +00:00
if ( UtilitiesStringHelper :: check ( $tmp ) && strpos ( $tmp , ',' ) !== false && strpos ( $tmp , '->' ) !== false )
2018-03-03 16:43:27 +00:00
{
$salt = array_map ( 'trim' , ( array ) explode ( ',' , $tmp ));
2024-02-10 09:13:31 +00:00
if ( UtilitiesArrayHelper :: check ( $salt ))
2018-03-03 16:43:27 +00:00
{
foreach ( $salt as $replace )
{
$dynamic = array_map ( 'trim' , ( array ) explode ( '->' , $replace ));
if ( isset ( $dynamic [ 0 ]) && isset ( $dynamic [ 1 ]))
{
self :: $globalSalt [ $dynamic [ 0 ]] = $dynamic [ 1 ];
}
}
}
}
}
// return global if found
2024-02-10 09:13:31 +00:00
if ( UtilitiesArrayHelper :: check ( self :: $globalSalt ))
2018-03-03 16:43:27 +00:00
{
return self :: $globalSalt ;
}
// return default as fail safe
return array ( '1' => '!' , '3' => 'E' , '4' => 'A' );
}
/**
2024-02-10 09:13:31 +00:00
* Close public protocol
* @ since 3.1
*/
2018-03-03 16:43:27 +00:00
public static function closePublicProtocol ( $id , $public )
{
// get secret salt
$secretSalt = self :: getSecretSalt ( self :: salt ( 1 , array ( '4' => 'R' , '1' => 'E' , '2' => 'G' , '7' => 'J' , '8' => 'A' )));
// get the key
$key = self :: salt ( 1 , $secretSalt );
// get secret salt
$secret = self :: getSecretSalt ();
// set the secret
$close [ 'SECRET' ] = self :: lock ( $secret , $key , 1 , array ( '1' => 's' , '3' => 'R' , '4' => 'D' ));
// get the key
$key = self :: salt ( 1 , $secret );
// get the public key
$close [ 'PUBLIC' ] = self :: lock ( $public , $key , 1 , array ( '1' => '!' , '3' => 'E' , '4' => 'A' ));
// get secret salt
$secretSalt = self :: getSecretSalt ( $public );
// get the key
$key = self :: salt ( 1 , $secretSalt );
// get the ID
$close [ 'ID' ] = self :: unlock ( $id , $key , 1 , array ( '1' => 'i' , '3' => 'e' , '4' => 'B' ));
// return closed values
return $close ;
}
/**
2024-02-10 09:13:31 +00:00
* Open public protocol
* @ since 3.1
*/
2018-03-03 16:43:27 +00:00
public static function openPublicProtocol ( $SECRET , $ID , $PUBLIC )
{
// get secret salt
$secretSalt = self :: getSecretSalt ( self :: salt ( 1 , array ( '4' => 'R' , '1' => 'E' , '2' => 'G' , '7' => 'J' , '8' => 'A' )));
// get the key
$key = self :: salt ( 1 , $secretSalt );
// get the $SECRET
$SECRET = self :: unlock ( $SECRET , $key , 1 , array ( '1' => 's' , '3' => 'R' , '4' => 'D' ));
// get the key
$key = self :: salt ( 1 , $SECRET );
// get the public key
$open [ 'public' ] = self :: unlock ( $PUBLIC , $key , 1 , array ( '1' => '!' , '3' => 'E' , '4' => 'A' ));
// get secret salt
$secretSalt = self :: getSecretSalt ( $open [ 'public' ]);
// get the key
$key = self :: salt ( 1 , $secretSalt );
// get the ID
$open [ 'id' ] = self :: unlock ( $ID , $key , 1 , array ( '1' => 'i' , '3' => 'e' , '4' => 'B' ));
// return opened values
return $open ;
2021-08-16 17:11:22 +00:00
}
/**
* Load the Composer Vendors
*/
public static function composerAutoload ( $target )
{
// insure we load the composer vendor only once
if ( ! isset ( self :: $composer [ $target ]))
{
// get the function name
2024-02-10 09:13:31 +00:00
$functionName = UtilitiesStringHelper :: safe ( 'compose' . $target );
2021-08-16 17:11:22 +00:00
// check if method exist
if ( method_exists ( __CLASS__ , $functionName ))
{
return self :: { $functionName }();
}
return false ;
}
return self :: $composer [ $target ];
}
/**
* Load the Component xml manifest .
*/
public static function manifest ()
{
$manifestUrl = JPATH_ADMINISTRATOR . " /components/com_sermondistributor/sermondistributor.xml " ;
return simplexml_load_file ( $manifestUrl );
}
/**
* Joomla version object
2024-02-10 09:13:31 +00:00
*/
2021-08-16 17:11:22 +00:00
protected static $JVersion ;
/**
* set / get Joomla version
*/
public static function jVersion ()
{
// check if set
2024-02-10 09:13:31 +00:00
if ( ! ObjectHelper :: check ( self :: $JVersion ))
2021-08-16 17:11:22 +00:00
{
2024-02-10 09:13:31 +00:00
self :: $JVersion = new Version ();
2021-08-16 17:11:22 +00:00
}
return self :: $JVersion ;
}
/**
* Load the Contributors details .
*/
public static function getContributors ()
{
// get params
2024-02-10 09:13:31 +00:00
$params = ComponentHelper :: getParams ( 'com_sermondistributor' );
2021-08-16 17:11:22 +00:00
// start contributors array
2024-02-10 09:13:31 +00:00
$contributors = [];
2021-08-16 17:11:22 +00:00
// get all Contributors (max 20)
$searchArray = range ( '0' , '20' );
foreach ( $searchArray as $nr )
2024-02-10 09:13:31 +00:00
{
2021-08-16 17:11:22 +00:00
if (( NULL !== $params -> get ( " showContributor " . $nr )) && ( $params -> get ( " showContributor " . $nr ) == 1 || $params -> get ( " showContributor " . $nr ) == 3 ))
{
// set link based of selected option
if ( $params -> get ( " useContributor " . $nr ) == 1 )
2024-02-10 09:13:31 +00:00
{
2021-08-16 17:11:22 +00:00
$link_front = '<a href="mailto:' . $params -> get ( " emailContributor " . $nr ) . '" target="_blank">' ;
$link_back = '</a>' ;
}
elseif ( $params -> get ( " useContributor " . $nr ) == 2 )
{
$link_front = '<a href="' . $params -> get ( " linkContributor " . $nr ) . '" target="_blank">' ;
$link_back = '</a>' ;
}
else
{
$link_front = '' ;
$link_back = '' ;
}
2024-02-10 09:13:31 +00:00
$contributors [ $nr ][ 'title' ] = UtilitiesStringHelper :: html ( $params -> get ( " titleContributor " . $nr ));
$contributors [ $nr ][ 'name' ] = $link_front . UtilitiesStringHelper :: html ( $params -> get ( " nameContributor " . $nr )) . $link_back ;
2021-08-16 17:11:22 +00:00
}
}
return $contributors ;
2015-11-30 21:30:54 +00:00
}
/**
2018-07-20 04:39:01 +00:00
* Load the Component Help URLs .
**/
2015-11-30 21:30:54 +00:00
public static function getHelpUrl ( $view )
{
2024-02-10 09:13:31 +00:00
$user = Factory :: getUser ();
2015-11-30 21:30:54 +00:00
$groups = $user -> get ( 'groups' );
2024-02-10 09:13:31 +00:00
$db = Factory :: getDbo ();
2015-11-30 21:30:54 +00:00
$query = $db -> getQuery ( true );
$query -> select ( array ( 'a.id' , 'a.groups' , 'a.target' , 'a.type' , 'a.article' , 'a.url' ));
$query -> from ( '#__sermondistributor_help_document AS a' );
$query -> where ( 'a.admin_view = ' . $db -> quote ( $view ));
$query -> where ( 'a.location = 1' );
$query -> where ( 'a.published = 1' );
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
{
$helps = $db -> loadObjectList ();
2024-02-10 09:13:31 +00:00
if ( UtilitiesArrayHelper :: check ( $helps ))
2015-11-30 21:30:54 +00:00
{
foreach ( $helps as $nr => $help )
{
if ( $help -> target == 1 )
{
$targetgroups = json_decode ( $help -> groups , true );
if ( ! array_intersect ( $targetgroups , $groups ))
{
2016-07-16 12:19:44 +00:00
// if user not in those target groups then remove the item
2015-11-30 21:30:54 +00:00
unset ( $helps [ $nr ]);
continue ;
}
}
2016-07-16 12:19:44 +00:00
// set the return type
2015-11-30 21:30:54 +00:00
switch ( $help -> type )
{
2016-07-16 12:19:44 +00:00
// set joomla article
2015-11-30 21:30:54 +00:00
case 1 :
return self :: loadArticleLink ( $help -> article );
2018-07-20 04:39:01 +00:00
break ;
2016-07-16 12:19:44 +00:00
// set help text
2015-11-30 21:30:54 +00:00
case 2 :
return self :: loadHelpTextLink ( $help -> id );
2018-07-20 04:39:01 +00:00
break ;
2016-07-16 12:19:44 +00:00
// set Link
2015-11-30 21:30:54 +00:00
case 3 :
return $help -> url ;
2018-07-20 04:39:01 +00:00
break ;
2015-11-30 21:30:54 +00:00
}
}
}
}
return false ;
}
/**
2018-07-20 04:39:01 +00:00
* Get the Article Link .
**/
2015-11-30 21:30:54 +00:00
protected static function loadArticleLink ( $id )
{
2024-02-10 09:13:31 +00:00
return Uri :: root () . 'index.php?option=com_content&view=article&id=' . $id . '&tmpl=component&layout=modal' ;
2015-11-30 21:30:54 +00:00
}
/**
2018-07-20 04:39:01 +00:00
* Get the Help Text Link .
**/
2015-11-30 21:30:54 +00:00
protected static function loadHelpTextLink ( $id )
{
2024-02-10 09:13:31 +00:00
$token = Session :: getFormToken ();
return 'index.php?option=com_sermondistributor&task=help.getText&id=' . ( int ) $id . '&' . $token . '=1' ;
2021-08-16 17:11:22 +00:00
}
/**
* Configure the Linkbar .
*/
public static function addSubmenu ( $submenu )
{
// load user for access menus
2024-02-10 09:13:31 +00:00
$user = Factory :: getUser ();
2021-08-16 17:11:22 +00:00
// load the submenus to sidebar
2024-02-10 09:13:31 +00:00
JHtmlSidebar :: addEntry ( Text :: _ ( 'COM_SERMONDISTRIBUTOR_SUBMENU_DASHBOARD' ), 'index.php?option=com_sermondistributor&view=sermondistributor' , $submenu === 'sermondistributor' );
2015-11-30 21:30:54 +00:00
if ( $user -> authorise ( 'preacher.access' , 'com_sermondistributor' ) && $user -> authorise ( 'preacher.submenu' , 'com_sermondistributor' ))
{
2024-02-10 09:13:31 +00:00
JHtmlSidebar :: addEntry ( Text :: _ ( 'COM_SERMONDISTRIBUTOR_SUBMENU_PREACHERS' ), 'index.php?option=com_sermondistributor&view=preachers' , $submenu === 'preachers' );
2015-11-30 21:30:54 +00:00
}
if ( $user -> authorise ( 'sermon.access' , 'com_sermondistributor' ) && $user -> authorise ( 'sermon.submenu' , 'com_sermondistributor' ))
{
2024-02-10 09:13:31 +00:00
JHtmlSidebar :: addEntry ( Text :: _ ( 'COM_SERMONDISTRIBUTOR_SUBMENU_SERMONS' ), 'index.php?option=com_sermondistributor&view=sermons' , $submenu === 'sermons' );
JHtmlSidebar :: addEntry ( Text :: _ ( 'COM_SERMONDISTRIBUTOR_SERMON_SERMONS_CATEGORIES' ), 'index.php?option=com_categories&view=categories&extension=com_sermondistributor.sermon' , $submenu === 'categories.sermon' );
2015-11-30 21:30:54 +00:00
}
if ( $user -> authorise ( 'series.access' , 'com_sermondistributor' ) && $user -> authorise ( 'series.submenu' , 'com_sermondistributor' ))
{
2024-02-10 09:13:31 +00:00
JHtmlSidebar :: addEntry ( Text :: _ ( 'COM_SERMONDISTRIBUTOR_SUBMENU_SERIES_LIST' ), 'index.php?option=com_sermondistributor&view=series_list' , $submenu === 'series_list' );
2015-11-30 21:30:54 +00:00
}
if ( $user -> authorise ( 'statistic.access' , 'com_sermondistributor' ) && $user -> authorise ( 'statistic.submenu' , 'com_sermondistributor' ))
{
2024-02-10 09:13:31 +00:00
JHtmlSidebar :: addEntry ( Text :: _ ( 'COM_SERMONDISTRIBUTOR_SUBMENU_STATISTICS' ), 'index.php?option=com_sermondistributor&view=statistics' , $submenu === 'statistics' );
2015-11-30 21:30:54 +00:00
}
2016-11-27 04:20:48 +00:00
if ( $user -> authorise ( 'external_source.access' , 'com_sermondistributor' ) && $user -> authorise ( 'external_source.submenu' , 'com_sermondistributor' ))
{
2024-02-10 09:13:31 +00:00
JHtmlSidebar :: addEntry ( Text :: _ ( 'COM_SERMONDISTRIBUTOR_SUBMENU_EXTERNAL_SOURCES' ), 'index.php?option=com_sermondistributor&view=external_sources' , $submenu === 'external_sources' );
2016-11-27 04:20:48 +00:00
}
// Access control (manual_updater.access && manual_updater.submenu).
if ( $user -> authorise ( 'manual_updater.access' , 'com_sermondistributor' ) && $user -> authorise ( 'manual_updater.submenu' , 'com_sermondistributor' ))
{
2024-02-10 09:13:31 +00:00
JHtmlSidebar :: addEntry ( Text :: _ ( 'COM_SERMONDISTRIBUTOR_SUBMENU_MANUAL_UPDATER' ), 'index.php?option=com_sermondistributor&view=manual_updater' , $submenu === 'manual_updater' );
2016-11-27 04:20:48 +00:00
}
if ( $user -> authorise ( 'local_listing.access' , 'com_sermondistributor' ) && $user -> authorise ( 'local_listing.submenu' , 'com_sermondistributor' ))
{
2024-02-10 09:13:31 +00:00
JHtmlSidebar :: addEntry ( Text :: _ ( 'COM_SERMONDISTRIBUTOR_SUBMENU_LOCAL_LISTINGS' ), 'index.php?option=com_sermondistributor&view=local_listings' , $submenu === 'local_listings' );
2016-11-27 04:20:48 +00:00
}
2015-11-30 21:30:54 +00:00
if ( $user -> authorise ( 'help_document.access' , 'com_sermondistributor' ) && $user -> authorise ( 'help_document.submenu' , 'com_sermondistributor' ))
{
2024-02-10 09:13:31 +00:00
JHtmlSidebar :: addEntry ( Text :: _ ( 'COM_SERMONDISTRIBUTOR_SUBMENU_HELP_DOCUMENTS' ), 'index.php?option=com_sermondistributor&view=help_documents' , $submenu === 'help_documents' );
2021-08-16 17:11:22 +00:00
}
2019-04-04 11:52:38 +00:00
}
2015-11-30 21:30:54 +00:00
/**
2018-07-20 04:39:01 +00:00
* UIKIT Component Classes
**/
2015-11-30 21:30:54 +00:00
public static $uk_components = array (
'data-uk-grid' => array (
'grid' ),
'uk-accordion' => array (
'accordion' ),
'uk-autocomplete' => array (
'autocomplete' ),
'data-uk-datepicker' => array (
'datepicker' ),
'uk-form-password' => array (
'form-password' ),
'uk-form-select' => array (
'form-select' ),
'data-uk-htmleditor' => array (
'htmleditor' ),
'data-uk-lightbox' => array (
'lightbox' ),
'uk-nestable' => array (
'nestable' ),
'UIkit.notify' => array (
'notify' ),
'data-uk-parallax' => array (
'parallax' ),
'uk-search' => array (
'search' ),
'uk-slider' => array (
'slider' ),
'uk-slideset' => array (
'slideset' ),
'uk-slideshow' => array (
'slideshow' ,
'slideshow-fx' ),
'uk-sortable' => array (
'sortable' ),
'data-uk-sticky' => array (
'sticky' ),
'data-uk-timepicker' => array (
'timepicker' ),
'data-uk-tooltip' => array (
'tooltip' ),
2015-12-23 12:44:56 +00:00
'uk-placeholder' => array (
'placeholder' ),
'uk-dotnav' => array (
'dotnav' ),
'uk-slidenav' => array (
'slidenav' ),
'uk-form' => array (
'form-advanced' ),
'uk-progress' => array (
'progress' ),
2015-11-30 21:30:54 +00:00
'upload-drop' => array (
2015-12-23 12:44:56 +00:00
'upload' , 'form-file' )
2015-11-30 21:30:54 +00:00
);
2018-07-20 04:39:01 +00:00
2015-11-30 21:30:54 +00:00
/**
2018-07-20 04:39:01 +00:00
* Add UIKIT Components
**/
2015-11-30 21:30:54 +00:00
public static $uikit = false ;
/**
2018-07-20 04:39:01 +00:00
* Get UIKIT Components
**/
2015-11-30 21:30:54 +00:00
public static function getUikitComp ( $content , $classes = array ())
{
if ( strpos ( $content , 'class="uk-' ) !== false )
{
2016-07-16 12:19:44 +00:00
// reset
2024-02-10 09:13:31 +00:00
$temp = [];
2015-11-30 21:30:54 +00:00
foreach ( self :: $uk_components as $looking => $add )
{
if ( strpos ( $content , $looking ) !== false )
{
$temp [] = $looking ;
}
}
2016-07-16 12:19:44 +00:00
// make sure uikit is loaded to config
2015-11-30 21:30:54 +00:00
if ( strpos ( $content , 'class="uk-' ) !== false )
{
self :: $uikit = true ;
}
2016-07-16 12:19:44 +00:00
// sorter
2024-02-10 09:13:31 +00:00
if ( UtilitiesArrayHelper :: check ( $temp ))
2015-11-30 21:30:54 +00:00
{
2016-07-16 12:19:44 +00:00
// merger
2024-02-10 09:13:31 +00:00
if ( UtilitiesArrayHelper :: check ( $classes ))
2015-11-30 21:30:54 +00:00
{
$newTemp = array_merge ( $temp , $classes );
$temp = array_unique ( $newTemp );
}
return $temp ;
}
2018-07-20 04:39:01 +00:00
}
2024-02-10 09:13:31 +00:00
if ( UtilitiesArrayHelper :: check ( $classes ))
2015-11-30 21:30:54 +00:00
{
return $classes ;
}
return false ;
2019-04-04 11:52:38 +00:00
}
2015-11-30 21:30:54 +00:00
/**
2020-05-30 21:39:43 +00:00
* Prepares the xml document
*/
2021-08-16 17:11:22 +00:00
public static function xls ( $rows , $fileName = null , $title = null , $subjectTab = null , $creator = 'Vast Development Method' , $description = null , $category = null , $keywords = null , $modified = null )
2015-11-30 21:30:54 +00:00
{
2016-07-16 12:19:44 +00:00
// set the user
2024-02-10 09:13:31 +00:00
$user = Factory :: getUser ();
2020-05-30 21:39:43 +00:00
// set fileName if not set
2015-11-30 21:30:54 +00:00
if ( ! $fileName )
{
2024-02-10 09:13:31 +00:00
$fileName = 'exported_' . Factory :: getDate () -> format ( 'jS_F_Y' );
2015-11-30 21:30:54 +00:00
}
2020-05-30 21:39:43 +00:00
// set modified if not set
2015-11-30 21:30:54 +00:00
if ( ! $modified )
{
$modified = $user -> name ;
}
2016-07-16 12:19:44 +00:00
// set title if not set
2015-11-30 21:30:54 +00:00
if ( ! $title )
{
$title = 'Book1' ;
}
2016-07-16 12:19:44 +00:00
// set tab name if not set
2015-11-30 21:30:54 +00:00
if ( ! $subjectTab )
{
$subjectTab = 'Sheet1' ;
}
2018-07-20 04:39:01 +00:00
2020-05-30 21:39:43 +00:00
// make sure we have the composer classes loaded
self :: composerAutoload ( 'phpspreadsheet' );
2018-07-20 04:39:01 +00:00
2020-05-30 21:39:43 +00:00
// Create new Spreadsheet object
$spreadsheet = new Spreadsheet ();
2018-07-20 04:39:01 +00:00
2016-07-16 12:19:44 +00:00
// Set document properties
2020-05-30 21:39:43 +00:00
$spreadsheet -> getProperties ()
-> setCreator ( $creator )
2021-08-16 17:11:22 +00:00
-> setCompany ( 'Vast Development Method' )
2018-07-20 04:39:01 +00:00
-> setLastModifiedBy ( $modified )
-> setTitle ( $title )
-> setSubject ( $subjectTab );
2020-11-30 16:57:29 +00:00
// The file type
$file_type = 'Xls' ;
2020-05-30 21:39:43 +00:00
// set description
if ( $description )
2015-11-30 21:30:54 +00:00
{
2020-05-30 21:39:43 +00:00
$spreadsheet -> getProperties () -> setDescription ( $description );
2015-11-30 21:30:54 +00:00
}
2020-05-30 21:39:43 +00:00
// set keywords
if ( $keywords )
2015-11-30 21:30:54 +00:00
{
2020-05-30 21:39:43 +00:00
$spreadsheet -> getProperties () -> setKeywords ( $keywords );
2015-11-30 21:30:54 +00:00
}
2020-05-30 21:39:43 +00:00
// set category
if ( $category )
2015-11-30 21:30:54 +00:00
{
2020-05-30 21:39:43 +00:00
$spreadsheet -> getProperties () -> setCategory ( $category );
2015-11-30 21:30:54 +00:00
}
2018-07-20 04:39:01 +00:00
2016-07-16 12:19:44 +00:00
// Some styles
2015-11-30 21:30:54 +00:00
$headerStyles = array (
'font' => array (
'bold' => true ,
'color' => array ( 'rgb' => '1171A3' ),
'size' => 12 ,
'name' => 'Verdana'
));
$sideStyles = array (
'font' => array (
'bold' => true ,
'color' => array ( 'rgb' => '444444' ),
'size' => 11 ,
'name' => 'Verdana'
));
$normalStyles = array (
'font' => array (
'color' => array ( 'rgb' => '444444' ),
'size' => 11 ,
'name' => 'Verdana'
));
2018-07-20 04:39:01 +00:00
2016-07-16 12:19:44 +00:00
// Add some data
2024-02-10 09:13:31 +00:00
if (( $size = UtilitiesArrayHelper :: check ( $rows )) !== false )
2015-11-30 21:30:54 +00:00
{
$i = 1 ;
2020-11-30 16:57:29 +00:00
// Based on data size we adapt the behaviour.
$xls_mode = 1 ;
if ( $size > 3000 )
{
$xls_mode = 3 ;
$file_type = 'Csv' ;
}
elseif ( $size > 2000 )
{
$xls_mode = 2 ;
}
// Set active sheet and get it.
$active_sheet = $spreadsheet -> setActiveSheetIndex ( 0 );
foreach ( $rows as $array )
{
2015-11-30 21:30:54 +00:00
$a = 'A' ;
2020-11-30 16:57:29 +00:00
foreach ( $array as $value )
{
$active_sheet -> setCellValue ( $a . $i , $value );
if ( $xls_mode != 3 )
{
if ( $i == 1 )
{
$active_sheet -> getColumnDimension ( $a ) -> setAutoSize ( true );
$active_sheet -> getStyle ( $a . $i ) -> applyFromArray ( $headerStyles );
$active_sheet -> getStyle ( $a . $i ) -> getAlignment () -> setHorizontal ( PhpOffice\PhpSpreadsheet\Style\Alignment :: HORIZONTAL_CENTER );
}
elseif ( $a === 'A' )
{
$active_sheet -> getStyle ( $a . $i ) -> applyFromArray ( $sideStyles );
}
elseif ( $xls_mode == 1 )
{
$active_sheet -> getStyle ( $a . $i ) -> applyFromArray ( $normalStyles );
}
2015-11-30 21:30:54 +00:00
}
$a ++ ;
}
$i ++ ;
}
}
else
{
return false ;
}
2018-07-20 04:39:01 +00:00
2016-07-16 12:19:44 +00:00
// Rename worksheet
2020-05-30 21:39:43 +00:00
$spreadsheet -> getActiveSheet () -> setTitle ( $subjectTab );
2018-07-20 04:39:01 +00:00
2016-07-16 12:19:44 +00:00
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
2020-05-30 21:39:43 +00:00
$spreadsheet -> setActiveSheetIndex ( 0 );
2018-07-20 04:39:01 +00:00
2016-07-16 12:19:44 +00:00
// Redirect output to a client's web browser (Excel5)
2015-11-30 21:30:54 +00:00
header ( 'Content-Type: application/vnd.ms-excel' );
2020-11-30 16:57:29 +00:00
header ( 'Content-Disposition: attachment;filename="' . $fileName . '.' . strtolower ( $file_type ) . '"' );
2015-11-30 21:30:54 +00:00
header ( 'Cache-Control: max-age=0' );
2016-07-16 12:19:44 +00:00
// If you're serving to IE 9, then the following may be needed
2015-11-30 21:30:54 +00:00
header ( 'Cache-Control: max-age=1' );
2018-07-20 04:39:01 +00:00
2016-07-16 12:19:44 +00:00
// If you're serving to IE over SSL, then the following may be needed
2015-11-30 21:30:54 +00:00
header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); // Date in the past
header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' ); // always modified
header ( 'Cache-Control: cache, must-revalidate' ); // HTTP/1.1
header ( 'Pragma: public' ); // HTTP/1.0
2018-07-20 04:39:01 +00:00
2020-11-30 16:57:29 +00:00
$writer = IOFactory :: createWriter ( $spreadsheet , $file_type );
2020-05-30 21:39:43 +00:00
$writer -> save ( 'php://output' );
2015-11-30 21:30:54 +00:00
jexit ();
}
2018-07-20 04:39:01 +00:00
2015-11-30 21:30:54 +00:00
/**
2020-05-30 21:39:43 +00:00
* Get CSV Headers
*/
2015-11-30 21:30:54 +00:00
public static function getFileHeaders ( $dataType )
2018-07-20 04:39:01 +00:00
{
2020-05-30 21:39:43 +00:00
// make sure we have the composer classes loaded
self :: composerAutoload ( 'phpspreadsheet' );
2016-07-16 12:19:44 +00:00
// get session object
2024-02-10 09:13:31 +00:00
$session = Factory :: getSession ();
2018-07-20 04:39:01 +00:00
$package = $session -> get ( 'package' , null );
$package = json_decode ( $package , true );
2016-07-16 12:19:44 +00:00
// set the headers
2015-11-30 21:30:54 +00:00
if ( isset ( $package [ 'dir' ]))
{
2016-07-16 12:19:44 +00:00
// only load first three rows
2020-05-30 21:39:43 +00:00
$chunkFilter = new PhpOffice\PhpSpreadsheet\Reader\chunkReadFilter ( 2 , 1 );
2016-07-16 12:19:44 +00:00
// identify the file type
2020-05-30 21:39:43 +00:00
$inputFileType = IOFactory :: identify ( $package [ 'dir' ]);
2016-07-16 12:19:44 +00:00
// create the reader for this file type
2020-05-30 21:39:43 +00:00
$excelReader = IOFactory :: createReader ( $inputFileType );
2016-07-16 12:19:44 +00:00
// load the limiting filter
$excelReader -> setReadFilter ( $chunkFilter );
2015-11-30 21:30:54 +00:00
$excelReader -> setReadDataOnly ( true );
2016-07-16 12:19:44 +00:00
// load the rows (only first three)
2015-11-30 21:30:54 +00:00
$excelObj = $excelReader -> load ( $package [ 'dir' ]);
2024-02-10 09:13:31 +00:00
$headers = [];
2015-11-30 21:30:54 +00:00
foreach ( $excelObj -> getActiveSheet () -> getRowIterator () as $row )
{
if ( $row -> getRowIndex () == 1 )
{
$cellIterator = $row -> getCellIterator ();
$cellIterator -> setIterateOnlyExistingCells ( false );
foreach ( $cellIterator as $cell )
{
if ( ! is_null ( $cell ))
{
$headers [ $cell -> getColumn ()] = $cell -> getValue ();
}
}
$excelObj -> disconnectWorksheets ();
unset ( $excelObj );
break ;
}
}
return $headers ;
}
return false ;
2020-05-30 21:39:43 +00:00
}
/**
* Load the Composer Vendor phpspreadsheet
*/
protected static function composephpspreadsheet ()
{
// load the autoloader for phpspreadsheet
require_once JPATH_SITE . '/libraries/phpspreadsheet/vendor/autoload.php' ;
// do not load again
self :: $composer [ 'phpspreadsheet' ] = true ;
return true ;
2021-08-16 17:11:22 +00:00
}
/**
2024-02-10 09:13:31 +00:00
* Get a Variable
2021-08-16 17:11:22 +00:00
*
* @ param string $table The table from which to get the variable
* @ param string $where The value where
* @ param string $whereString The target / field string where / name
* @ param string $what The return field
* @ param string $operator The operator between $whereString / field and $where / value
* @ param string $main The component in which the table is found
*
* @ return mix string / int / float
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use GetHelper :: var ( ... );
2021-08-16 17:11:22 +00:00
*/
public static function getVar ( $table , $where = null , $whereString = 'user' , $what = 'id' , $operator = '=' , $main = 'sermondistributor' )
{
2024-02-10 09:13:31 +00:00
return GetHelper :: var (
$table ,
$where ,
$whereString ,
$what ,
$operator ,
$main
);
2021-08-16 17:11:22 +00:00
}
/**
* Get array of variables
*
* @ param string $table The table from which to get the variables
* @ param string $where The value where
* @ param string $whereString The target / field string where / name
* @ param string $what The return field
* @ param string $operator The operator between $whereString / field and $where / value
* @ param string $main The component in which the table is found
* @ param bool $unique The switch to return a unique array
*
* @ return array
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use GetHelper :: vars ( ... );
2021-08-16 17:11:22 +00:00
*/
public static function getVars ( $table , $where = null , $whereString = 'user' , $what = 'id' , $operator = 'IN' , $main = 'sermondistributor' , $unique = true )
{
2024-02-10 09:13:31 +00:00
return GetHelper :: vars (
$table ,
$where ,
$whereString ,
$what ,
$operator ,
$main ,
$unique
);
2021-08-16 17:11:22 +00:00
}
2024-02-10 09:13:31 +00:00
/**
* Convert a json object to a string
*
* @ input string $value The json string to convert
*
* @ returns a string
* @ deprecated 3.3 Use JsonHelper :: string ( ... );
*/
2021-08-16 17:11:22 +00:00
public static function jsonToString ( $value , $sperator = " , " , $table = null , $id = 'id' , $name = 'name' )
{
2024-02-10 09:13:31 +00:00
return JsonHelper :: string (
$value ,
$sperator ,
$table ,
$id ,
$name
);
2021-08-16 17:11:22 +00:00
}
public static function isPublished ( $id , $type )
{
if ( $type == 'raw' )
{
$type = 'item' ;
}
2024-02-10 09:13:31 +00:00
$db = Factory :: getDbo ();
2021-08-16 17:11:22 +00:00
$query = $db -> getQuery ( true );
$query -> select ( array ( 'a.published' ));
$query -> from ( '#__sermondistributor_' . $type . ' AS a' );
$query -> where ( 'a.id = ' . ( int ) $id );
$query -> where ( 'a.published = 1' );
$db -> setQuery ( $query );
$db -> execute ();
$found = $db -> getNumRows ();
if ( $found )
{
return true ;
}
return false ;
}
public static function getGroupName ( $id )
{
2024-02-10 09:13:31 +00:00
$db = Factory :: getDBO ();
2021-08-16 17:11:22 +00:00
$query = $db -> getQuery ( true );
$query -> select ( array ( 'a.title' ));
$query -> from ( '#__usergroups AS a' );
$query -> where ( 'a.id = ' . ( int ) $id );
$db -> setQuery ( $query );
$db -> execute ();
$found = $db -> getNumRows ();
if ( $found )
2024-02-10 09:13:31 +00:00
{
2021-08-16 17:11:22 +00:00
return $db -> loadResult ();
}
return $id ;
}
/**
* Get the action permissions
*
* @ param string $view The related view name
* @ param int $record The item to act upon
* @ param string $views The related list view name
* @ param mixed $target Only get this permission ( like edit , create , delete )
* @ param string $component The target component
* @ param object $user The user whose permissions we are loading
*
2024-02-10 09:13:31 +00:00
* @ return object The CMSObject of permission / authorised actions
*
2021-08-16 17:11:22 +00:00
*/
public static function getActions ( $view , & $record = null , $views = null , $target = null , $component = 'sermondistributor' , $user = 'null' )
{
// load the user if not given
2024-02-10 09:13:31 +00:00
if ( ! ObjectHelper :: check ( $user ))
2021-08-16 17:11:22 +00:00
{
// get the user object
2024-02-10 09:13:31 +00:00
$user = Factory :: getUser ();
2021-08-16 17:11:22 +00:00
}
2024-02-10 09:13:31 +00:00
// load the CMSObject
$result = new CMSObject ;
2021-08-16 17:11:22 +00:00
// make view name safe (just incase)
2024-02-10 09:13:31 +00:00
$view = UtilitiesStringHelper :: safe ( $view );
if ( UtilitiesStringHelper :: check ( $views ))
2021-08-16 17:11:22 +00:00
{
2024-02-10 09:13:31 +00:00
$views = UtilitiesStringHelper :: safe ( $views );
}
2021-08-16 17:11:22 +00:00
// get all actions from component
2024-02-10 09:13:31 +00:00
$actions = Access :: getActionsFromFile (
2021-08-16 17:11:22 +00:00
JPATH_ADMINISTRATOR . '/components/com_' . $component . '/access.xml' ,
" /access/section[@name='component']/ "
);
2024-02-10 09:13:31 +00:00
// if non found then return empty CMSObject
2021-08-16 17:11:22 +00:00
if ( empty ( $actions ))
{
return $result ;
}
// get created by if not found
2024-02-10 09:13:31 +00:00
if ( ObjectHelper :: check ( $record ) && ! isset ( $record -> created_by ) && isset ( $record -> id ))
2021-08-16 17:11:22 +00:00
{
2024-02-10 09:13:31 +00:00
$record -> created_by = GetHelper :: var ( $view , $record -> id , 'id' , 'created_by' , '=' , $component );
2021-08-16 17:11:22 +00:00
}
// set actions only set in component settings
$componentActions = array ( 'core.admin' , 'core.manage' , 'core.options' , 'core.export' );
// check if we have a target
$checkTarget = false ;
if ( $target )
{
// convert to an array
2024-02-10 09:13:31 +00:00
if ( UtilitiesStringHelper :: check ( $target ))
2021-08-16 17:11:22 +00:00
{
$target = array ( $target );
}
// check if we are good to go
2024-02-10 09:13:31 +00:00
if ( UtilitiesArrayHelper :: check ( $target ))
2021-08-16 17:11:22 +00:00
{
$checkTarget = true ;
}
}
// loop the actions and set the permissions
foreach ( $actions as $action )
{
// check target action filter
if ( $checkTarget && self :: filterActions ( $view , $action -> name , $target ))
{
continue ;
}
// set to use component default
$fallback = true ;
// reset permission per/action
$permission = false ;
$catpermission = false ;
// set area
$area = 'comp' ;
// check if the record has an ID and the action is item related (not a component action)
2024-02-10 09:13:31 +00:00
if ( ObjectHelper :: check ( $record ) && isset ( $record -> id ) && $record -> id > 0 && ! in_array ( $action -> name , $componentActions ) &&
2021-08-16 17:11:22 +00:00
( strpos ( $action -> name , 'core.' ) !== false || strpos ( $action -> name , $view . '.' ) !== false ))
{
// we are in item
$area = 'item' ;
// The record has been set. Check the record permissions.
$permission = $user -> authorise ( $action -> name , 'com_' . $component . '.' . $view . '.' . ( int ) $record -> id );
// if no permission found, check edit own
if ( ! $permission )
{
// With edit, if the created_by matches current user then dig deeper.
if (( $action -> name === 'core.edit' || $action -> name === $view . '.edit' ) && $record -> created_by > 0 && ( $record -> created_by == $user -> id ))
{
// the correct target
$coreCheck = ( array ) explode ( '.' , $action -> name );
// check that we have both local and global access
if ( $user -> authorise ( $coreCheck [ 0 ] . '.edit.own' , 'com_' . $component . '.' . $view . '.' . ( int ) $record -> id ) &&
$user -> authorise ( $coreCheck [ 0 ] . '.edit.own' , 'com_' . $component ))
{
// allow edit
$result -> set ( $action -> name , true );
// set not to use global default
// because we already validated it
$fallback = false ;
}
else
{
// do not allow edit
$result -> set ( $action -> name , false );
$fallback = false ;
}
}
}
2024-02-10 09:13:31 +00:00
elseif ( UtilitiesStringHelper :: check ( $views ) && isset ( $record -> catid ) && $record -> catid > 0 )
2021-08-16 17:11:22 +00:00
{
// we are in item
$area = 'category' ;
// set the core check
$coreCheck = explode ( '.' , $action -> name );
$core = $coreCheck [ 0 ];
// make sure we use the core. action check for the categories
if ( strpos ( $action -> name , $view ) !== false && strpos ( $action -> name , 'core.' ) === false )
{
$coreCheck [ 0 ] = 'core' ;
$categoryCheck = implode ( '.' , $coreCheck );
}
else
{
$categoryCheck = $action -> name ;
}
// The record has a category. Check the category permissions.
$catpermission = $user -> authorise ( $categoryCheck , 'com_' . $component . '.' . $views . '.category.' . ( int ) $record -> catid );
if ( ! $catpermission && ! is_null ( $catpermission ))
{
// With edit, if the created_by matches current user then dig deeper.
if (( $action -> name === 'core.edit' || $action -> name === $view . '.edit' ) && $record -> created_by > 0 && ( $record -> created_by == $user -> id ))
{
// check that we have both local and global access
if ( $user -> authorise ( 'core.edit.own' , 'com_' . $component . '.' . $views . '.category.' . ( int ) $record -> catid ) &&
$user -> authorise ( $core . '.edit.own' , 'com_' . $component ))
{
// allow edit
$result -> set ( $action -> name , true );
// set not to use global default
// because we already validated it
$fallback = false ;
}
else
{
// do not allow edit
$result -> set ( $action -> name , false );
$fallback = false ;
}
}
}
}
}
// if allowed then fallback on component global settings
if ( $fallback )
{
// if item/category blocks access then don't fall back on global
if ((( $area === 'item' ) && ! $permission ) || (( $area === 'category' ) && ! $catpermission ))
{
// do not allow
$result -> set ( $action -> name , false );
}
// Finally remember the global settings have the final say. (even if item allow)
// The local item permissions can block, but it can't open and override of global permissions.
// Since items are created by users and global permissions is set by system admin.
else
{
$result -> set ( $action -> name , $user -> authorise ( $action -> name , 'com_' . $component ));
}
}
}
return $result ;
}
/**
* Filter the action permissions
*
* @ param string $action The action to check
* @ param array $targets The array of target actions
*
* @ return boolean true if action should be filtered out
2024-02-10 09:13:31 +00:00
*
2021-08-16 17:11:22 +00:00
*/
protected static function filterActions ( & $view , & $action , & $targets )
{
foreach ( $targets as $target )
{
if ( strpos ( $action , $view . '.' . $target ) !== false ||
strpos ( $action , 'core.' . $target ) !== false )
{
return false ;
break ;
}
}
return true ;
}
/**
* Get any component ' s model
*/
2024-02-10 09:13:31 +00:00
public static function getModel ( $name , $path = JPATH_COMPONENT_ADMINISTRATOR , $Component = 'Sermondistributor' , $config = [])
2021-08-16 17:11:22 +00:00
{
// fix the name
2024-02-10 09:13:31 +00:00
$name = UtilitiesStringHelper :: safe ( $name );
2021-08-16 17:11:22 +00:00
// full path to models
$fullPathModels = $path . '/models' ;
// load the model file
2024-02-10 09:13:31 +00:00
BaseDatabaseModel :: addIncludePath ( $fullPathModels , $Component . 'Model' );
2021-08-16 17:11:22 +00:00
// make sure the table path is loaded
2024-02-10 09:13:31 +00:00
if ( ! isset ( $config [ 'table_path' ]) || ! UtilitiesStringHelper :: check ( $config [ 'table_path' ]))
2021-08-16 17:11:22 +00:00
{
// This is the JCB default path to tables in Joomla 3.x
$config [ 'table_path' ] = JPATH_ADMINISTRATOR . '/components/com_' . strtolower ( $Component ) . '/tables' ;
}
// get instance
2024-02-10 09:13:31 +00:00
$model = BaseDatabaseModel :: getInstance ( $name , $Component . 'Model' , $config );
2021-08-16 17:11:22 +00:00
// if model not found (strange)
if ( $model == false )
{
jimport ( 'joomla.filesystem.file' );
// get file path
$filePath = $path . '/' . $name . '.php' ;
$fullPathModel = $fullPathModels . '/' . $name . '.php' ;
// check if it exists
if ( File :: exists ( $filePath ))
{
// get the file
require_once $filePath ;
}
elseif ( File :: exists ( $fullPathModel ))
{
// get the file
require_once $fullPathModel ;
}
// build class names
$modelClass = $Component . 'Model' . $name ;
if ( class_exists ( $modelClass ))
{
// initialize the model
return new $modelClass ( $config );
}
}
return $model ;
}
/**
* Add to asset Table
*/
public static function setAsset ( $id , $table , $inherit = true )
{
2024-02-10 09:13:31 +00:00
$parent = Table :: getInstance ( 'Asset' );
2021-08-16 17:11:22 +00:00
$parent -> loadByName ( 'com_sermondistributor' );
2024-02-10 09:13:31 +00:00
2021-08-16 17:11:22 +00:00
$parentId = $parent -> id ;
$name = 'com_sermondistributor.' . $table . '.' . $id ;
$title = '' ;
2024-02-10 09:13:31 +00:00
$asset = Table :: getInstance ( 'Asset' );
2021-08-16 17:11:22 +00:00
$asset -> loadByName ( $name );
// Check for an error.
$error = $asset -> getError ();
if ( $error )
{
return false ;
}
else
{
// Specify how a new or moved node asset is inserted into the tree.
if ( $asset -> parent_id != $parentId )
{
$asset -> setLocation ( $parentId , 'last-child' );
}
// Prepare the asset to be stored.
$asset -> parent_id = $parentId ;
$asset -> name = $name ;
$asset -> title = $title ;
// get the default asset rules
$rules = self :: getDefaultAssetRules ( 'com_sermondistributor' , $table , $inherit );
2024-02-10 09:13:31 +00:00
if ( $rules instanceof AccessRules )
2021-08-16 17:11:22 +00:00
{
$asset -> rules = ( string ) $rules ;
}
if ( ! $asset -> check () || ! $asset -> store ())
{
2024-02-10 09:13:31 +00:00
Factory :: getApplication () -> enqueueMessage ( $asset -> getError (), 'warning' );
2021-08-16 17:11:22 +00:00
return false ;
}
else
{
// Create an asset_id or heal one that is corrupted.
$object = new stdClass ();
// Must be a valid primary key value.
$object -> id = $id ;
$object -> asset_id = ( int ) $asset -> id ;
// Update their asset_id to link to the asset table.
2024-02-10 09:13:31 +00:00
return Factory :: getDbo () -> updateObject ( '#__sermondistributor_' . $table , $object , 'id' );
2021-08-16 17:11:22 +00:00
}
}
return false ;
}
/**
* Gets the default asset Rules for a component / view .
*/
protected static function getDefaultAssetRules ( $component , $view , $inherit = true )
{
// if new or inherited
$assetId = 0 ;
// Only get the actual item rules if not inheriting
if ( ! $inherit )
{
// Need to find the asset id by the name of the component.
2024-02-10 09:13:31 +00:00
$db = Factory :: getDbo ();
2021-08-16 17:11:22 +00:00
$query = $db -> getQuery ( true )
-> select ( $db -> quoteName ( 'id' ))
-> from ( $db -> quoteName ( '#__assets' ))
-> where ( $db -> quoteName ( 'name' ) . ' = ' . $db -> quote ( $component ));
$db -> setQuery ( $query );
$db -> execute ();
// check that there is a value
if ( $db -> getNumRows ())
{
// asset already set so use saved rules
$assetId = ( int ) $db -> loadResult ();
}
}
// get asset rules
2024-02-10 09:13:31 +00:00
$result = Access :: getAssetRules ( $assetId );
if ( $result instanceof AccessRules )
2021-08-16 17:11:22 +00:00
{
$_result = ( string ) $result ;
$_result = json_decode ( $_result );
foreach ( $_result as $name => & $rule )
{
$v = explode ( '.' , $name );
if ( $view !== $v [ 0 ])
{
// remove since it is not part of this view
unset ( $_result -> $name );
}
elseif ( $inherit )
{
// clear the value since we inherit
2024-02-10 09:13:31 +00:00
$rule = [];
2021-08-16 17:11:22 +00:00
}
}
// check if there are any view values remaining
if ( count (( array ) $_result ))
{
$_result = json_encode ( $_result );
$_result = array ( $_result );
2024-02-10 09:13:31 +00:00
// Instantiate and return the AccessRules object for the asset rules.
$rules = new AccessRules ( $_result );
2021-08-16 17:11:22 +00:00
// return filtered rules
return $rules ;
}
}
return $result ;
}
/**
* xmlAppend
*
* @ param SimpleXMLElement $xml The XML element reference in which to inject a comment
* @ param mixed $node A SimpleXMLElement node to append to the XML element reference , or a stdClass object containing a comment attribute to be injected before the XML node and a fieldXML attribute containing a SimpleXMLElement
*
2024-02-10 09:13:31 +00:00
* @ return void
* @ deprecated 3.3 Use FormHelper :: append ( $xml , $node );
2021-08-16 17:11:22 +00:00
*/
public static function xmlAppend ( & $xml , $node )
{
2024-02-10 09:13:31 +00:00
FormHelper :: append ( $xml , $node );
2021-08-16 17:11:22 +00:00
}
/**
* xmlComment
*
* @ param SimpleXMLElement $xml The XML element reference in which to inject a comment
* @ param string $comment The comment to inject
*
2024-02-10 09:13:31 +00:00
* @ return void
* @ deprecated 3.3 Use FormHelper :: comment ( $xml , $comment );
2021-08-16 17:11:22 +00:00
*/
public static function xmlComment ( & $xml , $comment )
{
2024-02-10 09:13:31 +00:00
FormHelper :: comment ( $xml , $comment );
2021-08-16 17:11:22 +00:00
}
/**
* xmlAddAttributes
*
* @ param SimpleXMLElement $xml The XML element reference in which to inject a comment
* @ param array $attributes The attributes to apply to the XML element
*
* @ return null
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use FormHelper :: attributes ( $xml , $attributes );
2021-08-16 17:11:22 +00:00
*/
2024-02-10 09:13:31 +00:00
public static function xmlAddAttributes ( & $xml , $attributes = [])
2021-08-16 17:11:22 +00:00
{
2024-02-10 09:13:31 +00:00
FormHelper :: attributes ( $xml , $attributes );
2021-08-16 17:11:22 +00:00
}
/**
* xmlAddOptions
*
* @ param SimpleXMLElement $xml The XML element reference in which to inject a comment
* @ param array $options The options to apply to the XML element
*
* @ return void
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use FormHelper :: options ( $xml , $options );
2021-08-16 17:11:22 +00:00
*/
2024-02-10 09:13:31 +00:00
public static function xmlAddOptions ( & $xml , $options = [])
2021-08-16 17:11:22 +00:00
{
2024-02-10 09:13:31 +00:00
FormHelper :: options ( $xml , $options );
2021-08-16 17:11:22 +00:00
}
/**
* get the field object
*
* @ param array $attributes The array of attributes
* @ param string $default The default of the field
* @ param array $options The options to apply to the XML element
*
* @ return object
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use FormHelper :: field ( $attributes , $default , $options );
2021-08-16 17:11:22 +00:00
*/
public static function getFieldObject ( & $attributes , $default = '' , $options = null )
{
2024-02-10 09:13:31 +00:00
return FormHelper :: field ( $attributes , $default , $options );
2021-08-16 17:11:22 +00:00
}
/**
* get the field xml
*
* @ param array $attributes The array of attributes
* @ param array $options The options to apply to the XML element
*
* @ return object
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use FormHelper :: xml ( $attributes , $options );
2021-08-16 17:11:22 +00:00
*/
public static function getFieldXML ( & $attributes , $options = null )
{
2024-02-10 09:13:31 +00:00
return FormHelper :: xml ( $attributes , $options );
2021-08-16 17:11:22 +00:00
}
/**
* Render Bool Button
*
* @ param array $args All the args for the button
* 0 ) name
* 1 ) additional ( options class ) // not used at this time
* 2 ) default
* 3 ) yes ( name )
* 4 ) no ( name )
*
* @ return string The input html of the button
*
*/
public static function renderBoolButton ()
{
$args = func_get_args ();
// check if there is additional button class
$additional = isset ( $args [ 1 ]) ? ( string ) $args [ 1 ] : '' ; // not used at this time
// button attributes
$buttonAttributes = array (
'type' => 'radio' ,
2024-02-10 09:13:31 +00:00
'name' => isset ( $args [ 0 ]) ? UtilitiesStringHelper :: html ( $args [ 0 ]) : 'bool_button' ,
'label' => isset ( $args [ 0 ]) ? UtilitiesStringHelper :: safe ( UtilitiesStringHelper :: html ( $args [ 0 ]), 'Ww' ) : 'Bool Button' , // not seen anyway
2021-08-16 17:11:22 +00:00
'class' => 'btn-group' ,
'filter' => 'INT' ,
'default' => isset ( $args [ 2 ]) ? ( int ) $args [ 2 ] : 0 );
// set the button options
$buttonOptions = array (
2024-02-10 09:13:31 +00:00
'1' => isset ( $args [ 3 ]) ? UtilitiesStringHelper :: html ( $args [ 3 ]) : 'JYES' ,
'0' => isset ( $args [ 4 ]) ? UtilitiesStringHelper :: html ( $args [ 4 ]) : 'JNO' );
2021-08-16 17:11:22 +00:00
// return the input
2024-02-10 09:13:31 +00:00
return FormHelper :: field ( $buttonAttributes , $buttonAttributes [ 'default' ], $buttonOptions ) -> input ;
2021-08-16 17:11:22 +00:00
}
/**
* Check if have an json string
*
2024-02-10 09:13:31 +00:00
* @ input string The json string to check
2021-08-16 17:11:22 +00:00
*
* @ returns bool true on success
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use JsonHelper :: check ( $string );
2021-08-16 17:11:22 +00:00
*/
public static function checkJson ( $string )
{
2024-02-10 09:13:31 +00:00
return JsonHelper :: check ( $string );
2021-08-16 17:11:22 +00:00
}
/**
* Check if have an object with a length
*
2024-02-10 09:13:31 +00:00
* @ input object The object to check
2021-08-16 17:11:22 +00:00
*
* @ returns bool true on success
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use ObjectHelper :: check ( $object );
2021-08-16 17:11:22 +00:00
*/
public static function checkObject ( $object )
{
2024-02-10 09:13:31 +00:00
return ObjectHelper :: check ( $object );
2021-08-16 17:11:22 +00:00
}
/**
* Check if have an array with a length
*
2024-02-10 09:13:31 +00:00
* @ input array The array to check
2021-08-16 17:11:22 +00:00
*
* @ returns bool / int number of items in array on success
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use UtilitiesArrayHelper :: check ( $array , $removeEmptyString );
2021-08-16 17:11:22 +00:00
*/
public static function checkArray ( $array , $removeEmptyString = false )
{
2024-02-10 09:13:31 +00:00
return UtilitiesArrayHelper :: check ( $array , $removeEmptyString );
2021-08-16 17:11:22 +00:00
}
/**
* Check if have a string with a length
*
2024-02-10 09:13:31 +00:00
* @ input string The string to check
2021-08-16 17:11:22 +00:00
*
* @ returns bool true on success
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use UtilitiesStringHelper :: check ( $string );
2021-08-16 17:11:22 +00:00
*/
public static function checkString ( $string )
{
2024-02-10 09:13:31 +00:00
return UtilitiesStringHelper :: check ( $string );
2021-08-16 17:11:22 +00:00
}
/**
* Check if we are connected
* Thanks https :// stackoverflow . com / a / 4860432 / 1429677
*
* @ returns bool true on success
*/
public static function isConnected ()
{
// If example.com is down, then probably the whole internet is down, since IANA maintains the domain. Right?
2024-02-10 09:13:31 +00:00
$connected = @ fsockopen ( " www.example.com " , 80 );
// website, port (try 80 or 443)
2021-08-16 17:11:22 +00:00
if ( $connected )
{
//action when connected
$is_conn = true ;
fclose ( $connected );
}
else
{
//action in connection failure
$is_conn = false ;
}
return $is_conn ;
}
/**
* Merge an array of array ' s
*
2024-02-10 09:13:31 +00:00
* @ input array The arrays you would like to merge
2021-08-16 17:11:22 +00:00
*
* @ returns array on success
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use UtilitiesArrayHelper :: merge ( $arrays );
2021-08-16 17:11:22 +00:00
*/
public static function mergeArrays ( $arrays )
{
2024-02-10 09:13:31 +00:00
return UtilitiesArrayHelper :: merge ( $arrays );
2021-08-16 17:11:22 +00:00
}
// typo sorry!
public static function sorten ( $string , $length = 40 , $addTip = true )
{
return self :: shorten ( $string , $length , $addTip );
}
/**
* Shorten a string
*
2024-02-10 09:13:31 +00:00
* @ input string The you would like to shorten
2021-08-16 17:11:22 +00:00
*
* @ returns string on success
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use UtilitiesStringHelper :: shorten ( ... );
2021-08-16 17:11:22 +00:00
*/
public static function shorten ( $string , $length = 40 , $addTip = true )
{
2024-02-10 09:13:31 +00:00
return UtilitiesStringHelper :: shorten ( $string , $length , $addTip );
2021-08-16 17:11:22 +00:00
}
/**
* Making strings safe ( various ways )
*
2024-02-10 09:13:31 +00:00
* @ input string The you would like to make safe
2021-08-16 17:11:22 +00:00
*
* @ returns string on success
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use UtilitiesStringHelper :: safe ( ... );
2021-08-16 17:11:22 +00:00
*/
public static function safeString ( $string , $type = 'L' , $spacer = '_' , $replaceNumbers = true , $keepOnlyCharacters = true )
{
2024-02-10 09:13:31 +00:00
return UtilitiesStringHelper :: safe (
$string ,
$type ,
$spacer ,
$replaceNumbers ,
$keepOnlyCharacters
);
2021-08-16 17:11:22 +00:00
}
2024-02-10 09:13:31 +00:00
/**
* Convert none English strings to code usable string
*
* @ input an string
*
* @ returns a string
* @ deprecated 3.3 Use UtilitiesStringHelper :: transliterate ( $string );
*/
2021-08-16 17:11:22 +00:00
public static function transliterate ( $string )
{
2024-02-10 09:13:31 +00:00
return UtilitiesStringHelper :: transliterate ( $string );
2021-08-16 17:11:22 +00:00
}
2024-02-10 09:13:31 +00:00
/**
* make sure a string is HTML save
*
* @ input an html string
*
* @ returns a string
* @ deprecated 3.3 Use UtilitiesStringHelper :: html ( ... );
*/
2021-08-16 17:11:22 +00:00
public static function htmlEscape ( $var , $charset = 'UTF-8' , $shorten = false , $length = 40 )
{
2024-02-10 09:13:31 +00:00
return UtilitiesStringHelper :: html (
$var ,
$charset ,
$shorten ,
$length
);
2021-08-16 17:11:22 +00:00
}
2024-02-10 09:13:31 +00:00
/**
* Convert all int in a string to an English word string
*
* @ input an string with numbers
*
* @ returns a string
* @ deprecated 3.3 Use UtilitiesStringHelper :: numbers ( $string );
*/
2021-08-16 17:11:22 +00:00
public static function replaceNumbers ( $string )
{
2024-02-10 09:13:31 +00:00
return UtilitiesStringHelper :: numbers ( $string );
2021-08-16 17:11:22 +00:00
}
/**
* Convert an integer into an English word string
* Thanks to Tom Nicholson < http :// php . net / manual / en / function . strval . php #41988>
*
2024-02-10 09:13:31 +00:00
* @ input an int
2021-08-16 17:11:22 +00:00
* @ returns a string
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use UtilitiesStringHelper :: number ( $x );
2021-08-16 17:11:22 +00:00
*/
public static function numberToString ( $x )
{
2024-02-10 09:13:31 +00:00
return UtilitiesStringHelper :: number ( $x );
2021-08-16 17:11:22 +00:00
}
/**
* Random Key
*
* @ returns a string
2024-02-10 09:13:31 +00:00
* @ deprecated 3.3 Use UtilitiesStringHelper :: random ( $size );
2021-08-16 17:11:22 +00:00
*/
public static function randomkey ( $size )
{
2024-02-10 09:13:31 +00:00
return UtilitiesStringHelper :: random ( $size );
2016-11-27 04:20:48 +00:00
}
2018-03-19 22:24:44 +00:00
/**
* Get The Encryption Keys
*
* @ param string $type The type of key
* @ param string / bool $default The return value if no key was found
*
* @ return string On success
*
**/
public static function getCryptKey ( $type , $default = false )
2016-11-27 04:20:48 +00:00
{
2018-03-19 22:24:44 +00:00
// Get the global params
2024-02-10 09:13:31 +00:00
$params = ComponentHelper :: getParams ( 'com_sermondistributor' , true );
2018-03-19 22:24:44 +00:00
// Basic Encryption Type
2017-02-17 20:21:37 +00:00
if ( 'basic' === $type )
2016-11-27 04:20:48 +00:00
{
$basic_key = $params -> get ( 'basic_key' , $default );
2024-02-10 09:13:31 +00:00
if ( UtilitiesStringHelper :: check ( $basic_key ))
2016-11-27 04:20:48 +00:00
{
return $basic_key ;
}
}
2018-03-19 22:24:44 +00:00
return $default ;
2021-08-16 17:11:22 +00:00
}
}