2016-01-30 20:28:43 +00:00
< ? php
2021-03-05 03:08:47 +00:00
/**
* @ package Joomla . Component . Builder
*
* @ created 30 th April , 2015
2022-07-09 15:45:08 +00:00
* @ author Llewellyn van der Merwe < https :// dev . vdm . io >
* @ git Joomla Component Builder < https :// git . vdm . dev / joomla / Component - Builder >
2021-03-05 03:08:47 +00:00
* @ copyright Copyright ( C ) 2015 Vast Development Method . All rights reserved .
* @ license GNU General Public License version 2 or later ; see LICENSE . txt
*/
// No direct access to this file
defined ( '_JEXEC' ) or die ( 'Restricted access' );
2022-05-25 08:30:55 +00:00
use Joomla\CMS\MVC\Model\ListModel ;
2021-03-05 03:08:47 +00:00
use Joomla\Utilities\ArrayHelper ;
2023-05-02 00:10:55 +00:00
use VDM\Joomla\Gitea\Factory as GiteaFactory ;
2023-02-27 12:27:41 +00:00
use VDM\Joomla\Componentbuilder\Package\Factory as PackageFactory ;
use VDM\Joomla\Utilities\FileHelper ;
use VDM\Joomla\Utilities\JsonHelper ;
use VDM\Joomla\Utilities\StringHelper ;
2023-02-12 19:15:41 +00:00
use Joomla\Registry\Registry ;
2023-02-27 12:27:41 +00:00
use Joomla\CMS\Language\Text ;
2022-09-14 15:40:02 +00:00
use VDM\Joomla\Componentbuilder\Search\Factory as SearchFactory ;
2023-10-18 07:26:30 +00:00
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper ;
use VDM\Joomla\Utilities\GetHelper ;
use VDM\Joomla\Utilities\Base64Helper ;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\FieldHelper ;
2021-03-05 03:08:47 +00:00
/**
2022-05-25 08:30:55 +00:00
* Componentbuilder Ajax List Model
2021-03-05 03:08:47 +00:00
*/
2022-05-25 08:30:55 +00:00
class ComponentbuilderModelAjax extends ListModel
2021-03-05 03:08:47 +00:00
{
protected $app_params ;
public function __construct ()
{
parent :: __construct ();
// get params
$this -> app_params = JComponentHelper :: getParams ( 'com_componentbuilder' );
2016-01-30 20:28:43 +00:00
}
2017-02-16 14:02:23 +00:00
// Used in joomla_component
2019-05-15 17:39:27 +00:00
/**
* get the crowdin project details ( html )
**/
public function getCrowdinDetails ( $identifier , $key )
{
// set the url
$url = " https://api.crowdin.com/api/project/ $identifier /info?key= $key &json " ;
// get the details
2023-02-27 12:27:41 +00:00
if (( $details = FileHelper :: getContent ( $url , false )) !== false && JsonHelper :: check ( $details ))
2019-05-15 17:39:27 +00:00
{
$details = json_decode ( $details , true );
// check if there is an error
if ( isset ( $details [ 'error' ]))
{
return array ( 'error' => '<div class="alert alert-error">' . $details [ 'error' ][ 'message' ] . '<br /><br /><small>Identifier: ' . $identifier . '</small></div>' );
}
// build the details html
if ( isset ( $details [ 'details' ]))
{
$html = '<div class="alert alert-success" id="crowdin_message">' ;
2023-02-27 12:27:41 +00:00
$html .= '<h1>' . Text :: _ ( 'COM_COMPONENTBUILDER_COMPONENT_SUCCESSFULLY_LINKED' ) . '</h1>' ;
2019-05-15 17:39:27 +00:00
$html .= '<h3>' . $details [ 'details' ][ 'name' ] . '</h3>' ;
2023-02-27 12:27:41 +00:00
if ( StringHelper :: check ( $details [ 'details' ][ 'description' ]))
2019-05-15 17:39:27 +00:00
{
$html .= '<p>' ;
$html .= $details [ 'details' ][ 'description' ];
$html .= '</p>' ;
}
$html .= '<ul>' ;
$html .= '<li>Number of participants: <b>' ;
$html .= $details [ 'details' ][ 'participants_count' ];
$html .= '</b></li>' ;
$html .= '<li>Total strings count: <b>' ;
$html .= $details [ 'details' ][ 'total_strings_count' ];
$html .= '</b></li>' ;
$html .= '<li>Total words count: <b>' ;
$html .= $details [ 'details' ][ 'total_words_count' ];
$html .= '</b></li>' ;
$html .= '<li>Created: <b>' ;
$html .= ComponentbuilderHelper :: fancyDate ( $details [ 'details' ][ 'created' ]);
$html .= '</b></li>' ;
$html .= '<li>Last activity: <b>' ;
$html .= ComponentbuilderHelper :: fancyDate ( $details [ 'details' ][ 'last_activity' ]);
$html .= '</b></li>' ;
$html .= '</ul>' ;
$html .= '</div>' ;
2023-02-27 12:27:41 +00:00
return [ 'html' => $html ];
2019-05-15 17:39:27 +00:00
}
}
return false ;
}
2017-02-17 18:35:18 +00:00
/**
* get the component details ( html )
**/
public function getComponentDetails ( $id )
{
// Need to find the asset id by the name of the component.
$db = JFactory :: getDbo ();
$query = $db -> getQuery ( true )
-> select ( $db -> quoteName ( array (
2017-02-23 00:29:37 +00:00
'id' , 'companyname' , 'component_version' , 'copyright' , 'debug_linenr' ,
2017-02-17 18:35:18 +00:00
'description' , 'email' , 'image' , 'license' , 'name' ,
'short_description' , 'website' , 'author' , 'add_placeholders' ,
'system_name' , 'mvc_versiondate' )))
-> from ( $db -> quoteName ( '#__componentbuilder_joomla_component' ))
-> where ( $db -> quoteName ( 'id' ) . ' = ' . ( int ) $id );
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> loadRowList ())
{
2023-02-27 12:27:41 +00:00
return [ 'html' => $this -> componentDetailsDisplay ( $db -> loadObject ())];
2017-02-17 18:35:18 +00:00
}
return false ;
}
2018-05-01 22:17:38 +00:00
/**
* get the JCB package info ( html )
**/
2022-06-02 12:05:34 +00:00
public function getJCBpackageInfo ( $package )
2018-05-01 22:17:38 +00:00
{
// convert URL
2022-06-02 12:05:34 +00:00
$url = base64_decode ( $package );
2018-05-01 22:17:38 +00:00
$url = str_replace ( '.zip' , '.info' , $url );
2023-02-27 12:27:41 +00:00
2018-05-01 22:17:38 +00:00
// check if url exist
2023-02-27 12:27:41 +00:00
if ( $info = FileHelper :: getContent ( $url , false ))
2018-05-01 22:17:38 +00:00
{
2023-05-02 00:10:55 +00:00
$_info = PackageFactory :: _ ( 'Crypt' ) -> decrypt ( $info , 'local.legacy' );
// check if we had success
if ( ! JsonHelper :: check ( $_info ))
{
$_info = PackageFactory :: _ ( 'Crypt' ) -> decrypt ( $info , 'local.fof' );
}
// check if we have json
if ( JsonHelper :: check ( $_info ))
2018-05-01 22:17:38 +00:00
{
2023-05-02 00:10:55 +00:00
$info = json_decode ( $_info , true );
2023-02-27 12:27:41 +00:00
return [
'owner' => PackageFactory :: _ ( 'Display.Details' ) -> owner ( $info , true ),
'packages' => PackageFactory :: _ ( 'Display.Details' ) -> components ( $info )
];
2018-05-01 22:17:38 +00:00
}
}
2023-02-27 12:27:41 +00:00
return [
'error' => Text :: _ ( 'COM_COMPONENTBUILDER_JCB_PACKAGE_INFO_PATH_DOES_NOT_WORK_WE_ADVICE_YOU_BNOT_TO_CONTINUEB_WITH_THE_IMPORT_OF_THE_SELECTED_PACKAGE' )
];
2018-05-01 22:17:38 +00:00
}
2017-02-17 18:35:18 +00:00
/**
* set the component display
**/
protected function componentDetailsDisplay ( $object )
{
// set some vars
2023-02-27 12:27:41 +00:00
$image = ( StringHelper :: check ( $object -> image )) ? '<img alt="Joomla Component Image" src="' . JURI :: root () . $object -> image . '" style="float: right;">' : '' ;
$desc = ( StringHelper :: check ( $object -> description )) ? $object -> description : $object -> short_description ;
$placeholder = ( $object -> add_placeholders == 1 ) ? '<span class="btn btn-small btn-success"> ' . Text :: _ ( 'COM_COMPONENTBUILDER_YES' ) . ' </span>' : '<span class="btn btn-small btn-danger"> ' . Text :: _ ( 'COM_COMPONENTBUILDER_NO' ) . ' </span>' ;
$debug = ( $object -> debug_linenr == 1 ) ? '<span class="btn btn-small btn-success"> ' . Text :: _ ( 'COM_COMPONENTBUILDER_YES' ) . '</span>' : ' <span class="btn btn-small btn-danger"> ' . Text :: _ ( 'COM_COMPONENTBUILDER_NO' ) . ' </span>' ;
2017-02-17 18:35:18 +00:00
$html = array ();
$html [] = '<h3>' . $object -> name . ' (v' . $object -> component_version . ')</h3>' ;
$html [] = '<p>' . $desc . $image . '</p>' ;
$html [] = '<ul>' ;
2023-02-27 12:27:41 +00:00
$html [] = '<li>' . Text :: _ ( 'COM_COMPONENTBUILDER_COMPANY' ) . ': <b>' . $object -> companyname . '</b></li>' ;
$html [] = '<li>' . Text :: _ ( 'COM_COMPONENTBUILDER_AUTHOR' ) . ': <b>' . $object -> author . '</b></li>' ;
$html [] = '<li>' . Text :: _ ( 'COM_COMPONENTBUILDER_EMAIL' ) . ': <b>' . $object -> email . '</b></li>' ;
$html [] = '<li>' . Text :: _ ( 'COM_COMPONENTBUILDER_WEBSITE' ) . ': <b>' . $object -> website . '</b></li>' ;
2017-02-17 18:35:18 +00:00
$html [] = '</ul>' ;
2023-02-27 12:27:41 +00:00
$html [] = '<h4>' . Text :: _ ( 'COM_COMPONENTBUILDER_COMPONENT_GLOBAL_SETTINGS' ) . '</h4>' ;
2017-02-17 18:35:18 +00:00
$html [] = '<p>' ;
2023-02-27 12:27:41 +00:00
$html [] = Text :: _ ( 'COM_COMPONENTBUILDER_ADD_CUSTOM_CODE_PLACEHOLDERS' ) . '<br />' . $placeholder . '<br />' ;
$html [] = Text :: _ ( 'COM_COMPONENTBUILDER_DEBUG_LINE_NUMBERS' ) . '<br />' . $debug ;
2017-02-17 18:35:18 +00:00
$html [] = '</p>' ;
2023-02-27 12:27:41 +00:00
$html [] = '<h4>' . Text :: _ ( 'COM_COMPONENTBUILDER_LICENSE' ) . '</h4>' ;
2017-02-17 18:35:18 +00:00
$html [] = '<p>' . $object -> license . '</p>' ;
2023-02-27 12:27:41 +00:00
$html [] = '<h4>' . Text :: _ ( 'COM_COMPONENTBUILDER_COPYRIGHT' ) . '</h4>' ;
2017-03-03 21:53:18 +00:00
$html [] = '<p>' . $object -> copyright . '<br /><br />' ;
2023-02-27 12:27:41 +00:00
$html [] = '<a href="index.php?option=com_componentbuilder&ref=compiler&view=joomla_components&task=joomla_component.edit&id=' . ( int ) $object -> id . '" class="btn btn-small span12"><span class="icon-edit"></span> ' . Text :: _ ( 'COM_COMPONENTBUILDER_EDIT' ) . ' ' . $object -> system_name . '</a></p>' ;
2017-02-17 18:35:18 +00:00
// now return the diplay
return implode ( " \n " , $html );
2017-08-20 17:52:35 +00:00
}
/**
* get the component details ( html )
**/
public function getCronPath ( $type )
{
2023-02-27 12:27:41 +00:00
$result = array ( 'error' => '<span style="color: red;">' . Text :: _ ( 'COM_COMPONENTBUILDER_NO_CRONJOB_PATH_FOUND_SINCE_INCORRECT_TYPE_REQUESTED' ) . '</span>' );
2017-08-20 17:52:35 +00:00
if ( 'backup' === $type )
{
$result [ 'error' ] = '<span style="color: red;">' . JText :: sprintf ( 'COM_COMPONENTBUILDER_NO_CRONJOB_PATH_FOUND_FOR_S' , $type ) . '</span>' ;
if ( $this -> hasCurl ())
{
$path = '*/5 * * * * curl -s "' . JURI :: root () . 'index.php?option=com_componentbuilder&task=api.backup" >/dev/null 2>&1' ;
}
else
{
$path = '*/5 * * * * wget "' . JURI :: root () . 'index.php?option=com_componentbuilder&task=api.backup" >/dev/null 2>&1' ;
}
$result [ 'path' ] = '<code>' . $path . '</code>' ;
}
2018-04-24 22:36:05 +00:00
elseif ( 'expand' === $type )
{
$result [ 'error' ] = '<span style="color: red;">' . JText :: sprintf ( 'COM_COMPONENTBUILDER_NO_CRONJOB_PATH_FOUND_FOR_S' , $type ) . '</span>' ;
if ( $this -> hasCurl ())
{
$path = '* * * * * curl -s "' . JURI :: root () . 'index.php?option=com_componentbuilder&task=api.expand" >/dev/null 2>&1' ;
}
else
{
$path = '* * * * * wget "' . JURI :: root () . 'index.php?option=com_componentbuilder&task=api.expand" >/dev/null 2>&1' ;
}
$result [ 'path' ] = '<code>' . $path . '</code>' ;
}
2017-08-20 17:52:35 +00:00
return $result ;
}
2018-07-06 22:01:30 +00:00
2017-08-20 17:52:35 +00:00
protected function hasCurl ()
{
return function_exists ( 'curl_version' );
2022-07-09 15:16:21 +00:00
}
2023-10-18 07:26:30 +00:00
/**
* Check and if a notice is new ( per / user )
*
* @ param string | null $notice The current notice
*
* @ return bool true if is new
* @ since 2.0 . 0
*/
public function isNew ( ? string $notice ) : bool
2022-07-09 15:16:21 +00:00
{
2023-10-18 07:26:30 +00:00
// first get the file path
$path_filename = FileHelper :: getPath ( 'path' , 'usernotice' , 'md' , JFactory :: getUser () -> username , JPATH_COMPONENT_ADMINISTRATOR );
2022-07-09 15:16:21 +00:00
2023-10-18 07:26:30 +00:00
// check if the file is set
if (( $content = FileHelper :: getContent ( $path_filename , FALSE )) !== FALSE )
2022-07-09 15:16:21 +00:00
{
2023-10-18 07:26:30 +00:00
if ( $notice == $content )
{
return false ;
}
2022-07-09 15:16:21 +00:00
}
2023-10-18 07:26:30 +00:00
return true ;
2022-07-09 15:16:21 +00:00
}
2023-10-18 07:26:30 +00:00
/**
* Check if a notice has been read ( per / user )
*
* @ param string | null $notice The current notice
*
* @ return bool true if is read
* @ since 2.0 . 0
*/
public function isRead ( ? string $notice ) : bool
2022-07-09 15:16:21 +00:00
{
2023-10-18 07:26:30 +00:00
// first get the file path
$path_filename = FileHelper :: getPath ( 'path' , 'usernotice' , 'md' , JFactory :: getUser () -> username , JPATH_COMPONENT_ADMINISTRATOR );
// set as read if not already set
if (( $content = FileHelper :: getContent ( $path_filename , FALSE )) !== FALSE )
2022-07-09 15:16:21 +00:00
{
2023-10-18 07:26:30 +00:00
if ( $notice == $content )
{
return true ;
}
2022-07-09 15:16:21 +00:00
}
2023-10-18 07:26:30 +00:00
return FileHelper :: write ( $path_filename , $notice );
2022-07-09 20:37:56 +00:00
}
2023-10-18 07:26:30 +00:00
/**
* get Current Version
*
* @ param string | null $message The error messages if any .
*
* @ return array The array of the notice or error message
* @ since 2.3 . 0
*/
2022-07-09 20:37:56 +00:00
public function getVersion ( $version = null )
{
// get the token if set
2023-10-18 07:26:30 +00:00
$token = $this -> app_params -> get ( 'gitea_token' );
2023-05-02 00:10:55 +00:00
2022-07-09 20:37:56 +00:00
// only add if token is set
if ( $token )
{
try
{
2023-05-02 00:10:55 +00:00
// load the API details
GiteaFactory :: _ ( 'Gitea.Repository.Tags' ) -> load_ ( 'https://git.vdm.dev' , $token );
// get the repository tags
$tags = GiteaFactory :: _ ( 'Gitea.Repository.Tags' ) -> list ( 'joomla' , 'Component-Builder' );
2022-07-09 20:37:56 +00:00
}
catch ( DomainException $e )
{
return $this -> getTokenForVersion ( $e -> getMessage ());
}
catch ( InvalidArgumentException $e )
{
return $this -> getTokenForVersion ( $e -> getMessage ());
}
catch ( Exception $e )
{
return $this -> getTokenForVersion ( $e -> getMessage ());
}
// do we have tags returned
if ( isset ( $tags [ 0 ]) && isset ( $tags [ 0 ] -> name ))
{
// get the version
$manifest = ComponentbuilderHelper :: manifest ();
$local_version = ( string ) $manifest -> version ;
$current_version = trim ( $tags [ 0 ] -> name , 'vV' );
// now check if this version is out dated
if ( $current_version === $local_version )
{
2023-02-27 12:27:41 +00:00
return [ 'notice' => '<small><span style="color:green;"><span class="icon-shield"></span>' . Text :: _ ( 'COM_COMPONENTBUILDER_UP_TO_DATE' ) . '</span></small>' ];
2022-07-09 20:37:56 +00:00
}
else
{
// check if this is beta version
$current_array = array_map ( function ( $v ) { return ( int ) $v ; }, ( array ) explode ( '.' , $current_version ));
$local_array = array_map ( function ( $v ) { return ( int ) $v ; }, ( array ) explode ( '.' , $local_version ));
if (( $local_array [ 0 ] > $current_array [ 0 ]) ||
( $local_array [ 0 ] == $current_array [ 0 ] && $local_array [ 1 ] > $current_array [ 1 ]) ||
( $local_array [ 0 ] == $current_array [ 0 ] && $local_array [ 1 ] == $current_array [ 1 ] && $local_array [ 2 ] > $current_array [ 2 ]))
{
2023-02-27 12:27:41 +00:00
return [ 'notice' => '<small><span style="color:#F7B033;"><span class="icon-wrench"></span>' . Text :: _ ( 'COM_COMPONENTBUILDER_BETA_RELEASE' ) . '</span></small>' ];
2022-07-09 20:37:56 +00:00
}
else
{
// download link of the latest version
2023-10-18 07:26:30 +00:00
$download = " https://git.vdm.dev/api/v1/repos/joomla/Component-Builder/archive/ " . $tags [ 0 ] -> name . " .zip?access_token= " . $token ;
2022-07-09 20:37:56 +00:00
2023-02-27 12:27:41 +00:00
return [ 'notice' => '<small><span style="color:red;"><span class="icon-warning-circle"></span>' . Text :: _ ( 'COM_COMPONENTBUILDER_OUT_OF_DATE' ) . '!</span> <a style="color:green;" href="' .
$download . '" title="' . Text :: _ ( 'COM_COMPONENTBUILDER_YOU_CAN_DIRECTLY_DOWNLOAD_THE_LATEST_UPDATE_OR_USE_THE_JOOMLA_UPDATE_AREA' ) . '">' . Text :: _ ( 'COM_COMPONENTBUILDER_DOWNLOAD_UPDATE' ) . '!</a></small>' ];
2022-07-09 20:37:56 +00:00
}
}
}
}
return $this -> getTokenForVersion ();
}
2023-10-18 07:26:30 +00:00
/**
* Instructions to get Token for version
*
* @ param string | null $message The error messages if any .
*
* @ return array The array of the error message
* @ since 2.3 . 0
*/
protected function getTokenForVersion ( ? string $message = null ) : array
2022-07-09 20:37:56 +00:00
{
// the URL
$url = 'https://git.vdm.dev/user/settings/applications' ;
2023-10-18 07:26:30 +00:00
2022-07-09 20:37:56 +00:00
// create link
$a = '<small><a style="color:#F7B033;" href="' . $url . '" title="' ;
$a_ = '">' ;
$_a = '</a></small>' ;
if ( $message )
{
2023-02-27 12:27:41 +00:00
return [ 'error' => $a . $message . $a_ . Text :: _ ( 'COM_COMPONENTBUILDER_GET_TOKEN' ) . $_a ];
2022-07-09 20:37:56 +00:00
}
2023-02-27 12:27:41 +00:00
return [ 'error' => $a . Text :: _ ( 'COM_COMPONENTBUILDER_GET_TOKEN_FROM_VDM_TO_GET_UPDATE_NOTICE_AND_ADD_IT_TO_YOUR_GLOBAL_OPTIONS' ) . $a_ . Text :: _ ( 'COM_COMPONENTBUILDER_GET_TOKEN' ) . $_a ];
2022-07-09 20:37:56 +00:00
}
2023-10-18 07:26:30 +00:00
/**
* get Wiki Page
*
* @ param string | null $message The error messages if any .
*
* @ return array The array of the page or error message
* @ since 2.3 . 0
*/
public function getWiki ( string $name = 'Home' ) : array
{
try
{
// get the token if set
$token = $this -> app_params -> get ( 'gitea_token' );
// load the API details
GiteaFactory :: _ ( 'Gitea.Repository.Wiki' ) -> load_ ( 'https://git.vdm.dev' , $token );
// get the gitea wiki page im markdown
$wiki = GiteaFactory :: _ ( 'Gitea.Repository.Wiki' ) -> get ( 'joomla' , 'Component-Builder' , $name );
// now render the page in HTML
$page = GiteaFactory :: _ ( 'Gitea.Miscellaneous.Markdown' ) -> render ( $wiki -> content , true );
}
catch ( DomainException $e )
{
return $this -> getTokenForWiki ( $e -> getMessage ());
}
catch ( InvalidArgumentException $e )
{
return $this -> getTokenForWiki ( $e -> getMessage ());
}
catch ( Exception $e )
{
return $this -> getTokenForWiki ( $e -> getMessage ());
}
// get the html
if ( isset ( $page ))
{
return [ 'page' => $page ];
}
2023-02-27 12:27:41 +00:00
2023-10-18 07:26:30 +00:00
return $this -> getTokenForWiki ();
}
2022-07-09 20:37:56 +00:00
2023-10-18 07:26:30 +00:00
/**
* Instructions to get Token for wiki
*
* @ param string | null $message The error messages if any .
*
* @ return array The array of the error message
* @ since 2.3 . 0
*/
protected function getTokenForWiki ( ? string $message = null ) : array
{
if ( $message )
{
return [ 'error' => $message ];
}
return [ 'error' => Text :: _ ( 'COM_COMPONENTBUILDER_THE_WIKI_CAN_ONLY_BE_LOADED_WHEN_YOUR_JOOMLA_COMPONENT_BUILDER_SYSTEM_HAS_INTERNET_CONNECTION' )];
}
2016-10-31 21:47:21 +00:00
2019-12-10 23:18:55 +00:00
// Used in joomla_module
public function getModuleCode ( $data )
{
// reset the return array
$code = array ();
2023-10-18 07:26:30 +00:00
if ( JsonHelper :: check ( $data ))
2019-12-10 23:18:55 +00:00
{
// convert the data to object
$data = json_decode ( $data );
// set class
if ( isset ( $data -> class ) && is_numeric ( $data -> class ) && (( int ) $data -> class == 2 || ( int ) $data -> class == 1 ))
{
$code [ 'class' ] = array ();
// add the code
$code [ 'class' ][ 'code' ] = '// Include the helper functions only once' ;
$code [ 'class' ][ 'code' ] .= PHP_EOL . " JLoader::register('Mod[[[Module]]]Helper', __DIR__ . '/helper.php'); " ;
// set placement
$code [ 'class' ][ 'merge' ] = 1 ;
$code [ 'class' ][ 'merge_target' ] = 'prepend' ;
}
// get data
2023-10-18 07:26:30 +00:00
if ( isset ( $data -> get ) && UtilitiesArrayHelper :: check ( $data -> get ))
2019-12-10 23:18:55 +00:00
{
$code [ 'get' ] = array ();
// add the code
$code [ 'get' ][ 'code' ] = '// Include the data functions only once' ;
$code [ 'get' ][ 'code' ] .= PHP_EOL . " JLoader::register('Mod[[[Module]]]Data', __DIR__ . '/data.php'); " ;
// set placement
$code [ 'get' ][ 'merge' ] = 1 ;
$code [ 'get' ][ 'merge_target' ] = 'prepend' ;
}
// get libraries
2023-10-18 07:26:30 +00:00
if ( isset ( $data -> lib ) && UtilitiesArrayHelper :: check ( $data -> lib ))
2019-12-10 23:18:55 +00:00
{
$code [ 'lib' ] = array ();
// add the code
$code [ 'lib' ][ 'code' ] = '[[[MOD_LIBRARIES]]]' ;
// set placement
$code [ 'lib' ][ 'merge' ] = 1 ;
$code [ 'lib' ][ 'merge_target' ] = '// get the module class sfx (local)' ;
}
}
// set the defaults
$code [ 'css' ] = array ();
$code [ 'tmpl' ] = array ();
// add the code
$code [ 'css' ][ 'code' ] = '// get the module class sfx (local)' ;
$code [ 'css' ][ 'code' ] .= PHP_EOL . " \$ moduleclass_sfx = htmlspecialchars( \$ params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8'); " ;
$code [ 'tmpl' ][ 'code' ] = '// load the default Tmpl' ;
$code [ 'tmpl' ][ 'code' ] .= PHP_EOL . " require JModuleHelper::getLayoutPath('mod_[[[module]]]', \$ params->get('layout', 'default')); " ;
// set placement
$code [ 'css' ][ 'merge' ] = 1 ;
$code [ 'css' ][ 'merge_target' ] = '// load the default Tmpl' ;
$code [ 'tmpl' ][ 'merge' ] = 1 ;
$code [ 'tmpl' ][ 'merge_target' ] = 'append' ;
return $code ;
}
2019-07-15 20:00:46 +00:00
// Used in joomla_plugin
public function getClassCode ( $id , $type )
{
return ComponentbuilderHelper :: getClassCode ( $id , $type );
}
2021-10-18 20:12:19 +00:00
public function getClassCodeIds ( $id , $type , $key )
2019-07-15 20:00:46 +00:00
{
if ( 'property' === $type || 'method' === $type )
{
2021-10-18 20:12:19 +00:00
// we get the plugin group, or the powers
if ( $key == 1 )
{
return ComponentbuilderHelper :: getVars ( 'class_' . $type , $id , 'joomla_plugin_group' , 'id' );
}
elseif ( $key == 2 )
{
return ComponentbuilderHelper :: getVars ( 'class_' . $type , 'powers' , 'extension_type' , 'id' );
}
2019-07-15 20:00:46 +00:00
}
elseif ( 'joomla_plugin_group' === $type )
{
return ComponentbuilderHelper :: getVars ( $type , $id , 'class_extends' , 'id' );
}
return false ;
}
2019-07-19 02:17:15 +00:00
public function getClassHeaderCode ( $id , $type )
{
2023-10-18 07:26:30 +00:00
if ( 'extends' === $type && ( $head = ComponentbuilderHelper :: getVar ( 'class_' . $type , $id , 'id' , 'head' )) !== false && StringHelper :: check ( $head ))
2019-07-19 02:17:15 +00:00
{
return base64_decode ( $head );
}
return false ;
}
2019-07-15 20:00:46 +00:00
2016-01-30 20:28:43 +00:00
// Used in admin_view
2018-05-31 10:31:44 +00:00
protected $rowNumbers = array (
'admin_fields_conditions' => 80 ,
'admin_fields' => 50
);
2017-10-12 23:14:17 +00:00
protected $buttonArray = array (
2018-05-31 10:31:44 +00:00
'library_config' => 'libraries_config' ,
'library_files_folders_urls' => 'libraries_files_folders_urls' ,
'admin_fields' => 'admins_fields' ,
'admin_fields_conditions' => 'admins_fields_conditions' ,
'admin_fields_relations' => 'admins_fields_relations' ,
2018-08-24 21:46:41 +00:00
'admin_custom_tabs' => 'admins_custom_tabs' ,
2018-05-31 10:31:44 +00:00
'validation_rule' => 'validation_rules' ,
'field' => 'fields' ,
'component_admin_views' => 'components_admin_views' ,
'component_site_views' => 'components_site_views' ,
'component_custom_admin_views' => 'components_custom_views' ,
'component_updates' => 'components_updates' ,
'component_mysql_tweaks' => 'components_mysql_tweaks' ,
'component_custom_admin_menus' => 'components_custom_admin_menus' ,
'component_config' => 'components_config' ,
'component_dashboard' => 'components_dashboard' ,
'component_files_folders' => 'components_files_folders' ,
2019-05-15 22:50:45 +00:00
'custom_code' => 'custom_codes' ,
2018-05-31 10:31:44 +00:00
'language' => true );
2017-10-12 23:14:17 +00:00
2018-03-28 09:46:14 +00:00
public function checkAliasField ( $type )
{
// get the view name & id
$values = $this -> getViewID ();
if ( ! is_null ( $values [ 'a_id' ]) && $values [ 'a_id' ] > 0 && strlen ( $values [ 'a_view' ]) && in_array ( $values [ 'a_view' ], $this -> allowedViewsArray ))
{
// get the fields
if ( $fields = ComponentbuilderHelper :: getVar ( 'admin_fields' , $values [ 'a_id' ], 'admin_view' , 'addfields' ))
{
// open the fields
2023-10-18 07:26:30 +00:00
if ( JsonHelper :: check ( $fields ))
2018-03-28 09:46:14 +00:00
{
$fields = json_decode ( $fields , true );
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $fields ))
2018-03-28 09:46:14 +00:00
{
foreach ( $fields as $field )
{
if ( isset ( $field [ 'alias' ]) && $field [ 'alias' ] == 1 )
{
return true ;
}
}
}
}
}
}
return false ;
}
2021-01-06 10:02:55 +00:00
public function checkCategoryField ( $type )
{
// get the view name & id
$values = $this -> getViewID ();
if ( ! is_null ( $values [ 'a_id' ]) && $values [ 'a_id' ] > 0 && strlen ( $values [ 'a_view' ]) && in_array ( $values [ 'a_view' ], $this -> allowedViewsArray ))
{
// get the fields
if ( $fields = ComponentbuilderHelper :: getVar ( 'admin_fields' , $values [ 'a_id' ], 'admin_view' , 'addfields' ))
{
// open the fields
2023-10-18 07:26:30 +00:00
if ( JsonHelper :: check ( $fields ))
2021-01-06 10:02:55 +00:00
{
$fields = json_decode ( $fields , true );
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $fields ))
2021-01-06 10:02:55 +00:00
{
foreach ( $fields as $field )
{
if ( isset ( $field [ 'field' ]) &&
( $field_values = ComponentbuilderHelper :: getFieldNameAndType ( $field [ 'field' ])) !== false &&
$field_values [ 'type' ] === 'category' )
{
return true ;
}
}
}
}
}
}
return false ;
}
2018-03-28 09:46:14 +00:00
public function getDynamicScripts ( $type )
2016-05-04 04:53:33 +00:00
{
2017-03-27 12:38:51 +00:00
// get from global helper
2018-01-23 22:05:57 +00:00
return ComponentbuilderHelper :: getDynamicScripts ( $type );
2016-05-04 04:53:33 +00:00
}
2017-10-14 03:37:18 +00:00
protected $functionArray = array (
2017-11-26 00:29:08 +00:00
// Library
'rename' => 'setYesNo' ,
'update' => 'setYesNo' ,
'type' => 'setURLType' ,
2017-10-26 16:43:51 +00:00
// Admin View
2017-10-27 01:35:08 +00:00
'field' => 'setItemNames' ,
2018-05-22 19:01:36 +00:00
'listfield' => 'setItemNames' ,
'joinfields' => 'setItemNames' ,
2018-05-29 03:45:16 +00:00
'area' => 'setAreaName' ,
'set' => 'setCode' ,
2018-05-22 19:01:36 +00:00
'join_type' => 'setJoinType' ,
2018-04-13 15:24:06 +00:00
'list' => 'setAdminBehaviour' ,
2017-10-14 03:37:18 +00:00
'title' => 'setYesNo' ,
'alias' => 'setYesNo' ,
'sort' => 'setYesNo' ,
'search' => 'setYesNo' ,
'filter' => 'setYesNo' ,
'link' => 'setYesNo' ,
2018-07-21 07:10:37 +00:00
'permission' => 'setPermissions' ,
2017-10-14 03:37:18 +00:00
'tab' => 'setTabName' ,
'alignment' => 'setAlignmentName' ,
2017-10-27 01:35:08 +00:00
'target_field' => 'setItemNames' ,
2017-10-14 03:37:18 +00:00
'target_behavior' => 'setTargetBehavior' ,
'target_relation' => 'setTargetRelation' ,
2017-10-27 01:35:08 +00:00
'match_field' => 'setItemNames' ,
2017-10-14 03:37:18 +00:00
'match_behavior' => 'setMatchBehavior' ,
2017-10-26 16:43:51 +00:00
'match_options' => 'setMatchOptions' ,
// Joomla Component
'menu' => 'setYesNo' ,
'metadata' => 'setYesNo' ,
'default_view' => 'setYesNo' ,
'access' => 'setYesNo' ,
2017-12-22 19:46:03 +00:00
'public_access' => 'setYesNo' ,
2017-10-26 16:43:51 +00:00
'mainmenu' => 'setYesNo' ,
'dashboard_list' => 'setYesNo' ,
'submenu' => 'setYesNo' ,
'dashboard_add' => 'setYesNo' ,
'checkin' => 'setYesNo' ,
'history' => 'setYesNo' ,
2019-05-20 20:54:40 +00:00
'joomla_fields' => 'setYesNo' ,
2017-10-26 16:43:51 +00:00
'port' => 'setYesNo' ,
'edit_create_site_view' => 'setYesNo' ,
'icomoon' => 'setIcoMoon' ,
2017-10-27 01:35:08 +00:00
'customadminview' => 'setItemNames' ,
'adminviews' => 'setItemNames' ,
'adminview' => 'setItemNames' ,
'siteview' => 'setItemNames' ,
'before' => 'setItemNames' );
2017-10-28 03:25:33 +00:00
protected function getLanguage ( $key )
{
$language = array (
2017-11-26 00:29:08 +00:00
// Library (folder file url)
'rename' => JText :: _ ( 'COM_COMPONENTBUILDER_RENAME' ),
'path' => JText :: _ ( 'COM_COMPONENTBUILDER_TARGET_PATH' ),
'update' => JText :: _ ( 'COM_COMPONENTBUILDER_UPDATE' ),
2017-10-28 03:25:33 +00:00
// Admin View (fields)
'field' => JText :: _ ( 'COM_COMPONENTBUILDER_FIELD' ),
2018-05-22 19:01:36 +00:00
'listfield' => JText :: _ ( 'COM_COMPONENTBUILDER_LIST_FIELD' ),
'joinfields' => JText :: _ ( 'COM_COMPONENTBUILDER_JOIN_FIELDS' ),
'set' => JText :: _ ( 'COM_COMPONENTBUILDER_GLUECODE' ),
'join_type' => JText :: _ ( 'COM_COMPONENTBUILDER_JOIN_TYPE' ),
2018-04-13 15:24:06 +00:00
'list' => JText :: _ ( 'COM_COMPONENTBUILDER_ADMIN_BEHAVIOUR' ),
2017-10-28 03:25:33 +00:00
'order_list' => JText :: _ ( 'COM_COMPONENTBUILDER_ORDER_IN_LIST_VIEWS' ),
'title' => JText :: _ ( 'COM_COMPONENTBUILDER_TITLE' ),
'alias' => JText :: _ ( 'COM_COMPONENTBUILDER_ALIAS' ),
'sort' => JText :: _ ( 'COM_COMPONENTBUILDER_SORTABLE' ),
'search' => JText :: _ ( 'COM_COMPONENTBUILDER_SEARCHABLE' ),
'filter' => JText :: _ ( 'COM_COMPONENTBUILDER_FILTER' ),
'link' => JText :: _ ( 'COM_COMPONENTBUILDER_LINK' ),
'permission' => JText :: _ ( 'COM_COMPONENTBUILDER_PERMISSIONS' ),
'tab' => JText :: _ ( 'COM_COMPONENTBUILDER_TAB' ),
'alignment' => JText :: _ ( 'COM_COMPONENTBUILDER_ALIGNMENT' ),
'order_edit' => JText :: _ ( 'COM_COMPONENTBUILDER_ORDER_IN_EDIT' ),
// Admin View (conditions)
'target_field' => JText :: _ ( 'COM_COMPONENTBUILDER_TARGET_FIELDS' ),
2018-04-13 15:24:06 +00:00
'target_behavior' => JText :: _ ( 'COM_COMPONENTBUILDER_TARGET_BEHAVIOUR' ),
2017-10-28 03:25:33 +00:00
'target_relation' => JText :: _ ( 'COM_COMPONENTBUILDER_TARGET_RELATION' ),
'match_field' => JText :: _ ( 'COM_COMPONENTBUILDER_MATCH_FIELD' ),
2018-04-13 15:24:06 +00:00
'match_behavior' => JText :: _ ( 'COM_COMPONENTBUILDER_MATCH_BEHAVIOUR' ),
2017-10-28 03:25:33 +00:00
'match_options' => JText :: _ ( 'COM_COMPONENTBUILDER_MATCH_OPTIONS' ),
// Joomla Component
'menu' => JText :: _ ( 'COM_COMPONENTBUILDER_ADD_MENU' ),
'metadata' => JText :: _ ( 'COM_COMPONENTBUILDER_HAS_METADATA' ),
'default_view' => JText :: _ ( 'COM_COMPONENTBUILDER_DEFAULT_VIEW' ),
'access' => JText :: _ ( 'COM_COMPONENTBUILDER_ADD_ACCESS' ),
2017-12-22 19:46:03 +00:00
'public_access' => JText :: _ ( 'COM_COMPONENTBUILDER_PUBLIC_ACCESS' ),
2017-10-28 03:25:33 +00:00
'mainmenu' => JText :: _ ( 'COM_COMPONENTBUILDER_MAIN_MENU' ),
'dashboard_list' => JText :: _ ( 'COM_COMPONENTBUILDER_DASHBOARD_LIST_OF_RECORDS' ),
'dashboard_add' => JText :: _ ( 'COM_COMPONENTBUILDER_DASHBOARD_ADD_RECORD' ),
'submenu' => JText :: _ ( 'COM_COMPONENTBUILDER_SUBMENU' ),
'checkin' => JText :: _ ( 'COM_COMPONENTBUILDER_AUTO_CHECKIN' ),
'history' => JText :: _ ( 'COM_COMPONENTBUILDER_KEEP_HISTORY' ),
2019-05-20 20:54:40 +00:00
'joomla_fields' => JText :: _ ( 'COM_COMPONENTBUILDER_JOOMLA_FIELDS' ),
2017-10-28 03:25:33 +00:00
'port' => JText :: _ ( 'COM_COMPONENTBUILDER_EXPORTIMPORT_DATA' ),
'edit_create_site_view' => JText :: _ ( 'COM_COMPONENTBUILDER_EDITCREATE_SITE_VIEW' ),
'icomoon' => JText :: _ ( 'COM_COMPONENTBUILDER_ICON' ),
'customadminview' => JText :: _ ( 'COM_COMPONENTBUILDER_VIEW' ),
'adminviews' => JText :: _ ( 'COM_COMPONENTBUILDER_VIEWS' ),
'adminview' => JText :: _ ( 'COM_COMPONENTBUILDER_VIEW' ),
'siteview' => JText :: _ ( 'COM_COMPONENTBUILDER_VIEW' ),
'before' => JText :: _ ( 'COM_COMPONENTBUILDER_ORDER_BEFORE' )
);
// check if a unique value is available
if ( isset ( $language [ $key ]))
{
return $language [ $key ];
}
// check a shared value is available
2019-11-08 16:07:08 +00:00
if ( strpos ( $key , '|=VDM=|' ) !== false )
2017-10-14 03:37:18 +00:00
{
2019-11-08 16:07:08 +00:00
$keys = explode ( '|=VDM=|' , $key );
if ( isset ( $language [ $keys [ 1 ]]))
2017-10-16 17:14:23 +00:00
{
2019-11-08 16:07:08 +00:00
return $language [ $keys [ 1 ]];
2017-10-14 03:37:18 +00:00
}
}
2023-10-18 07:26:30 +00:00
return StringHelper :: safe ( $keys [ 1 ], 'Ww' );
2018-02-27 12:17:38 +00:00
}
2017-10-14 03:37:18 +00:00
2017-10-14 17:18:29 +00:00
protected $ref ;
2019-11-08 16:07:08 +00:00
2017-10-14 03:37:18 +00:00
protected $fieldsArray = array (
2017-11-26 00:29:08 +00:00
'library_config' => 'addconfig' ,
2019-03-19 15:33:03 +00:00
'library_files_folders_urls' => array ( 'addurls' , 'addfiles' , 'addfolders' , 'addfoldersfullpath' , 'addfilesfullpath' ),
2017-10-14 03:37:18 +00:00
'admin_fields' => 'addfields' ,
2017-10-26 16:43:51 +00:00
'admin_fields_conditions' => 'addconditions' ,
2018-05-22 19:01:36 +00:00
'admin_fields_relations' => 'addrelations' ,
2017-10-26 16:43:51 +00:00
'component_admin_views' => 'addadmin_views' ,
'component_site_views' => 'addsite_views' ,
'component_custom_admin_views' => 'addcustom_admin_views' );
2019-11-08 16:07:08 +00:00
2017-11-26 00:29:08 +00:00
protected $allowedViewsArray = array (
'admin_view' ,
'joomla_component' ,
'library' );
2017-10-14 03:37:18 +00:00
2017-10-16 17:14:23 +00:00
protected $conversionCheck = array (
'addfields' => 'field' ,
2017-10-26 16:43:51 +00:00
'addconditions' => 'target_field' ,
'addadmin_views' => 'adminview' ,
'addconfig' => 'field' ,
'addcustom_admin_views' => 'customadminview' ,
'addcustommenus' => 'name' ,
'addsite_views' => 'siteview' ,
'sql_tweak' => 'adminview' ,
'version_update' => 'version' );
2017-10-16 17:14:23 +00:00
2017-10-27 01:35:08 +00:00
protected $itemNames = array (
'field' => array (),
'admin_view' => array (),
'site_view' => array (),
'custom_admin_view' => array ()
);
protected $itemKeys = array (
// admin view
2019-11-09 01:53:24 +00:00
'field' => array ( 'table' => 'field' , 'tables' => 'fields' , 'id' => 'id' , 'name' => 'name' , 'text' => 'Field' , 'get' => 'getFieldNameAndType' ),
'target_field' => array ( 'table' => 'field' , 'tables' => 'fields' , 'id' => 'id' , 'name' => 'name' , 'text' => 'Field' , 'get' => 'getFieldNameAndType' ),
'match_field' => array ( 'table' => 'field' , 'tables' => 'fields' , 'id' => 'id' , 'name' => 'name' , 'text' => 'Field' , 'get' => 'getFieldNameAndType' ),
'listfield' => array ( 'table' => 'field' , 'tables' => 'fields' , 'id' => 'id' , 'name' => 'name' , 'text' => 'Field' , 'get' => 'getFieldNameAndType' ),
'joinfields' => array ( 'table' => 'field' , 'tables' => 'fields' , 'id' => 'id' , 'name' => 'name' , 'text' => 'Field' , 'get' => 'getFieldNameAndType' ),
2017-10-27 01:35:08 +00:00
// joomla component view
'siteview' => array ( 'table' => 'site_view' , 'tables' => 'site_views' , 'id' => 'id' , 'name' => 'name' , 'text' => 'Site View' ),
'customadminview' => array ( 'table' => 'custom_admin_view' , 'tables' => 'custom_admin_views' , 'id' => 'id' , 'name' => 'system_name' , 'text' => 'Custom Admin View' ),
'adminviews' => array ( 'table' => 'admin_view' , 'tables' => 'admin_views' , 'id' => 'id' , 'name' => 'system_name' , 'text' => 'Admin View' ),
'adminview' => array ( 'table' => 'admin_view' , 'tables' => 'admin_views' , 'id' => 'id' , 'name' => 'system_name' , 'text' => 'Admin View' ),
'before' => array ( 'table' => 'admin_view' , 'tables' => 'admin_views' , 'id' => 'id' , 'name' => 'system_name' , 'text' => 'Admin View' )
);
2021-08-11 12:15:35 +00:00
protected function checkRepeatableConversion ( $type , & $fieldsData , $fieldsArrayType , $id , $linked_id_name )
2017-10-27 01:35:08 +00:00
{
2023-10-18 07:26:30 +00:00
if ( JsonHelper :: check ( $fieldsData ) && isset ( $this -> conversionCheck [ $fieldsArrayType ]))
2017-10-27 01:35:08 +00:00
{
2019-11-08 16:07:08 +00:00
$fieldsData = json_decode ( $fieldsData , true );
if ( isset ( $fieldsData [ $this -> conversionCheck [ $fieldsArrayType ]]))
2017-10-27 01:35:08 +00:00
{
2019-11-08 16:07:08 +00:00
$bucket = array ();
foreach ( $fieldsData as $option => $values )
2017-10-27 01:35:08 +00:00
{
2019-11-08 16:07:08 +00:00
foreach ( $values as $nr => $value )
2017-11-02 23:41:32 +00:00
{
2019-11-08 16:07:08 +00:00
$bucket [ $fieldsArrayType . $nr ][ $option ] = $value ;
2017-11-02 23:41:32 +00:00
}
2017-10-27 01:35:08 +00:00
}
2019-11-08 16:07:08 +00:00
$fieldsData = json_encode ( $bucket );
// update the fields
$objectUpdate = new stdClass ();
$objectUpdate -> { $linked_id_name } = ( int ) $id ;
$objectUpdate -> { $fieldsArrayType } = $fieldsData ;
2021-08-11 12:15:35 +00:00
JFactory :: getDbo () -> updateObject ( '#__componentbuilder_' . $type , $objectUpdate , 'admin_view' );
2017-10-27 01:35:08 +00:00
}
}
}
2019-11-09 01:53:24 +00:00
protected function getFieldNameAndType ( $id )
{
// check if we can get the field name and type
if (( $array = ComponentbuilderHelper :: getFieldNameAndType ( $id , true )) !== false )
{
return ' [' . $array [ 'name' ] . ' - ' . $array [ 'type' ] . ']' ;
}
return '' ;
}
2018-07-21 07:10:37 +00:00
protected function setPermissions ( $header , $values )
{
// check if value is array
2023-10-18 07:26:30 +00:00
if ( ! UtilitiesArrayHelper :: check ( $values ))
2018-07-21 07:10:37 +00:00
{
$values = array ( $values );
}
// check if value is array
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $values ))
2018-07-21 07:10:37 +00:00
{
// Editing, Access, View
$bucket = array ();
foreach ( $values as $value )
{
switch ( $value )
{
case 1 :
$bucket [] = JText :: _ ( 'COM_COMPONENTBUILDER_EDITING' );
break ;
case 2 :
$bucket [] = JText :: _ ( 'COM_COMPONENTBUILDER_ACCESS' );
break ;
case 3 :
$bucket [] = JText :: _ ( 'COM_COMPONENTBUILDER_VIEW' );
break ;
}
}
// check if value is array
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $bucket ))
2018-07-21 07:10:37 +00:00
{
return implode ( ', ' , $bucket );
}
}
return JText :: _ ( 'COM_COMPONENTBUILDER_NONE' );
}
2018-05-22 19:01:36 +00:00
protected function setJoinType ( $header , $value )
{
switch ( $value )
{
case 1 :
return JText :: _ ( 'COM_COMPONENTBUILDER_CONCATENATE' );
break ;
case 2 :
return JText :: _ ( 'COM_COMPONENTBUILDER_CUSTOM_CODE' );
break ;
}
return JText :: _ ( 'COM_COMPONENTBUILDER_NOT_SET' );
}
2017-11-26 00:29:08 +00:00
protected function setURLType ( $header , $value )
{
switch ( $value )
{
case 1 :
return JText :: _ ( 'COM_COMPONENTBUILDER_DEFAULT_LINK' );
break ;
case 2 :
return JText :: _ ( 'COM_COMPONENTBUILDER_LOCAL_GET' );
break ;
case 3 :
return JText :: _ ( 'COM_COMPONENTBUILDER_LINK_LOCAL_DYNAMIC' );
break ;
}
return JText :: _ ( 'COM_COMPONENTBUILDER_NOT_SET' );
}
2017-10-26 16:43:51 +00:00
protected function setIcoMoon ( $header , $value )
{
2023-10-18 07:26:30 +00:00
if ( StringHelper :: check ( $value ))
2017-10-26 16:43:51 +00:00
{
return '<span class="icon-' . $value . '"></span>' ;
}
return '-' ;
}
2017-10-14 03:37:18 +00:00
protected function setAlignmentName ( $header , $value )
{
switch ( $value )
{
case 1 :
return JText :: _ ( 'COM_COMPONENTBUILDER_LEFT_IN_TAB' );
break ;
case 2 :
return JText :: _ ( 'COM_COMPONENTBUILDER_RIGHT_IN_TAB' );
break ;
case 3 :
return JText :: _ ( 'COM_COMPONENTBUILDER_FULL_WIDTH_IN_TAB' );
break ;
case 4 :
return JText :: _ ( 'COM_COMPONENTBUILDER_ABOVE_TABS' );
break ;
case 5 :
return JText :: _ ( 'COM_COMPONENTBUILDER_UNDERNEATH_TABS' );
break ;
case 6 :
return JText :: _ ( 'COM_COMPONENTBUILDER_LEFT_OF_TABS' );
break ;
case 7 :
return JText :: _ ( 'COM_COMPONENTBUILDER_RIGHT_OF_TABS' );
break ;
}
return JText :: _ ( 'COM_COMPONENTBUILDER_NOT_SET' );
}
2018-04-13 15:24:06 +00:00
protected function setAdminBehaviour ( $header , $value )
{
switch ( $value )
{
case 1 :
2019-08-14 11:45:49 +00:00
return JText :: _ ( 'COM_COMPONENTBUILDER_SHOW_IN_ALL_LIST_VIEWS' );
2018-04-13 15:24:06 +00:00
break ;
case 2 :
return JText :: _ ( 'COM_COMPONENTBUILDER_NONE_DB' );
break ;
2019-08-14 11:45:49 +00:00
case 3 :
return JText :: _ ( 'COM_COMPONENTBUILDER_ONLY_IN_ADMIN_LIST_VIEW' );
break ;
case 4 :
return JText :: _ ( 'COM_COMPONENTBUILDER_ONLY_IN_LINKED_LIST_VIEWS' );
break ;
2018-04-13 15:24:06 +00:00
default :
return JText :: _ ( 'COM_COMPONENTBUILDER_DEFAULT' );
break ;
}
}
2017-10-14 03:37:18 +00:00
protected $tabNames = array ();
protected function setTabName ( $header , $value )
{
2017-10-26 16:43:51 +00:00
// return published if set to 15 (since this is the default number for it)
if ( 15 == $value )
{
return JText :: _ ( 'COM_COMPONENTBUILDER_PUBLISHING' );
}
2023-10-18 07:26:30 +00:00
if ( ! UtilitiesArrayHelper :: check ( $this -> tabNames ))
2017-10-14 03:37:18 +00:00
{
// get the view name & id
$values = $this -> getViewID ();
if ( ! is_null ( $values [ 'a_id' ]) && $values [ 'a_id' ] > 0 && strlen ( $values [ 'a_view' ]) && $values [ 'a_view' ] === 'admin_view' )
{
if ( $tabs = ComponentbuilderHelper :: getVar ( 'admin_view' , $values [ 'a_id' ], 'id' , 'addtabs' ))
{
$tabs = json_decode ( $tabs , true );
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $tabs ))
2017-10-14 03:37:18 +00:00
{
$nr = 1 ;
foreach ( $tabs as $tab )
{
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $tab ) && isset ( $tab [ 'name' ]))
2017-10-14 03:37:18 +00:00
{
$this -> tabNames [ $nr ] = $tab [ 'name' ];
$nr ++ ;
}
}
}
}
}
}
// has it been set
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $this -> tabNames ) && isset ( $this -> tabNames [ $value ]))
2017-10-14 03:37:18 +00:00
{
return $this -> tabNames [ $value ];
}
return JText :: _ ( 'COM_COMPONENTBUILDER_DETAILS' );
}
2018-05-29 03:45:16 +00:00
protected function setAreaName ( $header , $value )
{
switch ( $value )
{
case 1 :
return JText :: _ ( 'COM_COMPONENTBUILDER_MODEL_BEFORE_MODELLING' );
break ;
case 2 :
return JText :: _ ( 'COM_COMPONENTBUILDER_VIEW' );
break ;
case 3 :
return JText :: _ ( 'COM_COMPONENTBUILDER_MODEL_AFTER_MODELLING' );
break ;
}
return JText :: _ ( 'COM_COMPONENTBUILDER_NOT_SET' );
}
protected function setCode ( $header , $value )
{
return nl2br ( htmlspecialchars ( $value ));
}
2017-10-14 03:37:18 +00:00
protected function setYesNo ( $header , $value )
{
if ( 1 == $value )
{
2017-10-27 01:35:08 +00:00
return '<span style="color: #46A546;" class="icon-ok"></span>' ;
2017-10-14 03:37:18 +00:00
}
2017-10-28 03:25:33 +00:00
return '<span style="color: #e6e6e6;" class="icon-delete"></span>' ;
2017-10-14 03:37:18 +00:00
}
protected function setTargetBehavior ( $header , $value )
{
if ( 1 == $value )
{
2018-09-09 20:04:38 +00:00
return JText :: _ ( 'COM_COMPONENTBUILDER_SHOW_TOGGLE' );
2017-10-14 03:37:18 +00:00
}
2018-09-09 20:04:38 +00:00
elseif ( 3 == $value )
{
return JText :: _ ( 'COM_COMPONENTBUILDER_SHOW_ONLY' );
}
elseif ( 4 == $value )
{
return JText :: _ ( 'COM_COMPONENTBUILDER_HIDE_ONLY' );
}
return JText :: _ ( 'COM_COMPONENTBUILDER_HIDE_TOGGLE' );
2017-10-14 03:37:18 +00:00
}
protected function setTargetRelation ( $header , $value )
{
switch ( $value )
{
case 0 :
return JText :: _ ( 'COM_COMPONENTBUILDER_ISOLATE' );
break ;
case 1 :
return JText :: _ ( 'COM_COMPONENTBUILDER_CHAIN' );
break ;
}
return JText :: _ ( 'COM_COMPONENTBUILDER_NOT_SET' );
}
protected function setMatchBehavior ( $header , $value )
{
switch ( $value )
{
case 1 :
return JText :: _ ( 'COM_COMPONENTBUILDER_IS_ONLY_FOUR_LISTRADIOCHECKBOXES' );
break ;
case 2 :
return JText :: _ ( 'COM_COMPONENTBUILDER_IS_NOT_ONLY_FOUR_LISTRADIOCHECKBOXES' );
break ;
case 3 :
return JText :: _ ( 'COM_COMPONENTBUILDER_ANY_SELECTION_ONLY_FOUR_LISTRADIOCHECKBOXESDYNAMIC_LIST' );
break ;
case 4 :
return JText :: _ ( 'COM_COMPONENTBUILDER_ACTIVE_ONLY_FOUR_TEXT_FIELD' );
break ;
case 5 :
return JText :: _ ( 'COM_COMPONENTBUILDER_UNACTIVE_ONLY_FOUR_TEXT_FIELD' );
break ;
case 6 :
return JText :: _ ( 'COM_COMPONENTBUILDER_KEY_WORD_ALL_CASESENSITIVE_ONLY_FOUR_TEXT_FIELD' );
break ;
case 7 :
return JText :: _ ( 'COM_COMPONENTBUILDER_KEY_WORD_ANY_CASESENSITIVE_ONLY_FOUR_TEXT_FIELD' );
break ;
case 8 :
return JText :: _ ( 'COM_COMPONENTBUILDER_KEY_WORD_ALL_CASEINSENSITIVE_ONLY_FOUR_TEXT_FIELD' );
break ;
case 9 :
return JText :: _ ( 'COM_COMPONENTBUILDER_KEY_WORD_ANY_CASEINSENSITIVE_ONLY_FOUR_TEXT_FIELD' );
break ;
case 10 :
return JText :: _ ( 'COM_COMPONENTBUILDER_MIN_LENGTH_ONLY_FOUR_TEXT_FIELD' );
break ;
case 11 :
return JText :: _ ( 'COM_COMPONENTBUILDER_MAX_LENGTH_ONLY_FOUR_TEXT_FIELD' );
break ;
case 12 :
return JText :: _ ( 'COM_COMPONENTBUILDER_EXACT_LENGTH_ONLY_FOUR_TEXT_FIELD' );
break ;
}
return JText :: _ ( 'COM_COMPONENTBUILDER_NOT_SET' );
}
protected function setMatchOptions ( $header , $value )
{
return str_replace ( " \n " , " <br /> " , $value );
}
2016-01-30 20:28:43 +00:00
public function getFieldSelectOptions ( $id )
2019-11-08 16:07:08 +00:00
{
2016-01-30 20:28:43 +00:00
// Create a new query object.
2018-01-15 15:54:05 +00:00
$query = $this -> _db -> getQuery ( true );
$query -> select ( $this -> _db -> quoteName ( array ( 'a.xml' , 'b.name' )));
$query -> from ( $this -> _db -> quoteName ( '#__componentbuilder_field' , 'a' ));
$query -> join ( 'LEFT' , $this -> _db -> quoteName ( '#__componentbuilder_fieldtype' , 'b' ) . ' ON (' . $this -> _db -> quoteName ( 'a.fieldtype' ) . ' = ' . $this -> _db -> quoteName ( 'b.id' ) . ')' );
$query -> where ( $this -> _db -> quoteName ( 'a.published' ) . ' = 1' );
$query -> where ( $this -> _db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $id );
2019-11-08 16:07:08 +00:00
2016-01-30 20:28:43 +00:00
// Reset the query using our newly populated query object.
2018-01-15 15:54:05 +00:00
$this -> _db -> setQuery ( $query );
$this -> _db -> execute ();
if ( $this -> _db -> getNumRows ())
2016-01-30 20:28:43 +00:00
{
2019-11-08 16:07:08 +00:00
$result = $this -> _db -> loadObject ();
$result -> name = strtolower ( $result -> name );
2018-05-24 13:56:56 +00:00
if ( ComponentbuilderHelper :: fieldCheck ( $result -> name , 'list' ))
2016-01-30 20:28:43 +00:00
{
// load the values form params
$xml = json_decode ( $result -> xml );
2019-11-08 16:07:08 +00:00
2023-10-18 07:26:30 +00:00
$xmlOptions = GetHelper :: between ( $xml , 'option="' , '"' );
2019-11-08 16:07:08 +00:00
2016-01-30 20:28:43 +00:00
$optionSet = '' ;
if ( strpos ( $xmlOptions , ',' ) !== false )
{
// mulitpal options
$options = explode ( ',' , $xmlOptions );
foreach ( $options as $option )
{
// return both value and text
2023-10-18 07:26:30 +00:00
if ( StringHelper :: check ( $optionSet ))
2016-01-30 20:28:43 +00:00
{
// no add to option set
$optionSet .= " \n " . $option ;
}
else
{
// no add to option set
$optionSet .= $option ;
}
}
}
else
{
// return both value and text
2023-10-18 07:26:30 +00:00
if ( StringHelper :: check ( $optionSet ))
2016-01-30 20:28:43 +00:00
{
// no add to option set
$optionSet .= " \n " . $xmlOptions ;
}
else
{
// no add to option set
$optionSet .= $xmlOptions ;
}
}
// return found field options
return $optionSet ;
}
2018-05-24 13:56:56 +00:00
elseif ( ComponentbuilderHelper :: fieldCheck ( $result -> name , 'text' ))
2016-01-30 20:28:43 +00:00
{
return " keywords= \" \" \n length= \" \" " ;
}
2018-05-24 13:56:56 +00:00
elseif ( ComponentbuilderHelper :: fieldCheck ( $result -> name , 'dynamic' ))
2016-01-30 20:28:43 +00:00
{
return 'dynamic_list' ;
}
2018-05-24 13:56:56 +00:00
elseif ( ComponentbuilderHelper :: fieldCheck ( $result -> name ))
2016-01-30 20:28:43 +00:00
{
return 'match field type not supported. Select another!' ;
}
else
{
return 'dynamic_list' ;
}
}
return false ;
}
2019-11-08 16:07:08 +00:00
2016-01-30 20:28:43 +00:00
public function getTableColumns ( $tableName )
{
// get the columns
2018-01-15 15:54:05 +00:00
$columns = $this -> _db -> getTableColumns ( " #__ " . $tableName );
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $columns ))
2016-01-30 20:28:43 +00:00
{
2019-11-08 16:07:08 +00:00
// build the return string
2016-01-30 20:28:43 +00:00
$tableColumns = array ();
foreach ( $columns as $column => $type )
{
$tableColumns [] = $column . ' => ' . $column ;
}
return implode ( " \n " , $tableColumns );
}
return false ;
2017-12-17 09:07:51 +00:00
}
2018-01-15 15:54:05 +00:00
protected $linkedKeys = array (
'field' => array (
2018-03-20 02:35:48 +00:00
array ( 'table' => 'component_config' , 'tables' => 'components_config' , 'fields' => array ( 'addconfig' => 'field' , 'joomla_component' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_JOOMLA_COMPONENT' , 'linked_name' => 'system_name' ),
2019-12-06 05:31:32 +00:00
array ( 'table' => 'library_config' , 'tables' => 'libraries_config' , 'fields' => array ( 'addconfig' => 'field' , 'library' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_LIBRARY' , 'linked_name' => 'name' ),
2018-03-20 02:35:48 +00:00
array ( 'table' => 'admin_fields' , 'tables' => 'admins_fields' , 'fields' => array ( 'addfields' => 'field' , 'admin_view' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_ADMIN_VIEW' , 'linked_name' => 'system_name' ),
2019-08-15 14:26:46 +00:00
array ( 'table' => 'field' , 'tables' => 'fields' , 'fields' => array ( 'xml' => 'fields' , 'name' => 'NAME' , 'fieldtype' => 'TYPE' ), 'linked' => 'COM_COMPONENTBUILDER_FIELD' , 'type_name' => 'name' ),
2019-12-06 05:31:32 +00:00
array ( 'table' => 'joomla_module' , 'tables' => 'joomla_modules' , 'fields' => array ( 'fields' => 'fields.fields.field' , 'system_name' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_JOOMLA_MODULE' ),
array ( 'table' => 'joomla_plugin' , 'tables' => 'joomla_plugins' , 'fields' => array ( 'fields' => 'fields.fields.field' , 'system_name' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_JOOMLA_PLUGIN' )
2018-01-15 15:54:05 +00:00
),
'admin_view' => array (
2018-03-20 02:35:48 +00:00
array ( 'table' => 'component_admin_views' , 'tables' => 'components_admin_views' , 'fields' => array ( 'addadmin_views' => 'adminview' , 'joomla_component' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_JOOMLA_COMPONENT' , 'linked_name' => 'system_name' )
2018-01-15 15:54:05 +00:00
),
'custom_admin_view' => array (
2018-03-20 02:35:48 +00:00
array ( 'table' => 'component_custom_admin_views' , 'tables' => 'components_custom_admin_views' , 'fields' => array ( 'addcustom_admin_views' => 'customadminview' , 'joomla_component' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_JOOMLA_COMPONENT' , 'linked_name' => 'system_name' )
2018-01-15 15:54:05 +00:00
),
'site_view' => array (
2018-03-20 02:35:48 +00:00
array ( 'table' => 'component_site_views' , 'tables' => 'components_site_views' , 'fields' => array ( 'addsite_views' => 'siteview' , 'joomla_component' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_JOOMLA_COMPONENT' , 'linked_name' => 'system_name' )
2018-01-15 15:54:05 +00:00
),
'library' => array (
2018-03-20 02:35:48 +00:00
array ( 'table' => 'template' , 'tables' => 'templates' , 'fields' => array ( 'libraries' => 'ARRAY' , 'name' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_TEMPLATE' ),
array ( 'table' => 'layout' , 'tables' => 'layouts' , 'fields' => array ( 'libraries' => 'ARRAY' , 'name' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_LAYOUT' ),
array ( 'table' => 'site_view' , 'tables' => 'site_views' , 'fields' => array ( 'libraries' => 'ARRAY' , 'system_name' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_SITE_VIEW' ),
array ( 'table' => 'custom_admin_view' , 'tables' => 'custom_admin_views' , 'fields' => array ( 'libraries' => 'ARRAY' , 'system_name' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW' )
2018-01-15 15:54:05 +00:00
),
'dynamic_get' => array (
2018-03-20 02:35:48 +00:00
array ( 'table' => 'site_view' , 'tables' => 'site_views' , 'fields' => array ( 'custom_get' => 'ARRAY' , 'main_get' => 'INT' , 'system_name' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_SITE_VIEW' ),
array ( 'table' => 'custom_admin_view' , 'tables' => 'custom_admin_views' , 'fields' => array ( 'custom_get' => 'ARRAY' , 'main_get' => 'INT' , 'system_name' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW' )
2019-08-15 14:26:46 +00:00
),
2019-12-06 05:31:32 +00:00
'joomla_module' => array (
array ( 'table' => 'component_modules' , 'tables' => 'components_modules' , 'fields' => array ( 'addjoomla_modules' => 'module' , 'joomla_component' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_JOOMLA_COMPONENT' , 'linked_name' => 'system_name' )
),
2019-08-15 14:26:46 +00:00
'joomla_plugin' => array (
array ( 'table' => 'component_plugins' , 'tables' => 'components_plugins' , 'fields' => array ( 'addjoomla_plugins' => 'plugin' , 'joomla_component' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_JOOMLA_COMPONENT' , 'linked_name' => 'system_name' )
2021-12-21 14:44:50 +00:00
),
'power' => array (
2022-05-25 08:30:55 +00:00
array ( 'table' => 'admin_view' , 'tables' => 'admin_views' , 'fields' => array ( 'params' => 'admin_view_headers:power_:power' , 'system_name' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_ADMIN_VIEW' ),
array ( 'table' => 'site_view' , 'tables' => 'site_views' , 'fields' => array ( 'params' => 'site_view_headers:power_:power' , 'system_name' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_SITE_VIEW' ),
array ( 'table' => 'custom_admin_view' , 'tables' => 'custom_admin_views' , 'fields' => array ( 'params' => 'custom_admin_view_headers:power_:power' , 'system_name' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW' ),
array ( 'table' => 'joomla_component' , 'tables' => 'joomla_components' , 'fields' => array ( 'params' => 'joomla_component_headers:power_:power' , 'system_name' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_JOOMLA_COMPONENT' ),
array ( 'table' => 'component_dashboard' , 'tables' => 'components_dashboard' , 'fields' => array ( 'params' => 'component_dashboard_headers:power_:power' , 'joomla_component' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_COMPONENT_DASHBOARD' , 'linked_name' => 'system_name' ),
2022-05-16 04:25:03 +00:00
array ( 'table' => 'power' , 'tables' => 'powers' , 'fields' => array ( 'extends' => 'GUID' , 'implements' => 'ARRAY' , 'use_selection' => 'use' , 'load_selection' => 'load' , 'system_name' => 'NAME' ), 'linked' => 'COM_COMPONENTBUILDER_POWER' )
2018-01-15 15:54:05 +00:00
)
);
2017-12-17 09:07:51 +00:00
/**
2018-01-15 15:54:05 +00:00
* Get Linked
2017-12-17 09:07:51 +00:00
*
2018-01-15 15:54:05 +00:00
* @ param int $type The display return type
2017-12-17 09:07:51 +00:00
*
2018-01-15 15:54:05 +00:00
* @ return string The display return type on success
2017-12-17 09:07:51 +00:00
*
*/
2018-01-15 15:54:05 +00:00
public function getLinked ( $type )
2017-12-17 09:07:51 +00:00
{
// get the view name & id
$values = $this -> getViewID ();
// check if item is set
if ( ! is_null ( $values [ 'a_id' ]) && $values [ 'a_id' ] > 0 && strlen ( $values [ 'a_view' ]))
{
2018-01-15 15:54:05 +00:00
// check if we have any linked to config
if ( isset ( $this -> linkedKeys [ $values [ 'a_view' ]]))
2017-12-17 09:07:51 +00:00
{
2018-08-18 12:09:17 +00:00
// set a return value
$return_url = 'index.php?option=com_componentbuilder&view=' . ( string ) $values [ 'a_view' ] . '&layout=edit&id=' . ( int ) $values [ 'a_id' ];
if ( isset ( $values [ 'a_return' ]))
{
$return_url .= '&return=' . ( string ) $values [ 'a_return' ];
}
2018-01-15 15:54:05 +00:00
// make sure the ref is set
2018-08-18 12:09:17 +00:00
$this -> ref = '&ref=' . $values [ 'a_view' ] . '&refid=' . $values [ 'a_id' ] . '&return=' . urlencode ( base64_encode ( $return_url ));
2022-05-16 04:25:03 +00:00
// specail treatment of powers
$guid = false ;
if ( 'power' === $values [ 'a_view' ])
{
$guid = $values [ 'a_guid' ];
}
2018-01-15 15:54:05 +00:00
// get the linked to
2022-05-16 04:25:03 +00:00
if ( $linked = $this -> getLinkedTo ( $values [ 'a_view' ], $values [ 'a_id' ], $guid ))
2017-12-17 09:07:51 +00:00
{
2018-03-27 09:57:16 +00:00
// just return it for now a table
$table = '<div class="control-group"><table class="uk-table uk-table-hover uk-table-striped uk-table-condensed">' ;
2023-10-18 07:26:30 +00:00
$table .= '<caption>' . JText :: sprintf ( 'COM_COMPONENTBUILDER_PLACES_ACROSS_JCB_WHERE_THIS_S_IS_LINKED' , StringHelper :: safe ( $values [ 'a_view' ], 'w' )) . '</caption>' ;
2018-03-27 09:57:16 +00:00
$table .= '<thead><tr><th>' . JText :: _ ( 'COM_COMPONENTBUILDER_TYPE_NAME' ) . '</th></tr></thead>' ;
$table .= '<tbody><tr><td>' . implode ( '</td></tr><tr><td>' , $linked ) . '</td></tr></tbody></table></div>' ;
return $table ;
2017-12-17 09:07:51 +00:00
}
}
2018-01-15 15:54:05 +00:00
}
// if not found but has session view name
if ( strlen ( $values [ 'a_view' ]))
{
2023-10-18 07:26:30 +00:00
return '<div class="control-group"><div class="alert alert-info"><h4>' . JText :: sprintf ( 'COM_COMPONENTBUILDER_S_NOT_LINKED' , StringHelper :: safe ( $values [ 'a_view' ], 'Ww' )) . '</h4><p>' . JText :: sprintf ( 'COM_COMPONENTBUILDER_THIS_BSB_IS_NOT_LINKED_TO_ANY_OTHER_AREAS_OF_JCB_AT_THIS_TIME' , $values [ 'a_view' ]) . '</p></div></div>' ;
2017-12-17 09:07:51 +00:00
}
// no view or id found in session, or view not allowed to access area
return '<div class="control-group"><div class="alert alert-error"><h4>' . JText :: _ ( 'COM_COMPONENTBUILDER_ERROR' ) . '</h4><p>' . JText :: _ ( 'COM_COMPONENTBUILDER_THERE_WAS_A_PROBLEM_BNO_VIEW_OR_ID_FOUND_IN_SESSION_OR_VIEW_NOT_ALLOWED_TO_ACCESS_AREAB_WE_COULD_NOT_LOAD_ANY_LINKED_TO_VALUES_PLEASE_INFORM_YOUR_SYSTEM_ADMINISTRATOR' ) . '</p></div></div>' ;
}
/**
2018-01-15 15:54:05 +00:00
* Get Linked to Items
2017-12-17 09:07:51 +00:00
*
2022-05-16 04:25:03 +00:00
* @ param string $view View that is being searched for
* @ param int $id ID
* @ param string $guid GUID
2017-12-17 09:07:51 +00:00
*
2018-01-15 15:54:05 +00:00
* @ return array Found items
2017-12-17 09:07:51 +00:00
*
*/
2022-05-16 04:25:03 +00:00
protected function getLinkedTo ( $view , $id , $guid )
2017-12-17 09:07:51 +00:00
{
// reset bucket
2018-01-15 15:54:05 +00:00
$linked = array ();
// start search
foreach ( $this -> linkedKeys [ $view ] as $search )
{
// Create a new query object.
$query = $this -> _db -> getQuery ( true );
// get all history values
$selection = array_keys ( $search [ 'fields' ]);
$selection [] = 'id' ;
$query -> select ( $selection );
$query -> from ( '#__componentbuilder_' . $search [ 'table' ]);
$this -> _db -> setQuery ( $query );
$this -> _db -> execute ();
if ( $this -> _db -> getNumRows ())
2017-12-17 09:07:51 +00:00
{
2018-01-15 15:54:05 +00:00
// load all items
$items = $this -> _db -> loadObjectList ();
// search the items
foreach ( $items as $item )
2017-12-17 09:07:51 +00:00
{
2018-01-15 15:54:05 +00:00
$found = false ;
2018-03-20 02:35:48 +00:00
$type_name = null ;
2018-01-15 15:54:05 +00:00
foreach ( $search [ 'fields' ] as $key => $target )
2017-12-17 09:07:51 +00:00
{
2018-01-15 15:54:05 +00:00
if ( 'NAME' === $target )
2017-12-17 09:07:51 +00:00
{
2018-03-20 02:35:48 +00:00
$linked_name = $item -> { $key };
$linked_nameTable = $key ;
continue ;
}
elseif ( 'TYPE' === $target )
{
$type_name = $item -> { $key };
$type_nameTable = $key ;
2018-01-15 15:54:05 +00:00
continue ;
}
elseif ( ! $found )
{
if ( 'INT' === $target )
2017-12-17 09:07:51 +00:00
{
2018-01-15 15:54:05 +00:00
// check if ID match
if ( $item -> { $key } == $id )
2017-12-17 09:07:51 +00:00
{
2018-01-15 15:54:05 +00:00
$found = true ;
2017-12-17 09:07:51 +00:00
}
}
2022-05-16 04:25:03 +00:00
elseif ( 'GUID' === $target )
{
// check if GUID match
if ( $this -> linkedGuid ( $guid , $item -> { $key }))
{
$found = true ;
}
}
2018-01-15 15:54:05 +00:00
else
2017-12-17 09:07:51 +00:00
{
2018-01-15 15:54:05 +00:00
// check if we have a json
2023-10-18 07:26:30 +00:00
if ( JsonHelper :: check ( $item -> { $key }))
2018-01-15 15:54:05 +00:00
{
$item -> { $key } = json_decode ( $item -> { $key }, true );
}
// if array
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $item -> { $key }))
2018-01-15 15:54:05 +00:00
{
if ( 'ARRAY' === $target )
{
// check if ID match
foreach ( $item -> { $key } as $_id )
{
2022-05-16 04:25:03 +00:00
if ( $_id == $id || $this -> linkedGuid ( $guid , $_id ))
2018-01-15 15:54:05 +00:00
{
$found = true ;
}
}
}
else
{
2019-12-06 05:31:32 +00:00
// check if this is a sub sub form target
if ( strpos ( $target , '.' ) !== false )
2018-01-15 15:54:05 +00:00
{
2019-12-06 05:31:32 +00:00
$_target = ( array ) explode ( '.' , $target );
// check that we have an array and get the size
2023-10-18 07:26:30 +00:00
if (( $_size = UtilitiesArrayHelper :: check ( $_target )) !== false )
2018-01-15 15:54:05 +00:00
{
2019-12-06 05:31:32 +00:00
foreach ( $item -> { $key } as $row )
{
if ( $_size == 2 )
{
2022-05-16 04:25:03 +00:00
if ( isset ( $row [ $_target [ 0 ]]) && isset ( $row [ $_target [ 0 ]][ $_target [ 1 ]]) && ( $row [ $_target [ 0 ]][ $_target [ 1 ]] == $id || $this -> linkedGuid ( $guid , $row [ $_target [ 0 ]][ $_target [ 1 ]])))
2019-12-06 05:31:32 +00:00
{
$found = true ;
}
}
2023-10-18 07:26:30 +00:00
elseif ( $_size == 3 && isset ( $row [ $_target [ 0 ]]) && UtilitiesArrayHelper :: check ( $row [ $_target [ 0 ]]))
2019-12-06 05:31:32 +00:00
{
foreach ( $row [ $_target [ 0 ]] as $_row )
{
2022-05-16 04:25:03 +00:00
if ( ! $found && isset ( $_row [ $_target [ 2 ]]) && ( $_row [ $_target [ 2 ]] == $id || $this -> linkedGuid ( $guid , $_row [ $_target [ 2 ]])))
2019-12-06 05:31:32 +00:00
{
$found = true ;
}
}
}
}
}
}
2021-12-21 14:44:50 +00:00
elseif ( strpos ( $target , ':' ) !== false )
{
$_target = ( array ) explode ( ':' , $target );
// check that we have an array and get the size
if (( $_size = ComponentbuilderHelper :: checkArray ( $_target )) == 2 )
{
foreach ( $item -> { $key } as $field_name => $row )
{
if ( ! $found && $field_name === $_target [ 0 ])
{
2022-05-25 08:30:55 +00:00
foreach ( $row as $_key => $_ids )
2021-12-21 14:44:50 +00:00
{
2022-05-25 08:30:55 +00:00
if ( ! $found && strpos ( $_key , $_target [ 1 ]) !== false && ( in_array ( $id , $_ids ) || $this -> linkedGuid ( $guid , $_ids )))
2021-12-21 14:44:50 +00:00
{
$found = true ;
}
}
}
}
}
2022-05-25 08:30:55 +00:00
// check that we have an array and get the size
if (( $_size = ComponentbuilderHelper :: checkArray ( $_target )) == 3 )
{
foreach ( $item -> { $key } as $field_name => $row )
{
if ( ! $found && $field_name === $_target [ 0 ])
{
foreach ( $row as $_key => $_items )
{
if ( ! $found && strpos ( $_key , $_target [ 1 ]) !== false && is_array ( $_items ) && count ( $_items ) > 0 )
{
foreach ( $_items as $_item )
{
if ( ! $found && isset ( $_item [ $_target [ 2 ]]) && ( $id == $_item [ $_target [ 2 ]] || $this -> linkedGuid ( $guid , $_item [ $_target [ 2 ]])))
{
$found = true ;
}
}
}
}
}
}
}
2021-12-21 14:44:50 +00:00
}
2019-12-06 05:31:32 +00:00
else
{
foreach ( $item -> { $key } as $row )
{
2022-05-16 04:25:03 +00:00
if ( ! $found && isset ( $row [ $target ]) && ( $row [ $target ] == $id || $this -> linkedGuid ( $guid , $row [ $target ])))
2019-12-06 05:31:32 +00:00
{
$found = true ;
}
2018-01-15 15:54:05 +00:00
}
}
}
}
2018-03-20 02:35:48 +00:00
// if string (fields)
2023-10-18 07:26:30 +00:00
if ( ! $found && 'xml' === $key && StringHelper :: check ( $item -> { $key })
2018-03-21 02:45:51 +00:00
&& strpos ( $item -> { $key }, $target . '="' ) !== false )
2018-03-20 02:35:48 +00:00
{
// now get the fields between
2023-10-18 07:26:30 +00:00
$_fields = GetHelper :: between ( $item -> { $key }, $target . '="' , '"' );
2018-03-20 02:35:48 +00:00
// check the result
2023-10-18 07:26:30 +00:00
if ( StringHelper :: check ( $_fields ))
2018-03-20 02:35:48 +00:00
{
// get the ids of all the fields linked here
$_fields = array_map ( 'trim' , ( array ) explode ( ',' , $_fields ));
// check the result
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $_fields ))
2018-03-20 02:35:48 +00:00
{
foreach ( $_fields as $_field )
{
2022-05-16 04:25:03 +00:00
if ( $_field == $id || $this -> linkedGuid ( $guid , $_field ))
2018-03-20 02:35:48 +00:00
{
$found = true ;
}
}
}
}
}
2017-12-17 09:07:51 +00:00
}
}
}
2018-01-15 15:54:05 +00:00
// check if found
if ( $found )
2017-12-03 18:09:04 +00:00
{
2018-01-15 15:54:05 +00:00
// build the name
$edit = true ;
2018-03-20 02:35:48 +00:00
if ( is_numeric ( $linked_name ) && isset ( $search [ 'linked_name' ]))
2018-01-15 15:54:05 +00:00
{
2018-03-20 02:35:48 +00:00
if ( ! $linked_name = ComponentbuilderHelper :: getVar ( $linked_nameTable , ( int ) $linked_name , 'id' , $search [ 'linked_name' ]))
2018-01-15 15:54:05 +00:00
{
2018-03-20 02:35:48 +00:00
$linked_name = JText :: _ ( 'COM_COMPONENTBUILDER_NO_FOUND' );
2018-01-15 15:54:05 +00:00
$edit = false ;
}
}
2018-03-20 02:35:48 +00:00
// build the local type
if ( is_numeric ( $type_name ) && isset ( $search [ 'type_name' ]))
{
if ( ! $type_name = ComponentbuilderHelper :: getVar ( $type_nameTable , ( int ) $type_name , 'id' , $search [ 'type_name' ]))
{
$type_name = '' ;
}
else
{
$type_name = ' (' . $type_name . ') ' ;
}
}
2023-10-18 07:26:30 +00:00
elseif ( StringHelper :: check ( $type_name ) || is_numeric ( $type_name ))
2018-03-20 02:35:48 +00:00
{
$type_name = ' (' . $type_name . ') ' ;
}
2018-01-15 15:54:05 +00:00
// set edit link
2018-08-18 12:09:17 +00:00
$link = ( $edit ) ? ComponentbuilderHelper :: getEditButton ( $item -> id , $search [ 'table' ], $search [ 'tables' ], $this -> ref ) : '' ;
2018-01-15 15:54:05 +00:00
// build the linked
2018-03-20 02:35:48 +00:00
$linked [] = JText :: _ ( $search [ 'linked' ]) . $type_name . ' - ' . $linked_name . ' ' . $link ;
2017-12-03 18:09:04 +00:00
}
}
}
}
2018-01-15 15:54:05 +00:00
// check if we found any
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $linked ))
2017-12-03 18:09:04 +00:00
{
2018-01-15 15:54:05 +00:00
return $linked ;
2017-12-03 18:09:04 +00:00
}
return false ;
2019-11-08 16:07:08 +00:00
}
2022-05-16 04:25:03 +00:00
/**
* Check if we have a GUID match
*
* @ param string | bool $guid The active power guid
* @ param string | array $setGuid The linked power guid
*
* @ return bool true if match is found
*
*/
protected function linkedGuid ( $guid , $setGuid ) : bool
{
// check if GUID is valid
if ( $guid && ComponentbuilderHelper :: validGUID ( $guid ))
{
if ( is_string ( $setGuid ) && ComponentbuilderHelper :: validGUID ( $setGuid ) && $guid === $setGuid )
{
return true ;
}
elseif ( is_array ( $setGuid ) && in_array ( $guid , $setGuid ))
{
return true ;
}
}
return false ;
}
2019-11-08 16:07:08 +00:00
2022-05-19 13:34:11 +00:00
/**
* The view persistence details
*
* @ var array
* @ since 3.0 . 13
*/
2019-11-08 16:07:08 +00:00
protected $viewid = array ();
2022-05-19 13:34:11 +00:00
/**
* Get the view details via the session
*
* @ input string $call The persistence key
*
* @ return mixed
* @ since 3.0 . 13
*/
2019-11-08 16:07:08 +00:00
protected function getViewID ( $call = 'table' )
{
if ( ! isset ( $this -> viewid [ $call ]))
{
// get the vdm key
$jinput = JFactory :: getApplication () -> input ;
$vdm = $jinput -> get ( 'vdm' , null , 'WORD' );
if ( $vdm )
{
// set view and id
if ( $view = ComponentbuilderHelper :: get ( $vdm ))
{
$current = ( array ) explode ( '__' , $view );
2023-10-18 07:26:30 +00:00
if ( StringHelper :: check ( $current [ 0 ]) && isset ( $current [ 1 ]) && is_numeric ( $current [ 1 ]))
2019-11-08 16:07:08 +00:00
{
// get the view name & id
$this -> viewid [ $call ] = array (
'a_id' => ( int ) $current [ 1 ],
'a_view' => $current [ 0 ]
);
}
}
2022-05-19 13:34:11 +00:00
// set GUID if found
2022-05-16 04:25:03 +00:00
if (( $guid = ComponentbuilderHelper :: get ( $vdm . '__guid' )) !== false && method_exists ( 'ComponentbuilderHelper' , 'validGUID' ))
{
if ( ComponentbuilderHelper :: validGUID ( $guid ))
{
$this -> viewid [ $call ][ 'a_guid' ] = $guid ;
}
}
2019-11-08 16:07:08 +00:00
// set return if found
if (( $return = ComponentbuilderHelper :: get ( $vdm . '__return' )) !== false )
{
2023-10-18 07:26:30 +00:00
if ( StringHelper :: check ( $return ))
2019-11-08 16:07:08 +00:00
{
$this -> viewid [ $call ][ 'a_return' ] = $return ;
}
}
}
}
if ( isset ( $this -> viewid [ $call ]))
{
return $this -> viewid [ $call ];
}
return false ;
}
public function getButton ( $type , $size )
{
if ( isset ( $this -> buttonArray [ $type ]))
{
$user = JFactory :: getUser ();
// only add if user allowed to create
if ( $user -> authorise ( $type . '.create' , 'com_componentbuilder' ))
{
// get the view name & id
$values = $this -> getViewID ();
// check if new item
$ref = '' ;
if ( ! is_null ( $values [ 'a_id' ]) && $values [ 'a_id' ] > 0 && strlen ( $values [ 'a_view' ]))
{
// check if we have a return value
$return_url = 'index.php?option=com_componentbuilder&view=' . ( string ) $values [ 'a_view' ] . '&layout=edit&id=' . ( int ) $values [ 'a_id' ];
if ( isset ( $values [ 'a_return' ]))
{
$return_url .= '&return=' . ( string ) $values [ 'a_return' ];
}
// only load referral if not new item.
$ref = '&ref=' . $values [ 'a_view' ] . '&refid=' . $values [ 'a_id' ] . '&return=' . urlencode ( base64_encode ( $return_url ));
}
// build url (A tag)
2023-10-18 07:26:30 +00:00
$startAtag = 'onclick="UIkit2.modal.confirm(\'' . JText :: _ ( 'COM_COMPONENTBUILDER_ALL_UNSAVED_WORK_ON_THIS_PAGE_WILL_BE_LOST_ARE_YOU_SURE_YOU_WANT_TO_CONTINUE' ) . '\', function(){ window.location.href = \'index.php?option=com_componentbuilder&view=' . $type . '&layout=edit' . $ref . '\' })" href="javascript:void(0)" title="' . JText :: sprintf ( 'COM_COMPONENTBUILDER_CREATE_NEW_S' , StringHelper :: safe ( $type , 'W' )) . '">' ;
2019-11-08 16:07:08 +00:00
// build the smallest button
if ( 3 == $size )
{
$button = '<a class="btn btn-small btn-success" style="margin: 0 0 5px 0;" ' . $startAtag . '<span class="icon-new icon-white"></span></a>' ;
}
// build the smaller button
elseif ( 2 == $size )
{
$button = '<a class="btn btn-success vdm-button-new" ' . $startAtag . '<span class="icon-new icon-white"></span> ' . JText :: _ ( 'COM_COMPONENTBUILDER_CREATE' ) . '</a>' ;
}
else
// build the big button
{
$button = ' < div class = " control-group " >
< div class = " control-label " >
< label > ' . ucwords($type) . ' </ label >
</ div >
< div class = " controls " >< a class = " btn btn-success vdm-button-new " ' . $startAtag . '
< span class = " icon-new icon-white " ></ span >
' . JText::_(' COM_COMPONENTBUILDER_NEW ') . '
</ a >
</ div >
</ div > ' ;
}
// return the button attached to input field
return $button ;
}
return '' ;
}
return false ;
}
public function getButtonID ( $type , $size )
{
if ( isset ( $this -> buttonArray [ $type ]))
{
$user = JFactory :: getUser ();
// only add if user allowed to create
if ( $user -> authorise ( $type . '.create' , 'com_componentbuilder' ))
{
// get the view name & id
$values = $this -> getViewID ();
// set the button ID
2023-10-18 07:26:30 +00:00
$css_class = 'control-group-' . StringHelper :: safe ( $type . '-' . $size , 'L' , '-' );
2019-11-08 16:07:08 +00:00
// check if new item
$ref = '' ;
if ( ! is_null ( $values [ 'a_id' ]) && $values [ 'a_id' ] > 0 && strlen ( $values [ 'a_view' ]))
{
// set the return value
$return_url = 'index.php?option=com_componentbuilder&view=' . ( string ) $values [ 'a_view' ] . '&layout=edit&id=' . ( int ) $values [ 'a_id' ];
if ( isset ( $values [ 'a_return' ]))
{
$return_url .= '&return=' . ( string ) $values [ 'a_return' ];
}
// only load referral if not new item.
$ref = '&ref=' . $values [ 'a_view' ] . '&refid=' . $values [ 'a_id' ] . '&return=' . urlencode ( base64_encode ( $return_url ));
// set the key get value
$key_get_value = $values [ 'a_id' ];
// check if we have a GUID
2022-05-16 04:27:50 +00:00
//if (isset($values['a_guid']))
//{
// $ref .= '&guid=' . (string) $values['a_guid'];
// $key_get_value = $values['a_guid'];
//}
2019-11-08 16:07:08 +00:00
// get item id
if (( $id = ComponentbuilderHelper :: getVar ( $type , $key_get_value , $values [ 'a_view' ], 'id' )) !== false && $id > 0 )
{
2023-10-18 07:26:30 +00:00
$buttonText = JText :: sprintf ( 'COM_COMPONENTBUILDER_EDIT_S_FOR_THIS_S' , StringHelper :: safe ( $type , 'w' ), StringHelper :: safe ( $values [ 'a_view' ], 'w' ));
2019-11-08 16:07:08 +00:00
$buttonTextSmall = JText :: _ ( 'COM_COMPONENTBUILDER_EDIT' );
$editThis = 'index.php?option=com_componentbuilder&view=' . $this -> buttonArray [ $type ] . '&task=' . $type . '.edit&id=' . $id ;
$icon = 'icon-apply' ;
}
else
{
2023-10-18 07:26:30 +00:00
$buttonText = JText :: sprintf ( 'COM_COMPONENTBUILDER_CREATE_S_FOR_THIS_S' , StringHelper :: safe ( $type , 'w' ), StringHelper :: safe ( $values [ 'a_view' ], 'w' ));
2019-11-08 16:07:08 +00:00
$buttonTextSmall = JText :: _ ( 'COM_COMPONENTBUILDER_CREATE' );
$editThis = 'index.php?option=com_componentbuilder&view=' . $type . '&layout=edit' ;
$icon = 'icon-new' ;
}
// build the button
$button = array ();
if ( 1 == $size )
{
$button [] = '<div class="control-group ' . $css_class . '">' ;
$button [] = '<div class="control-label">' ;
2023-10-18 07:26:30 +00:00
$button [] = '<label>' . StringHelper :: safe ( $type , 'Ww' ) . '</label>' ;
2019-11-08 16:07:08 +00:00
$button [] = '</div>' ;
$button [] = '<div class="controls">' ;
}
$button [] = '<a class="btn btn-success vdm-button-new" onclick="UIkit2.modal.confirm(\'' . JText :: _ ( 'COM_COMPONENTBUILDER_ALL_UNSAVED_WORK_ON_THIS_PAGE_WILL_BE_LOST_ARE_YOU_SURE_YOU_WANT_TO_CONTINUE' ) . '\', function(){ window.location.href = \'' . $editThis . $ref . '\' })" href="javascript:void(0)" title="' . $buttonText . '">' ;
if ( 1 == $size )
{
$button [] = '<span class="' . $icon . ' icon-white"></span>' ;
$button [] = $buttonText ;
$button [] = '</a>' ;
$button [] = '</div>' ;
$button [] = '</div>' ;
}
elseif ( 2 == $size )
{
$button [] = '<span class="' . $icon . ' icon-white"></span>' ;
$button [] = $buttonTextSmall ;
$button [] = '</a>' ;
}
// return the button attached to input field
return implode ( " \n " , $button );
}
// only return notice if big button
if ( 1 == $size )
{
2023-10-18 07:26:30 +00:00
return '<div class="control-group ' . $css_class . '"><div class="alert alert-info">' . JText :: sprintf ( 'COM_COMPONENTBUILDER_BUTTON_TO_CREATE_S_WILL_SHOW_ONCE_S_IS_SAVED_FOR_THE_FIRST_TIME' , StringHelper :: safe ( $type , 'w' ), StringHelper :: safe ( $values [ 'a_view' ], 'w' )) . '</div></div>' ;
2019-11-08 16:07:08 +00:00
}
}
}
return '' ;
}
protected function getSubformTable ( $idName , $data )
{
// make sure we convert the json to array
2023-10-18 07:26:30 +00:00
if ( JsonHelper :: check ( $data ))
2019-11-08 16:07:08 +00:00
{
$data = json_decode ( $data , true );
}
// make sure we have an array
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $data ) && StringHelper :: check ( $idName ))
2019-11-08 16:07:08 +00:00
{
// Build heading
$head = array ();
foreach ( $data as $headers )
{
foreach ( $headers as $header => $value )
{
if ( ! isset ( $head [ $header ]))
{
$head [ $header ] = $this -> getLanguage ( $idName . '|=VDM=|' . $header );
}
}
}
// build the rows
$rows = array ();
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $data ) && UtilitiesArrayHelper :: check ( $head ))
2019-11-08 16:07:08 +00:00
{
foreach ( $data as $nr => $values )
{
foreach ( $head as $key => $_header )
{
// set the value for the row
if ( isset ( $values [ $key ]))
{
$this -> setSubformRows ( $nr , $this -> setSubformValue ( $key , $values [ $key ]), $rows , $_header );
}
else
{
$this -> setSubformRows ( $nr , $this -> setSubformValue ( $key , '' ), $rows , $_header );
}
}
}
}
// build table
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $rows ) && UtilitiesArrayHelper :: check ( $head ))
2019-11-08 16:07:08 +00:00
{
// set the number of rows
$this -> rowNumber = count ( $rows );
// return the table
return ComponentbuilderHelper :: setSubformTable ( $head , $rows , $idName );
}
}
return false ;
}
protected function setSubformValue ( $header , $value )
{
if ( array_key_exists ( $header , $this -> functionArray ) && method_exists ( $this , $this -> functionArray [ $header ]))
{
$value = $this -> { $this -> functionArray [ $header ]}( $header , $value );
}
// if no value are set
2023-10-18 07:26:30 +00:00
if ( ! StringHelper :: check ( $value ))
2019-11-08 16:07:08 +00:00
{
$value = '-' ;
}
return $value ;
}
protected function setSubformRows ( $nr , $value , & $rows , $_header )
{
// build rows
if ( ! isset ( $rows [ $nr ]))
{
$rows [ $nr ] = '<td data-column=" ' . $_header . ' ">' . $value . '</td>' ;
}
else
{
$rows [ $nr ] .= '<td data-column=" ' . $_header . ' ">' . $value . '</td>' ;
}
}
public function getAjaxDisplay ( $type )
{
if ( isset ( $this -> fieldsArray [ $type ]))
{
// set type name
2023-10-18 07:26:30 +00:00
$typeName = StringHelper :: safe ( $type , 'w' );
2019-11-08 16:07:08 +00:00
// get the view name & id
$values = $this -> getViewID ();
// check if we are in the correct view.
if ( ! is_null ( $values [ 'a_id' ]) && $values [ 'a_id' ] > 0 && strlen ( $values [ 'a_view' ]) && in_array ( $values [ 'a_view' ], $this -> allowedViewsArray ))
{
// set a return value
$return_url = 'index.php?option=com_componentbuilder&view=' . ( string ) $values [ 'a_view' ] . '&layout=edit&id=' . ( int ) $values [ 'a_id' ];
// set a global return value
if ( isset ( $values [ 'a_return' ]))
{
$return_url .= '&return=' . ( string ) $values [ 'a_return' ];
}
// set the ref
$this -> ref = '&ref=' . $values [ 'a_view' ] . '&refid=' . $values [ 'a_id' ] . '&return=' . urlencode ( base64_encode ( $return_url ));
// set the key get value
$key_get_value = $values [ 'a_id' ];
// check if we have a GUID
2022-05-16 04:25:03 +00:00
//if (isset($values['a_guid']))
//{
//$this->ref .= '&guid=' . (string) $values['a_guid'];
//$key_get_value = $values['a_guid'];
//}
2019-11-08 16:07:08 +00:00
// load the results
$result = array ();
// return field table
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $this -> fieldsArray [ $type ]))
2019-11-08 16:07:08 +00:00
{
foreach ( $this -> fieldsArray [ $type ] as $fieldName )
{
if ( $table = $this -> getFieldTable ( $type , $key_get_value , $values [ 'a_view' ], $fieldName , $typeName ))
{
$result [] = $table ;
}
}
}
2023-10-18 07:26:30 +00:00
elseif ( StringHelper :: check ( $this -> fieldsArray [ $type ]))
2019-11-08 16:07:08 +00:00
{
if ( $table = $this -> getFieldTable ( $type , $key_get_value , $values [ 'a_view' ], $this -> fieldsArray [ $type ], $typeName ))
{
$result [] = $table ;
}
}
// check if we have results
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $result ) && count ( $result ) == 1 )
2019-11-08 16:07:08 +00:00
{
// return the display
return implode ( '' , $result );
}
2023-10-18 07:26:30 +00:00
elseif ( UtilitiesArrayHelper :: check ( $result ))
2019-11-08 16:07:08 +00:00
{
// return the display
return '<div>' . implode ( '</div><div>' , $result ) . '</div>' ;
}
}
return '<div class="control-group"><div class="alert alert-info">' . JText :: sprintf ( 'COM_COMPONENTBUILDER_NO_S_HAVE_BEEN_LINKED_TO_THIS_VIEW_SOON_AS_THIS_IS_DONE_IT_WILL_BE_DISPLAYED_HERE' , $typeName ) . '</div></div>' ;
}
return '<div class="control-group"><div class="alert alert-error"><h4>' . JText :: _ ( 'COM_COMPONENTBUILDER_TYPE_ERROR' ) . '</h4><p>' . JText :: _ ( 'COM_COMPONENTBUILDER_THERE_HAS_BEEN_AN_ERROR_IF_THIS_CONTINUES_PLEASE_INFORM_YOUR_SYSTEM_ADMINISTRATOR_OF_A_TYPE_ERROR_IN_THE_FIELDS_DISPLAY_REQUEST' ) . '</p></div></div>' ;
}
protected function setItemNames ( $header , $value )
{
if ( isset ( $this -> itemKeys [ $header ]) && isset ( $this -> itemKeys [ $header ][ 'table' ]) && isset ( $this -> itemNames [ $this -> itemKeys [ $header ][ 'table' ]]))
{
// check if we have GUID setup
$validGUID = function ( $guid ) {
if ( method_exists ( 'ComponentbuilderHelper' , 'validGUID' ) && ComponentbuilderHelper :: validGUID ( $guid ))
{
return true ;
}
return false ;
};
2019-11-09 01:53:24 +00:00
// check if functions exists
$guidEdit = method_exists ( 'ComponentbuilderHelper' , 'getEditButtonGUID' );
$getEdit = method_exists ( 'ComponentbuilderHelper' , 'getEditButton' );
2019-11-08 16:07:08 +00:00
// reset bucket
$bucket = array ();
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $value ))
2019-11-08 16:07:08 +00:00
{
foreach ( $value as $item )
{
$edit = true ;
if ( ! isset ( $this -> itemNames [ $this -> itemKeys [ $header ][ 'table' ]][ $item ]))
{
if (( $this -> itemNames [ $this -> itemKeys [ $header ][ 'table' ]][ $item ] = ComponentbuilderHelper :: getVar ( $this -> itemKeys [ $header ][ 'table' ], $item , $this -> itemKeys [ $header ][ 'id' ], $this -> itemKeys [ $header ][ 'name' ])) === false )
{
$this -> itemNames [ $this -> itemKeys [ $header ][ 'table' ]][ $item ] = JText :: sprintf ( 'COM_COMPONENTBUILDER_NO_S_FOUND' , $this -> itemKeys [ $header ][ 'text' ]);
$edit = false ;
}
2019-11-09 01:53:24 +00:00
// check if we should load some get
2023-10-18 07:26:30 +00:00
if ( $edit && isset ( $this -> itemKeys [ $header ][ 'get' ]) && StringHelper :: check ( $this -> itemKeys [ $header ][ 'get' ]) && method_exists ( __CLASS__ , $this -> itemKeys [ $header ][ 'get' ]))
2019-11-08 16:07:08 +00:00
{
2019-11-09 01:53:24 +00:00
// gets
$this -> itemNames [ $this -> itemKeys [ $header ][ 'table' ]][ $item ] .= $this -> { $this -> itemKeys [ $header ][ 'get' ]}( $item );
2019-11-08 16:07:08 +00:00
}
}
// check if we are working with GUID
2019-11-09 01:53:24 +00:00
if ( $validGUID ( $item ))
2019-11-08 16:07:08 +00:00
{
// set edit link
2019-11-09 01:53:24 +00:00
$link = ( $edit && $guidEdit ) ? ComponentbuilderHelper :: getEditButtonGUID ( $item , $this -> itemKeys [ $header ][ 'id' ], $this -> itemKeys [ $header ][ 'table' ], $this -> itemKeys [ $header ][ 'tables' ], $this -> ref ) : '' ;
2019-11-08 16:07:08 +00:00
}
else
{
// set edit link
2019-11-09 01:53:24 +00:00
$link = ( $edit && $getEdit ) ? ComponentbuilderHelper :: getEditButton ( $item , $this -> itemKeys [ $header ][ 'table' ], $this -> itemKeys [ $header ][ 'tables' ], $this -> ref ) : '' ;
2019-11-08 16:07:08 +00:00
}
// load item
$bucket [] = $this -> itemNames [ $this -> itemKeys [ $header ][ 'table' ]][ $item ] . $link ;
}
}
elseif ( is_numeric ( $value ) || $validGUID ( $value ))
{
$edit = true ;
if ( ! isset ( $this -> itemNames [ $this -> itemKeys [ $header ][ 'table' ]][ $value ]))
{
if (( $this -> itemNames [ $this -> itemKeys [ $header ][ 'table' ]][ $value ] = ComponentbuilderHelper :: getVar ( $this -> itemKeys [ $header ][ 'table' ], $value , $this -> itemKeys [ $header ][ 'id' ], $this -> itemKeys [ $header ][ 'name' ])) === false )
{
$this -> itemNames [ $this -> itemKeys [ $header ][ 'table' ]][ $value ] = JText :: sprintf ( 'COM_COMPONENTBUILDER_NO_S_FOUND' , $this -> itemKeys [ $header ][ 'text' ]);
$edit = false ;
}
2019-11-09 01:53:24 +00:00
// check if we should load some get
2023-10-18 07:26:30 +00:00
if ( $edit && isset ( $this -> itemKeys [ $header ][ 'get' ]) && StringHelper :: check ( $this -> itemKeys [ $header ][ 'get' ]) && method_exists ( __CLASS__ , $this -> itemKeys [ $header ][ 'get' ]))
2019-11-08 16:07:08 +00:00
{
2019-11-09 01:53:24 +00:00
// gets
$this -> itemNames [ $this -> itemKeys [ $header ][ 'table' ]][ $value ] .= $this -> { $this -> itemKeys [ $header ][ 'get' ]}( $value );
2019-11-08 16:07:08 +00:00
}
}
// check if we are working with GUID
2019-11-09 01:53:24 +00:00
if ( $validGUID ( $value ))
2019-11-08 16:07:08 +00:00
{
// set edit link
2019-11-09 01:53:24 +00:00
$link = ( $edit && $guidEdit ) ? ComponentbuilderHelper :: getEditButtonGUID ( $value , $this -> itemKeys [ $header ][ 'id' ], $this -> itemKeys [ $header ][ 'table' ], $this -> itemKeys [ $header ][ 'tables' ], $this -> ref ) : '' ;
2019-11-08 16:07:08 +00:00
}
else
{
// set edit link
2019-11-09 01:53:24 +00:00
$link = ( $edit && $getEdit ) ? ComponentbuilderHelper :: getEditButton ( $value , $this -> itemKeys [ $header ][ 'table' ], $this -> itemKeys [ $header ][ 'tables' ], $this -> ref ) : '' ;
2019-11-08 16:07:08 +00:00
}
// load item
$bucket [] = $this -> itemNames [ $this -> itemKeys [ $header ][ 'table' ]][ $value ] . $link ;
}
// return found items
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $bucket ))
2019-11-08 16:07:08 +00:00
{
return implode ( '<br />' , $bucket );
}
return JText :: sprintf ( 'COM_COMPONENTBUILDER_NO_S_FOUND' , $this -> itemKeys [ $header ][ 'text' ]);
}
return JText :: _ ( 'COM_COMPONENTBUILDER_NO_ITEM_FOUND' );
}
protected function getFieldTable ( $type , $id , $idName , $fieldName , $typeName )
{
// get the field data
if (( $fieldsData = ComponentbuilderHelper :: getVar ( $type , $id , $idName , $fieldName )) !== false )
{
// check repeatable conversion
if ( method_exists ( __CLASS__ , 'checkRepeatableConversion' ))
{
2021-08-11 12:15:35 +00:00
$this -> checkRepeatableConversion ( $type , $fieldsData , $fieldName , $id , $idName );
2019-11-08 16:07:08 +00:00
}
// get the table
$table = $this -> getSubformTable ( $type , $fieldsData );
// get row number
$number = ( isset ( $this -> rowNumbers ) && isset ( $this -> rowNumbers [ $type ]) && $this -> rowNumbers [ $type ]) ? $this -> rowNumbers [ $type ] : false ;
// set notice of bad practice
$notice = '' ;
if ( $number && isset ( $this -> rowNumber ) && $this -> rowNumber > $number )
{
$notice = '<div class="alert alert-warning">' . JText :: sprintf ( 'COM_COMPONENTBUILDER_YOU_HAVE_S_S_ADDING_MORE_THEN_S_S_IS_CONSIDERED_BAD_PRACTICE_YOUR_S_PAGE_LOAD_IN_JCB_WILL_SLOWDOWN_YOU_SHOULD_CONSIDER_DECOUPLING_SOME_OF_THESE_S' , $this -> rowNumber , $typeName , $number , $typeName , $typeName , $typeName ) . '</div>' ;
}
elseif ( $number && isset ( $this -> rowNumber ))
{
$notice = '<div class="alert alert-info">' . JText :: sprintf ( 'COM_COMPONENTBUILDER_YOU_HAVE_S_S_ADDING_MORE_THEN_S_S_IS_CONSIDERED_BAD_PRACTICE' , $this -> rowNumber , $typeName , $number , $typeName ) . '</div>' ;
}
// return table
return $notice . $table ;
}
return false ;
}
2017-11-26 00:29:08 +00:00
2016-01-30 20:28:43 +00:00
// Used in template
public function getTemplateDetails ( $id )
{
2018-03-27 09:57:16 +00:00
// set table
$table = false ;
2016-01-30 20:28:43 +00:00
// Get a db connection.
2018-04-19 15:52:47 +00:00
$db = JFactory :: getDbo ();
2016-01-30 20:28:43 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
2022-02-05 21:24:51 +00:00
$query -> select ( $db -> quoteName ( array ( 'a.id' , 'a.alias' , 'a.template' , 'b.name' , 'a.dynamic_get' )));
2016-01-30 20:28:43 +00:00
$query -> from ( $db -> quoteName ( '#__componentbuilder_template' , 'a' ));
$query -> join ( 'LEFT' , $db -> quoteName ( '#__componentbuilder_dynamic_get' , 'b' ) . ' ON (' . $db -> quoteName ( 'b.id' ) . ' = ' . $db -> quoteName ( 'a.dynamic_get' ) . ')' );
2022-02-05 21:24:51 +00:00
$query -> where ( $db -> quoteName ( 'a.id' ) . ' != ' . ( int ) $id );
2018-04-19 15:52:47 +00:00
$query -> where ( $db -> quoteName ( 'a.published' ) . ' = 1' );
2016-01-30 20:28:43 +00:00
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
{
$results = $db -> loadObjectList ();
2018-03-27 09:57:16 +00:00
$templateString = array ();
2018-04-19 15:52:47 +00:00
// get the view name & id
$values = $this -> getViewID ();
2018-08-23 01:37:42 +00:00
// set a return value
$return_url = 'index.php?option=com_componentbuilder&view=' . ( string ) $values [ 'a_view' ] . '&layout=edit&id=' . ( int ) $values [ 'a_id' ];
if ( isset ( $values [ 'a_return' ]))
{
$return_url .= '&return=' . ( string ) $values [ 'a_return' ];
}
// start the ref builder
$ref = '' ;
2018-04-19 15:52:47 +00:00
if ( ! is_null ( $values [ 'a_id' ]) && $values [ 'a_id' ] > 0 && strlen ( $values [ 'a_view' ]))
{
// set the return ref
2018-08-23 01:37:42 +00:00
$ref = '&ref=' . $values [ 'a_view' ] . '&refid=' . $values [ 'a_id' ] . '&return=' . urlencode ( base64_encode ( $return_url ));
2018-04-19 15:52:47 +00:00
}
2018-08-23 01:37:42 +00:00
// load the template data
2016-01-30 20:28:43 +00:00
foreach ( $results as $result )
{
2018-08-23 01:37:42 +00:00
$edit = (( $button = ComponentbuilderHelper :: getEditButton ( $result -> id , 'template' , 'templates' , $ref )) !== false ) ? $button : '' ;
$editget = ( isset ( $result -> dynamic_get ) && $result -> dynamic_get > 0 && ( $button = ComponentbuilderHelper :: getEditButton ( $result -> dynamic_get , 'dynamic_get' , 'dynamic_gets' , $ref )) !== false ) ? $button : '' ;
2023-10-18 07:26:30 +00:00
$result -> name = ( StringHelper :: check ( $result -> name )) ? $result -> name : JText :: _ ( 'COM_COMPONENTBUILDER_NONE_SELECTED' );
$templateString [] = " <td><b> " . $result -> name . " </b> " . $editget . " </td><td><code><?php echo \$ this->loadTemplate(' " . StringHelper :: safe ( $result -> alias ) . " '); ?></code> " . $edit . " </td> " ;
2016-01-30 20:28:43 +00:00
}
2018-03-27 09:57:16 +00:00
// build the table
2022-02-05 21:24:51 +00:00
$table = '<h2>' . JText :: _ ( 'COM_COMPONENTBUILDER_TEMPLATE_CODE_SNIPPETS' ) . '</h2><div class="uk-scrollable-box"><table class="uk-table uk-table-hover uk-table-striped uk-table-condensed">' ;
$table .= '<caption>' . JText :: _ ( 'COM_COMPONENTBUILDER_TO_ADD_SIMPLY_COPY_AND_PAST_THE_SNIPPET_INTO_YOUR_CODE' ) . '</caption>' ;
$table .= '<thead><tr><th>' . JText :: _ ( 'COM_COMPONENTBUILDER_NAME_OF_DYNAMICGET' ) . '</th><th>' . JText :: _ ( 'COM_COMPONENTBUILDER_SNIPPET' ) . '</th></thead>' ;
$table .= '<tbody><tr>' . implode ( " </tr><tr> " , $templateString ) . " </tr></tbody></table></div> " ;
2016-01-30 20:28:43 +00:00
}
2018-03-27 09:57:16 +00:00
return $table ;
2016-01-30 20:28:43 +00:00
}
// Used in layout
2017-10-06 14:53:22 +00:00
public function getLayoutDetails ( $id )
2016-01-30 20:28:43 +00:00
{
2018-03-27 09:57:16 +00:00
// set table
$table = false ;
2016-01-30 20:28:43 +00:00
// Get a db connection.
2018-04-19 15:52:47 +00:00
$db = JFactory :: getDbo ();
2016-01-30 20:28:43 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
2018-04-19 15:52:47 +00:00
$query -> select ( $db -> quoteName ( array ( 'a.id' , 'a.alias' , 'a.layout' , 'b.getcustom' , 'b.gettype' , 'b.name' , 'a.dynamic_get' )));
2017-10-06 14:53:22 +00:00
$query -> from ( $db -> quoteName ( '#__componentbuilder_layout' , 'a' ));
$query -> join ( 'LEFT' , $db -> quoteName ( '#__componentbuilder_dynamic_get' , 'b' ) . ' ON (' . $db -> quoteName ( 'b.id' ) . ' = ' . $db -> quoteName ( 'a.dynamic_get' ) . ')' );
$query -> where ( $db -> quoteName ( 'a.id' ) . ' != ' . ( int ) $id );
2018-04-19 15:52:47 +00:00
$query -> where ( $db -> quoteName ( 'a.published' ) . ' = 1' );
2017-10-06 14:53:22 +00:00
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
{
$results = $db -> loadObjectList ();
2018-03-27 09:57:16 +00:00
$layoutString = array ();
2018-04-19 15:52:47 +00:00
// get the view name & id
$values = $this -> getViewID ();
2018-08-23 01:37:42 +00:00
// set a return value
$return_url = 'index.php?option=com_componentbuilder&view=' . ( string ) $values [ 'a_view' ] . '&layout=edit&id=' . ( int ) $values [ 'a_id' ];
if ( isset ( $values [ 'a_return' ]))
{
$return_url .= '&return=' . ( string ) $values [ 'a_return' ];
}
// start the ref builder
$ref = '' ;
2018-04-19 15:52:47 +00:00
if ( ! is_null ( $values [ 'a_id' ]) && $values [ 'a_id' ] > 0 && strlen ( $values [ 'a_view' ]))
{
// set the return ref
2018-08-23 01:37:42 +00:00
$ref = '&ref=' . $values [ 'a_view' ] . '&refid=' . $values [ 'a_id' ] . '&return=' . urlencode ( base64_encode ( $return_url ));
2018-04-19 15:52:47 +00:00
}
2017-10-06 14:53:22 +00:00
foreach ( $results as $result )
{
2018-08-23 01:37:42 +00:00
$edit = (( $button = ComponentbuilderHelper :: getEditButton ( $result -> id , 'layout' , 'layouts' , $ref )) !== false ) ? $button : '' ;
$editget = ( isset ( $result -> dynamic_get ) && $result -> dynamic_get > 0 && ( $button = ComponentbuilderHelper :: getEditButton ( $result -> dynamic_get , 'dynamic_get' , 'dynamic_gets' , $ref )) !== false ) ? $button : '' ;
2023-10-18 07:26:30 +00:00
$result -> name = ( StringHelper :: check ( $result -> name )) ? $result -> name : JText :: _ ( 'COM_COMPONENTBUILDER_NONE_SELECTED' );
2018-04-19 15:52:47 +00:00
2017-10-06 14:53:22 +00:00
switch ( $result -> gettype )
{
case 1 :
2022-02-05 21:24:51 +00:00
// single
2023-10-18 07:26:30 +00:00
$layoutString [] = " <td><b> " . $result -> name . " </b> " . $editget . " </td><td><code><?php echo JLayoutHelper::render(' " . StringHelper :: safe ( $result -> alias ) . " ', \$ this->item); ?></code> " . $edit . " </td> " ;
2017-10-06 14:53:22 +00:00
break ;
case 2 :
2022-02-05 21:24:51 +00:00
// list
2023-10-18 07:26:30 +00:00
$layoutString [] = " <td><b> " . $result -> name . " </b> " . $editget . " </td><td><code><?php echo JLayoutHelper::render(' " . StringHelper :: safe ( $result -> alias ) . " ', \$ this->items); ?></code> " . $edit . " </td> " ;
2017-10-06 14:53:22 +00:00
break ;
case 3 :
case 4 :
2022-02-05 21:24:51 +00:00
// custom
2023-10-18 07:26:30 +00:00
$result -> getcustom = StringHelper :: safe ( $result -> getcustom );
2022-02-05 21:24:51 +00:00
if ( substr ( $result -> getcustom , 0 , strlen ( 'get' )) == 'get' )
{
$varName = substr ( $result -> getcustom , strlen ( 'get' ));
}
else
{
$varName = $result -> getcustom ;
}
2023-10-18 07:26:30 +00:00
$layoutString [] = " <td><b> " . $result -> name . " </b> " . $editget . " </td><td><code><?php echo JLayoutHelper::render(' " . StringHelper :: safe ( $result -> alias ) . " ', \$ this-> " . $varName . " ); ?></code> " . $edit . " </td> " ;
2022-02-05 21:24:51 +00:00
break ;
default :
// no get
2023-10-18 07:26:30 +00:00
$layoutString [] = " <td> " . JText :: _ ( 'COM_COMPONENTBUILDER_NONE_SELECTED' ) . " </td><td><code><?php echo JLayoutHelper::render(' " . StringHelper :: safe ( $result -> alias ) . " ', [?]); ?></code> " . $edit . " </td> " ;
2017-10-06 14:53:22 +00:00
break ;
}
}
2018-03-27 09:57:16 +00:00
// build the table
2022-02-05 21:24:51 +00:00
$table = '<h2>' . JText :: _ ( 'COM_COMPONENTBUILDER_LAYOUT_CODE_SNIPPETS' ) . '</h2><div class="uk-scrollable-box"><table class="uk-table uk-table-hover uk-table-striped uk-table-condensed">' ;
$table .= '<caption>' . JText :: _ ( 'COM_COMPONENTBUILDER_TO_ADD_SIMPLY_COPY_AND_PAST_THE_SNIPPET_INTO_YOUR_CODE' ) . '</caption>' ;
$table .= '<thead><tr><th>' . JText :: _ ( 'COM_COMPONENTBUILDER_NAME_OF_DYNAMICGET' ) . '</th><th>' . JText :: _ ( 'COM_COMPONENTBUILDER_SNIPPET' ) . '</th></thead>' ;
$table .= '<tbody><tr>' . implode ( " </tr><tr> " , $layoutString ) . " </tr></tbody></table></div> " ;
2017-10-06 14:53:22 +00:00
}
2018-03-27 09:57:16 +00:00
return $table ;
2017-10-06 14:53:22 +00:00
}
// Used in dynamic_get
2017-10-12 23:39:04 +00:00
public function getViewTableColumns ( $admin_view , $as , $type )
2017-10-06 14:53:22 +00:00
{
2019-01-29 14:43:27 +00:00
return ComponentbuilderHelper :: getViewTableColumns ( $admin_view , $as , $type );
2016-01-30 20:28:43 +00:00
}
2017-10-06 14:53:22 +00:00
public function getDbTableColumns ( $tableName , $as , $type )
{
2019-01-29 14:43:27 +00:00
return ComponentbuilderHelper :: getDbTableColumns ( $tableName , $as , $type );
2017-10-06 14:53:22 +00:00
}
public function getDynamicValues ( $id , $view )
2016-01-30 20:28:43 +00:00
{
// Get a db connection.
$db = JFactory :: getDbo ();
2019-01-29 14:43:27 +00:00
2016-01-30 20:28:43 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
2019-01-29 14:43:27 +00:00
$query -> select ( $db -> quoteName ( array ( 'getcustom' , 'gettype' , 'select_all' , 'db_table_main' , 'view_table_main' , 'main_source' , 'view_selection' , 'db_selection' , 'join_view_table' , 'join_db_table' , 'addcalculation' , 'php_calculation' )));
2016-01-30 20:28:43 +00:00
$query -> from ( $db -> quoteName ( '#__componentbuilder_dynamic_get' ));
$query -> where ( $db -> quoteName ( 'published' ) . ' = 1' );
2019-01-29 14:43:27 +00:00
$query -> where ( $db -> quoteName ( 'id' ) . ' = ' . ( int ) $id );
2016-01-30 20:28:43 +00:00
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
{
$result = $db -> loadObject ();
// reset buket
$selections = array ();
$selectionsList = array ();
// get the main values (name)
if ( $result -> main_source == 1 )
{
2019-01-29 14:43:27 +00:00
if ( $result -> select_all == 1 )
{
$result -> view_selection = ComponentbuilderHelper :: getViewTableColumns ( $result -> view_table_main , 'a' , $result -> gettype );
}
$selections [] = explode ( " \n " , $result -> view_selection );
2016-01-30 20:28:43 +00:00
}
elseif ( $result -> main_source == 2 )
{
2019-01-29 14:43:27 +00:00
if ( $result -> select_all == 1 )
{
$result -> db_selection = ComponentbuilderHelper :: getDbTableColumns ( $result -> db_table_main , 'a' , $result -> gettype );
}
$selections [] = explode ( " \n " , $result -> db_selection );
2016-01-30 20:28:43 +00:00
}
elseif ( $result -> main_source == 3 )
{
return '<br /><br /><h2>Custom get source! You will need to transpose the variables manually.</h2>' ;
}
// get the joined values (name)
2017-10-06 14:53:22 +00:00
$result -> join_view_table = json_decode ( $result -> join_view_table , true );
2023-10-18 07:26:30 +00:00
if ( ! UtilitiesArrayHelper :: check ( $result -> join_view_table ))
2016-01-30 20:28:43 +00:00
{
2017-10-06 14:53:22 +00:00
unset ( $result -> join_view_table );
2016-01-30 20:28:43 +00:00
}
2017-10-06 14:53:22 +00:00
$result -> join_db_table = json_decode ( $result -> join_db_table , true );
2023-10-18 07:26:30 +00:00
if ( ! UtilitiesArrayHelper :: check ( $result -> join_db_table ))
2016-01-30 20:28:43 +00:00
{
2017-10-06 14:53:22 +00:00
unset ( $result -> join_db_table );
2016-01-30 20:28:43 +00:00
}
// now load the joined values to the selection set
2023-10-18 07:26:30 +00:00
if ( isset ( $result -> join_view_table ) && UtilitiesArrayHelper :: check ( $result -> join_view_table ))
2016-01-30 20:28:43 +00:00
{
foreach ( $result -> join_view_table as $join_view_table )
{
2019-01-29 14:43:27 +00:00
// check if all is selected
if ( strpos ( $join_view_table [ 'selection' ], '*' ) !== false )
{
$join_view_table [ 'selection' ] = ComponentbuilderHelper :: getViewTableColumns ( $join_view_table [ 'view_table' ], $join_view_table [ 'as' ], $join_view_table [ 'row_type' ]);
}
// build selection
2016-01-30 20:28:43 +00:00
if ( $join_view_table [ 'row_type' ] == '1' )
{
2019-01-29 14:43:27 +00:00
$selections [] = explode ( " \n " , $join_view_table [ 'selection' ]);
2016-01-30 20:28:43 +00:00
}
elseif ( $join_view_table [ 'row_type' ] == '2' )
{
$names = $this -> setListMethodName ( array ( $join_view_table [ 'on_field' ], $join_view_table [ 'join_field' ]), $join_view_table [ 'view_table' ], $join_view_table [ 'as' ], 1 );
2019-01-29 14:43:27 +00:00
$selectionsList [ implode ( '' , $names )] = explode ( " \n " , $join_view_table [ 'selection' ]);
2016-01-30 20:28:43 +00:00
}
}
unset ( $result -> join_view_table );
}
2023-10-18 07:26:30 +00:00
if ( isset ( $result -> join_db_table ) && UtilitiesArrayHelper :: check ( $result -> join_db_table ))
2016-01-30 20:28:43 +00:00
{
foreach ( $result -> join_db_table as $join_db_table )
{
2019-01-29 14:43:27 +00:00
// check if all is selected
if ( strpos ( $join_db_table [ 'selection' ], '*' ) !== false )
{
$join_db_table [ 'selection' ] = ComponentbuilderHelper :: getViewTableColumns ( $join_db_table [ 'view_table' ], $join_db_table [ 'as' ], $join_db_table [ 'row_type' ]);
}
// build selections
2016-01-30 20:28:43 +00:00
if ( $join_db_table [ 'row_type' ] == '1' )
{
2019-01-29 14:43:27 +00:00
$selections [] = explode ( " \n " , $join_db_table [ 'selection' ]);
2016-01-30 20:28:43 +00:00
}
elseif ( $join_db_table [ 'row_type' ] == '2' )
{
$names = $this -> setListMethodName ( array ( $join_db_table [ 'on_field' ], $join_db_table [ 'join_field' ]), $join_db_table [ 'db_table' ], $join_db_table [ 'as' ], 2 );
2019-01-29 14:43:27 +00:00
$selectionsList [ implode ( '' , $names )] = explode ( " \n " , $join_db_table [ 'selection' ]);
2016-01-30 20:28:43 +00:00
}
}
unset ( $result -> join_db_table );
}
2017-10-06 14:53:22 +00:00
// get the calculation result values (name)
2016-01-30 20:28:43 +00:00
if ( $result -> addcalculation == 1 )
{
$php_calculation = base64_decode ( $result -> php_calculation );
2023-10-18 07:26:30 +00:00
$phpSelections = GetHelper :: allBetween ( $php_calculation , 'cal__' , ' ' );
2016-01-30 20:28:43 +00:00
$selections [] = array_unique ( $phpSelections );
unset ( $php_calculation );
unset ( $phpSelections );
unset ( $result -> php_calculation );
}
// name the main var based on view
2017-11-01 03:16:21 +00:00
if ( 'template' === $view || 'site_view' === $view || 'custom_admin_view' === $view )
2016-01-30 20:28:43 +00:00
{
switch ( $result -> gettype )
{
case 1 :
// single
$buketName = 'this->item' ;
break ;
case 2 :
// list
$buketName = 'this->items' ;
break ;
case 3 :
case 4 :
// custom
2023-10-18 07:26:30 +00:00
$result -> getcustom = StringHelper :: safe ( $result -> getcustom );
2016-01-30 20:28:43 +00:00
if ( substr ( $result -> getcustom , 0 , strlen ( 'get' )) == 'get' )
{
$varName = substr ( $result -> getcustom , strlen ( 'get' ));
}
else
{
$varName = $result -> getcustom ;
}
$buketName = 'this->' . $varName ;
break ;
}
}
elseif ( $view == 'layout' )
{
$buketName = 'displayData' ;
}
// now build the return values
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $selections ))
2016-01-30 20:28:43 +00:00
{
$buket = array ();
switch ( $result -> gettype )
{
case 1 :
case 3 :
// single
$ur = '<?php echo $' . $buketName ;
$cf = '; ?>' ;
break ;
case 2 :
case 4 :
// list
$ur = '<?php echo $item' ;
$cf = '; ?>' ;
$buket [] = '<code><?php foreach ($' . $buketName . ' as $item): ?></code><br />' ;
break ;
}
foreach ( $selections as $selection )
{
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $selection ))
2016-01-30 20:28:43 +00:00
{
foreach ( $selection as $value )
{
if ( strpos ( $value , 'AS' ) !== false )
{
list ( $table , $key ) = explode ( 'AS' , $value );
$buket [] = '<code>' . $ur . '->' . trim ( $key ) . $cf . '</code>' ;
}
else
{
$buket [] = '<code>' . $ur . '->' . trim ( $value ) . $cf . '</code>' ;
}
}
}
}
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $selectionsList ))
2016-01-30 20:28:43 +00:00
{
$buket [] = '<hr />' ;
foreach ( $selectionsList as $name => $selectionList )
{
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $selectionList ))
2016-01-30 20:28:43 +00:00
{
$ur = '<?php echo $' . $name ;
$cf = '; ?>' ;
$buket [] = '<code><?php foreach ($item->' . $name . ' as $' . $name . '): ?></code><br />' ;
foreach ( $selectionList as $value )
{
if ( strpos ( $value , 'AS' ) !== false )
{
list ( $table , $key ) = explode ( 'AS' , $value );
$buket [] = '<code>' . $ur . '->' . trim ( $key ) . $cf . '</code>' ;
}
else
{
$buket [] = '<code>' . $ur . '->' . trim ( $value ) . $cf . '</code>' ;
}
}
$buket [] = '<br /><code><?php endforeach; ?></code><hr />' ;
}
}
}
switch ( $result -> gettype )
{
case 2 :
case 4 :
// list
$buket [] = '<br /><code><?php endforeach; ?></code>' ;
break ;
}
return implode ( ' ' , $buket );
}
}
return false ;
}
2019-01-29 14:43:27 +00:00
2017-10-12 23:39:04 +00:00
protected function setListMethodName ( $names , $table , $as , $type )
2016-01-30 20:28:43 +00:00
{
$methodNames = array ();
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $names ))
2016-01-30 20:28:43 +00:00
{
foreach ( $names as $nr => $name )
{
2023-10-18 07:26:30 +00:00
if ( StringHelper :: check ( $name ))
2016-01-30 20:28:43 +00:00
{
if ( strpos ( $name , '.' ) !== false )
{
list ( $dump , $var ) = explode ( '.' , $name );
}
else
{
$var = $name ;
}
if ( $nr > 0 )
{
2023-10-18 07:26:30 +00:00
$methodNames [] = StringHelper :: safe ( $var , 'F' );
2016-01-30 20:28:43 +00:00
}
else
{
2023-10-18 07:26:30 +00:00
$methodNames [] = StringHelper :: safe ( $var );
2016-01-30 20:28:43 +00:00
}
}
}
}
switch ( $type )
{
// set view name
case 1 :
2023-10-18 07:26:30 +00:00
$methodNames [] = StringHelper :: safe ( $this -> getViewName ( $table ), 'F' );
2016-01-30 20:28:43 +00:00
break ;
// set db name
case 2 :
2023-10-18 07:26:30 +00:00
$methodNames [] = StringHelper :: safe ( $table , 'F' );
2016-01-30 20:28:43 +00:00
break ;
}
// make sure there is uniqe method names
2023-10-18 07:26:30 +00:00
$methodNames [] = StringHelper :: safe ( $as , 'U' );
2016-01-30 20:28:43 +00:00
return $methodNames ;
}
2019-01-29 14:43:27 +00:00
2016-01-30 20:28:43 +00:00
protected function getViewName ( $id )
{
2017-10-12 23:39:04 +00:00
// Get the view name
if ( $name = ComponentbuilderHelper :: getVar ( 'admin_view' , ( int ) $id , 'id' , 'name_single' ))
2016-01-30 20:28:43 +00:00
{
2017-10-12 23:39:04 +00:00
return $name ;
2016-01-30 20:28:43 +00:00
}
return '' ;
}
2017-02-13 23:24:38 +00:00
// Used in custom_code
2019-01-31 21:44:21 +00:00
public function getEditCustomCodeButtons ( $id )
{
$view = $this -> getViewID ();
// only continue if this is a legitimate call
if ( isset ( $view [ 'a_id' ]) && $view [ 'a_id' ] == $id && isset ( $view [ 'a_view' ]) && ( $target = $this -> getCodeSearchKeys ( $view [ 'a_view' ], 'query_' )) !== false )
{
2019-05-15 22:50:45 +00:00
// reset the buttons bucket
$buttons = array ();
2021-08-11 12:15:35 +00:00
// some helper for some fields (I am sorry)
$helper = array ( 'xml' => 'note_filter_information' );
2019-05-15 22:50:45 +00:00
// get input
$jinput = JFactory :: getApplication () -> input ;
$return_here = $jinput -> get ( 'return_here' , null , 'base64' );
// set the return here value if not found
2023-10-18 07:26:30 +00:00
if ( StringHelper :: check ( $return_here ))
2019-05-15 22:50:45 +00:00
{
$return_here = '&return=' . $return_here ;
}
else
{
$return_here = '&ref=' . $view [ 'a_view' ] . '&refid=' . ( int ) $id ;
}
// start db query
2019-01-31 21:44:21 +00:00
$db = JFactory :: getDbo ();
$query = $db -> getQuery ( true )
-> select ( $db -> quoteName ( $target [ 'select' ]))
-> from ( $db -> quoteName ( '#__componentbuilder_' . $target [ 'table' ], 'a' ))
-> where ( 'a.id = ' . ( int ) $id );
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> loadRowList ())
{
$data = $db -> loadAssoc ();
// reset the bucket
$bucket = array ();
foreach ( $data as $key => $value )
{
if ( 'id' !== $key && $target [ 'name' ] !== $key )
{
if ( ! isset ( $target [ 'not_base64' ][ $key ]))
{
2023-10-18 07:26:30 +00:00
$value = Base64Helper :: open ( $value , null );
2019-01-31 21:44:21 +00:00
}
elseif ( 'json' === $target [ 'not_base64' ][ $key ] && 'xml' === $key ) // just for field search
{
$value = json_decode ( $value );
}
// check if we should search for base64 string inside the text
if ( isset ( $target [ 'base64_search' ]) && isset ( $target [ 'base64_search' ][ $key ])
&& isset ( $target [ 'base64_search' ][ $key ][ 'start' ]) && strpos ( $value , $target [ 'base64_search' ][ $key ][ 'start' ]) !== false )
{
// search and open the base64 strings
$this -> searchOpenBase64 ( $value , $target [ 'base64_search' ][ $key ]);
}
// check if place holder set
if ( strpos ( $value , '[CUSTOMC' . 'ODE=' ) !== false )
{
// get all custom codes in value
2023-10-18 07:26:30 +00:00
$bucket [ $key ] = GetHelper :: allBetween ( $value , '[CUSTOMC' . 'ODE=' , ']' );
2019-01-31 21:44:21 +00:00
}
2019-05-15 22:50:45 +00:00
// check if field has string length
2023-10-18 07:26:30 +00:00
if ( StringHelper :: check ( $value ))
2019-05-15 22:50:45 +00:00
{
2021-08-11 12:15:35 +00:00
// see if the field needs some help :)
$_key = ( isset ( $helper [ $key ])) ? $helper [ $key ] : $key ;
// build the buttons
$buttons [ $_key ] = array ();
2023-10-18 07:26:30 +00:00
if (( $button = $this -> getButton ( 'custom_code' , 3 )) && StringHelper :: check ( $button ))
2019-05-15 22:50:45 +00:00
{
2021-08-11 12:15:35 +00:00
$buttons [ $_key ][ '_create' ] = $button ;
2019-05-15 22:50:45 +00:00
}
}
2019-01-31 21:44:21 +00:00
}
}
// check if any values found
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $bucket ))
2019-01-31 21:44:21 +00:00
{
foreach ( $bucket as $field => $customcodes )
{
// see if the field needs some help :)
2021-08-11 12:15:35 +00:00
$field = ( isset ( $helper [ $field ])) ? $helper [ $field ] : $field ;
// set the edit icon
$edit_icon = '<span class="icon-edit" aria-hidden="true"></span> ' ;
// load the buttons found
2019-01-31 21:44:21 +00:00
foreach ( $customcodes as $customcode )
{
2021-08-11 12:15:35 +00:00
// get the customcode name
2019-01-31 21:44:21 +00:00
$key = ( array ) explode ( '+' , $customcode );
2021-08-11 12:15:35 +00:00
// see if we can get the button
2019-01-31 21:44:21 +00:00
if ( ! isset ( $buttons [ $field ][ $key [ 0 ]]) && ( $_id = ComponentbuilderHelper :: getVar ( 'custom_code' , $key [ 0 ], 'function_name' )) !== false
&& ( $button = ComponentbuilderHelper :: getEditTextButton ( $edit_icon . $key [ 0 ], $_id , 'custom_code' , 'custom_codes' , $return_here , 'com_componentbuilder' , false , 'btn btn-small button-edit" style="margin: 0 0 5px 0;' ))
2023-10-18 07:26:30 +00:00
&& StringHelper :: check ( $button ))
2019-01-31 21:44:21 +00:00
{
$buttons [ $field ][ $key [ 0 ]] = $button ;
}
}
}
}
}
2019-05-15 22:50:45 +00:00
// only continue if we have buttons in array
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $buttons , true ))
2019-05-15 22:50:45 +00:00
{
return $buttons ;
}
2019-01-31 21:44:21 +00:00
}
return false ;
}
2017-02-13 23:24:38 +00:00
public function checkFunctionName ( $name , $id )
{
$nameArray = ( array ) $this -> splitAtUpperCase ( $name );
2023-10-18 07:26:30 +00:00
$name = StringHelper :: safe ( implode ( ' ' , $nameArray ), 'cA' );
2017-02-13 23:24:38 +00:00
if ( $found = ComponentbuilderHelper :: getVar ( 'custom_code' , $name , 'function_name' , 'id' ))
{
if (( int ) $id !== ( int ) $found )
{
return array (
'message' => JText :: _ ( 'COM_COMPONENTBUILDER_SORRY_THIS_FUNCTION_NAME_IS_ALREADY_IN_USE' ),
'status' => 'danger' );
}
}
return array (
'name' => $name ,
'message' => JText :: _ ( 'COM_COMPONENTBUILDER_GREAT_THIS_FUNCTION_NAME_WILL_WORK' ),
'status' => 'success' );
}
protected function splitAtUpperCase ( $string )
{
return preg_split ( '/(?=[A-Z])/' , $string , - 1 , PREG_SPLIT_NO_EMPTY );
}
2019-02-23 13:28:54 +00:00
2017-02-17 18:35:18 +00:00
public function usedin ( $functioName , $id , $targeting )
{
// get the table being targeted
2018-02-20 20:46:29 +00:00
if ( $target = $this -> getCodeSearchKeys ( $targeting , 'query' ))
2017-02-17 18:35:18 +00:00
{
$db = JFactory :: getDbo ();
$query = $db -> getQuery ( true )
-> select ( $db -> quoteName ( $target [ 'select' ]))
2017-11-01 03:16:21 +00:00
-> from ( $db -> quoteName ( '#__componentbuilder_' . $target [ 'table' ], 'a' ));
if ( strpos ( $target [ 'name' ], '->' ) !== false && strpos ( $target [ 'name' ], ':' ) !== false && strpos ( $target [ 'name' ], '.' ) !== false )
{
// joomla_component->id:joomla_component.system_name (example)
$targetJoin = explode ( '->' , $target [ 'name' ]);
// get keys
$targetKeys = explode ( ':' , $targetJoin [ 1 ]);
// get table.name
$table_name = explode ( '.' , $targetKeys [ 1 ]);
// select the correct name
$query -> select ( $db -> quoteName ( array ( 'c.' . $table_name [ 1 ]), array ( $targetJoin [ 0 ])));
// add some special fetch
$query -> join ( 'LEFT' , $db -> quoteName ( '#__componentbuilder_' . $table_name [ 0 ], 'c' ) . ' ON (' . $db -> quoteName ( 'a.' . $targetJoin [ 0 ]) . ' = ' . $db -> quoteName ( 'c.' . $targetKeys [ 0 ]) . ')' );
// set the correct name
$target [ 'name' ] = $targetJoin [ 0 ];
}
2017-02-17 18:35:18 +00:00
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> loadRowList ())
{
$bucket = array ();
$hugeDataSet = $db -> loadAssocList ();
foreach ( $hugeDataSet as $data )
{
foreach ( $data as $key => $value )
{
if ( 'id' !== $key && $target [ 'name' ] !== $key )
{
if ( ! isset ( $target [ 'not_base64' ][ $key ]))
{
2023-10-18 07:26:30 +00:00
$value = Base64Helper :: open ( $value , null );
2018-09-28 15:46:21 +00:00
}
elseif ( 'json' === $target [ 'not_base64' ][ $key ] && 'xml' === $key ) // just for field search
{
$value = json_decode ( $value );
}
// check if we should search for base64 string inside the text
if ( isset ( $target [ 'base64_search' ]) && isset ( $target [ 'base64_search' ][ $key ])
&& isset ( $target [ 'base64_search' ][ $key ][ 'start' ]) && strpos ( $value , $target [ 'base64_search' ][ $key ][ 'start' ]) !== false )
{
2018-09-29 21:52:22 +00:00
// search and open the base64 strings
$this -> searchOpenBase64 ( $value , $target [ 'base64_search' ][ $key ]);
2017-02-17 18:35:18 +00:00
}
2019-02-23 13:28:54 +00:00
// when searching for custom code placeholders
if ( 'functioName' === 'functioName' )
{
// check if placeholder found
if ( strpos ( $value , '[CUSTOMC' . 'ODE=' . ( string ) $functioName . ']' ) !== false || strpos ( $value , '[CUSTOMC' . 'ODE=' . ( int ) $id . ']' ) !== false || strpos ( $value , '[CUSTOMC' . 'ODE=' . ( string ) $functioName . '+' ) !== false || strpos ( $value , '[CUSTOMC' . 'ODE=' . ( int ) $id . '+' ) !== false )
{
// found it so add to bucket
if ( ! isset ( $bucket [ $data [ 'id' ]]))
{
$bucket [ $data [ 'id' ]] = array ();
$bucket [ $data [ 'id' ]][ 'name' ] = $data [ $target [ 'name' ]];
$bucket [ $data [ 'id' ]][ 'fields' ] = array ();
}
$bucket [ $data [ 'id' ]][ 'fields' ][] = $key ;
}
}
// when searching for just placeholders
elseif ( 'functioName' === 'placeholder' )
2017-02-17 18:35:18 +00:00
{
2019-02-23 13:28:54 +00:00
// make sure the placeholder is wrapped
$functioName = preg_replace ( " /[^A-Za-z0-9_]/ " , '' , $functioName );
// add the padding (needed)
$functioName = '[[[' . trim ( $functioName ) . ']]]' ;
// check if placeholder found
if ( strpos ( $value , ( string ) $functioName ) !== false )
2017-02-17 18:35:18 +00:00
{
2019-02-23 13:28:54 +00:00
// found it so add to bucket
if ( ! isset ( $bucket [ $data [ 'id' ]]))
{
$bucket [ $data [ 'id' ]] = array ();
$bucket [ $data [ 'id' ]][ 'name' ] = $data [ $target [ 'name' ]];
$bucket [ $data [ 'id' ]][ 'fields' ] = array ();
}
$bucket [ $data [ 'id' ]][ 'fields' ][] = $key ;
2017-02-17 18:35:18 +00:00
}
}
}
}
}
// check if any values found
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $bucket ))
2017-02-17 18:35:18 +00:00
{
2019-01-31 21:44:21 +00:00
// get input
$jinput = JFactory :: getApplication () -> input ;
$return_here = $jinput -> get ( 'return_here' , null , 'base64' );
// set the return here value if not found
2023-10-18 07:26:30 +00:00
if ( StringHelper :: check ( $return_here ))
2019-01-31 21:44:21 +00:00
{
$return_here = '&return=' . $return_here ;
}
else
{
$return_here = '&ref=custom_code&refid=' . ( int ) $id ;
}
2017-02-17 18:35:18 +00:00
$usedin = array ();
foreach ( $bucket as $editId => $values )
{
2019-01-31 21:44:21 +00:00
if (( $button = ComponentbuilderHelper :: getEditTextButton ( $values [ 'name' ], $editId , $target [ 'table' ], $target [ 'views' ], $return_here , 'com_componentbuilder' , false , '' ))
2023-10-18 07:26:30 +00:00
&& StringHelper :: check ( $button ))
2019-01-31 21:44:21 +00:00
{
$usedin [] = $button . ' (' . implode ( ', ' , $values [ 'fields' ]) . ')' ;
}
2017-02-17 18:35:18 +00:00
}
$html = '<ul><li>' . implode ( '</li><li>' , $usedin ) . '</li></ul>' ;
return array ( 'in' => $html , 'id' => $targeting );
}
}
}
return false ;
}
2019-02-23 13:28:54 +00:00
2018-02-27 12:17:38 +00:00
2018-09-29 21:52:22 +00:00
/**
* Search for base64 strings and decode them
*
* @ param string $value The string to search
* @ param array $target The target search values
*
* @ return void
*
*/
protected function searchOpenBase64 ( & $value , & $target )
{
// first get the start property (if dynamic)
$starts = array ();
if ( isset ( $target [ '_start' ]))
{
// get all values
2023-10-18 07:26:30 +00:00
$allBetween = GetHelper :: allBetween ( $value , $target [ 'start' ], $target [ '_start' ]);
2018-09-29 21:52:22 +00:00
// just again make sure we found some
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $allBetween ))
2018-09-29 21:52:22 +00:00
{
if ( count (( array ) $allBetween ) > 1 )
{
// search for many
foreach ( $allBetween as $between )
{
// load the starting property
$start = $target [ 'start' ];
$start .= $between ;
$start .= $target [ '_start' ];
$starts [] = $start ;
}
}
else
{
// load the starting property
$start = $target [ 'start' ];
$start .= array_values ( $allBetween )[ 0 ];
$start .= $target [ '_start' ];
$starts [] = $start ;
}
}
}
else
{
$starts [] = $target [ 'start' ];
}
// has any been found
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $starts ))
2018-09-29 21:52:22 +00:00
{
foreach ( $starts as $_start )
{
// get the base64 string
2023-10-18 07:26:30 +00:00
$base64 = GetHelper :: between ( $value , $_start , $target [ 'end' ]);
2018-09-29 21:52:22 +00:00
// now open the base64 text
2023-10-18 07:26:30 +00:00
$tmp = Base64Helper :: open ( $base64 );
2018-09-29 21:52:22 +00:00
// insert it back into the value (so we still search the whole string)
$value = str_replace ( $base64 , $tmp , $value );
}
}
}
2018-09-28 15:46:21 +00:00
/**
* The code search keys / targets
*
* @ var array
*/
protected $codeSearchKeys = array (
2018-10-29 16:38:00 +00:00
// #__componentbuilder_joomla_component (a)
2018-09-28 15:46:21 +00:00
'joomla_component' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'system_name' , 'php_preflight_install' , 'php_postflight_install' ,
'php_preflight_update' , 'php_postflight_update' , 'php_method_uninstall' ,
'php_helper_admin' , 'php_admin_event' , 'php_helper_both' , 'php_helper_site' ,
2019-12-03 02:17:35 +00:00
'php_site_event' , 'javascript' , 'readme' , 'sql' , 'sql_uninstall' ),
2018-09-28 15:46:21 +00:00
'views' => 'joomla_components' ,
'not_base64' => array (),
'name' => 'system_name'
),
2018-10-29 16:38:00 +00:00
// #__componentbuilder_component_dashboard (b)
2018-09-28 15:46:21 +00:00
'component_dashboard' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'joomla_component' , 'php_dashboard_methods' , 'dashboard_tab' ),
2018-09-28 15:46:21 +00:00
'views' => 'components_dashboard' ,
'not_base64' => array ( 'dashboard_tab' => 'json' ),
'name' => 'joomla_component->id:joomla_component.system_name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_component_placeholders (c)
'component_placeholders' => array (
'search' => array ( 'id' , 'joomla_component' , 'addplaceholders' ),
'views' => 'components_placeholders' ,
'not_base64' => array ( 'addplaceholders' => 'json' ),
'name' => 'joomla_component->id:joomla_component.system_name'
),
// #__componentbuilder_admin_view (d)
2018-09-28 15:46:21 +00:00
'admin_view' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'system_name' , 'javascript_view_file' , 'javascript_view_footer' ,
'javascript_views_file' , 'javascript_views_footer' , 'html_import_view' ,
'php_after_delete' , 'php_after_publish' , 'php_ajaxmethod' , 'php_allowedit' , 'php_batchcopy' ,
'php_batchmove' , 'php_before_delete' , 'php_before_publish' , 'php_before_save' , 'php_controller' ,
'php_controller_list' , 'php_document' , 'php_getitem' , 'php_getitems' , 'php_getitems_after_all' ,
'php_getlistquery' , 'php_import' , 'php_import_display' , 'php_import_ext' , 'php_import_headers' , 'php_getform' ,
2020-10-11 02:02:00 +00:00
'php_import_save' , 'php_import_setdata' , 'php_model' , 'php_model_list' , 'php_postsavehook' , 'php_save' , 'sql' ),
2018-09-28 15:46:21 +00:00
'views' => 'admin_views' ,
'not_base64' => array (),
'name' => 'system_name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_admin_fields_relations (e)
2018-09-28 15:46:21 +00:00
'admin_fields_relations' => array (
'search' => array ( 'id' , 'admin_view' , 'addrelations' ),
'views' => 'admins_fields_relations' ,
'not_base64' => array ( 'addrelations' => 'json' ),
'name' => 'admin_view->id:admin_view.system_name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_admin_custom_tabs (f)
'admin_custom_tabs' => array (
'search' => array ( 'id' , 'admin_view' , 'tabs' ),
'views' => 'admins_custom_tabs' ,
'not_base64' => array ( 'tabs' => 'json' ),
'name' => 'admin_view->id:admin_view.system_name'
),
// #__componentbuilder_custom_admin_view (g)
2018-09-28 15:46:21 +00:00
'custom_admin_view' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'system_name' , 'default' , 'php_view' , 'php_jview' , 'php_jview_display' , 'php_document' ,
2020-01-03 01:41:55 +00:00
'javascript_file' , 'js_document' , 'css_document' , 'css' , 'php_ajaxmethod' , 'php_model' , 'php_controller' ),
2018-09-28 15:46:21 +00:00
'views' => 'custom_admin_views' ,
'not_base64' => array (),
'name' => 'system_name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_site_view (h)
2018-09-28 15:46:21 +00:00
'site_view' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'system_name' , 'default' , 'php_view' , 'php_jview' , 'php_jview_display' , 'php_document' ,
2020-01-03 01:41:55 +00:00
'javascript_file' , 'js_document' , 'css_document' , 'css' , 'php_ajaxmethod' , 'php_model' , 'php_controller' ),
2018-09-28 15:46:21 +00:00
'views' => 'site_views' ,
'not_base64' => array (),
'name' => 'system_name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_field (i)
2018-09-28 15:46:21 +00:00
'field' => array (
2019-10-16 20:34:36 +00:00
'search' => array ( 'id' , 'name' , 'xml' , 'javascript_view_footer' , 'javascript_views_footer' , 'on_save_model_field' , 'on_get_model_field' , 'initiator_on_save_model' , 'initiator_on_get_model' ),
2018-09-28 15:46:21 +00:00
'views' => 'fields' ,
'not_base64' => array ( 'xml' => 'json' ),
'base64_search' => array ( 'xml' => array ( 'start' => 'type_php' , '_start' => '="' , 'end' => '"' )),
'name' => 'name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_fieldtype (j)
2018-09-28 15:46:21 +00:00
'fieldtype' => array (
'search' => array ( 'id' , 'name' , 'properties' ),
'views' => 'fieldtypes' ,
'not_base64' => array ( 'properties' => 'json' ),
'name' => 'name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_dynamic_get (k)
2018-09-28 15:46:21 +00:00
'dynamic_get' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'name' , 'php_before_getitem' , 'php_after_getitem' , 'php_before_getitems' , 'php_after_getitems' ,
2019-10-11 13:41:00 +00:00
'php_getlistquery' , 'php_calculation' ),
2018-09-28 15:46:21 +00:00
'views' => 'dynamic_gets' ,
'not_base64' => array (),
'name' => 'name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_template (l)
2018-09-28 15:46:21 +00:00
'template' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'name' , 'php_view' , 'template' ),
2018-09-28 15:46:21 +00:00
'views' => 'templates' ,
'not_base64' => array (),
'name' => 'name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_layout (m)
2018-09-28 15:46:21 +00:00
'layout' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'name' , 'php_view' , 'layout' ),
2018-09-28 15:46:21 +00:00
'views' => 'layouts' ,
'not_base64' => array (),
'name' => 'name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_library (n)
2018-09-28 15:46:21 +00:00
'library' => array (
'search' => array ( 'id' , 'name' , 'php_setdocument' ),
'views' => 'libraries' ,
'not_base64' => array (),
'name' => 'name'
2018-11-27 13:05:47 +00:00
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_custom_code (o)
2018-11-27 13:05:47 +00:00
'custom_code' => array (
'search' => array ( 'id' , 'system_name' , 'code' ),
'views' => 'custom_codes' ,
'not_base64' => array (),
'name' => 'system_name'
2019-01-31 21:44:21 +00:00
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_validation_rule (p)
2019-01-31 21:44:21 +00:00
'validation_rule' => array (
'search' => array ( 'id' , 'name' , 'php' ),
'views' => 'validation_rules' ,
'not_base64' => array (),
'name' => 'name'
2019-07-16 23:15:42 +00:00
),
2019-12-06 05:31:32 +00:00
// #__componentbuilder_joomla_module (q)
'joomla_module' => array (
'search' => array ( 'id' , 'system_name' , 'name' , 'default' , 'description' , 'mod_code' , 'class_helper_header' , 'class_helper_code' , 'php_script_construct' , 'php_preflight_install' , 'php_preflight_update' ,
'php_preflight_uninstall' , 'php_postflight_install' , 'php_postflight_update' , 'php_method_uninstall' , 'sql' , 'sql_uninstall' , 'readme' ),
'views' => 'joomla_modules' ,
'not_base64' => array ( 'description' => 'string' , 'readme' => 'string' ),
'name' => 'system_name'
),
// #__componentbuilder_joomla_plugin (r)
2019-07-16 23:15:42 +00:00
'joomla_plugin' => array (
2019-08-15 14:26:46 +00:00
'search' => array ( 'id' , 'system_name' , 'name' , 'main_class_code' , 'head' , 'description' , 'php_script_construct' , 'php_preflight_install' , 'php_preflight_update' ,
2019-12-06 05:31:32 +00:00
'php_preflight_uninstall' , 'php_postflight_install' , 'php_postflight_update' , 'php_method_uninstall' , 'sql' , 'sql_uninstall' , 'readme' ),
2019-07-16 23:15:42 +00:00
'views' => 'joomla_plugins' ,
2019-12-06 05:31:32 +00:00
'not_base64' => array ( 'description' => 'string' , 'readme' => 'string' ),
2019-08-12 21:30:31 +00:00
'name' => 'system_name'
2019-07-16 23:15:42 +00:00
),
2019-12-06 05:31:32 +00:00
// #__componentbuilder_class_extends (s)
2019-07-16 23:15:42 +00:00
'class_extends' => array (
'search' => array ( 'id' , 'name' , 'head' , 'comment' ),
'views' => 'class_extendings' ,
'not_base64' => array (),
'name' => 'name'
),
2019-12-06 05:31:32 +00:00
// #__componentbuilder_class_property (t)
2019-07-16 23:15:42 +00:00
'class_property' => array (
'search' => array ( 'id' , 'name' , 'default' , 'comment' ),
'views' => 'class_properties' ,
'not_base64' => array (),
'name' => 'name'
),
2019-12-06 05:31:32 +00:00
// #__componentbuilder_class_method (u)
2019-07-16 23:15:42 +00:00
'class_method' => array (
'search' => array ( 'id' , 'name' , 'code' , 'comment' ),
'views' => 'class_methods' ,
'not_base64' => array (),
'name' => 'name'
2021-10-18 20:12:19 +00:00
),
// #__componentbuilder_power (v)
2022-05-16 04:25:03 +00:00
'power' => array (
2021-12-21 14:44:50 +00:00
'search' => array ( 'id' , 'system_name' , 'name' , 'description' , 'head' , 'namespace' , 'main_class_code' ),
2021-10-18 20:12:19 +00:00
'views' => 'powers' ,
'not_base64' => array ( 'description' ),
2021-12-21 14:44:50 +00:00
'name' => 'system_name'
2018-09-28 15:46:21 +00:00
)
);
2017-02-17 18:35:18 +00:00
/**
2018-02-20 20:46:29 +00:00
* Get the keys of the values to search custom code in
2017-02-17 18:35:18 +00:00
*
2018-09-29 00:57:11 +00:00
* @ param string $target The table targeted
2018-02-20 20:46:29 +00:00
* @ param string $type The type of get
2017-02-17 18:35:18 +00:00
*
* @ return array The query options
*
*/
2018-02-20 20:46:29 +00:00
protected function getCodeSearchKeys ( $target , $type = null )
2017-02-13 23:24:38 +00:00
{
2018-02-20 20:46:29 +00:00
// set the template if type is query
if ( 'query' === $type )
{
2018-09-28 15:46:21 +00:00
// setup the tables
$tables = array ();
$key = 'a' ;
foreach ( array_keys ( $this -> codeSearchKeys ) as $table )
{
$tables [ $key ] = $table ;
$key ++ ;
}
2018-02-20 20:46:29 +00:00
// check if we have a match
if ( isset ( $tables [ $target ]))
{
$target = $tables [ $target ];
}
}
// return result ready for a.query
2019-01-31 21:44:21 +00:00
if (( 'query' === $type || 'query_' === $type ) && isset ( $this -> codeSearchKeys [ $target ]))
2017-02-17 18:35:18 +00:00
{
2018-09-28 15:46:21 +00:00
// set the targets
$codeSearchTarget = $this -> codeSearchKeys [ $target ];
2017-11-01 03:16:21 +00:00
// add the .a to the selection array
2018-09-28 15:46:21 +00:00
$codeSearchTarget [ 'select' ] = array_map ( function ( $select ) { return 'a.' . $select ; }, $codeSearchTarget [ 'search' ]);
2018-02-20 20:46:29 +00:00
// also set the table
2018-09-28 15:46:21 +00:00
$codeSearchTarget [ 'table' ] = $target ;
2018-02-20 20:46:29 +00:00
// remove search
2018-09-28 15:46:21 +00:00
unset ( $codeSearchTarget [ 'search' ]);
// return targeted array to use in query
return $codeSearchTarget ;
2018-02-20 20:46:29 +00:00
}
2018-09-28 15:46:21 +00:00
// does the target exist
elseif ( isset ( $this -> codeSearchKeys [ $target ]))
2018-02-20 20:46:29 +00:00
{
2018-09-28 15:46:21 +00:00
// return target array values to use in search
return $this -> codeSearchKeys [ $target ];
2017-02-17 18:35:18 +00:00
}
return false ;
2018-09-28 15:46:21 +00:00
}
2017-02-13 23:24:38 +00:00
2019-02-23 13:28:54 +00:00
// Used in placeholder
public function checkPlaceholderName ( $id , $name )
{
return ComponentbuilderHelper :: validateUniquePlaceholder ( $id , $name );
}
public function placedin ( $placeholder , $id , $targeting )
{
// get the table being targeted
if ( $target = $this -> getCodeSearchKeys ( $targeting , 'query' ))
{
$db = JFactory :: getDbo ();
$query = $db -> getQuery ( true )
-> select ( $db -> quoteName ( $target [ 'select' ]))
-> from ( $db -> quoteName ( '#__componentbuilder_' . $target [ 'table' ], 'a' ));
if ( strpos ( $target [ 'name' ], '->' ) !== false && strpos ( $target [ 'name' ], ':' ) !== false && strpos ( $target [ 'name' ], '.' ) !== false )
{
// joomla_component->id:joomla_component.system_name (example)
$targetJoin = explode ( '->' , $target [ 'name' ]);
// get keys
$targetKeys = explode ( ':' , $targetJoin [ 1 ]);
// get table.name
$table_name = explode ( '.' , $targetKeys [ 1 ]);
// select the correct name
$query -> select ( $db -> quoteName ( array ( 'c.' . $table_name [ 1 ]), array ( $targetJoin [ 0 ])));
// add some special fetch
$query -> join ( 'LEFT' , $db -> quoteName ( '#__componentbuilder_' . $table_name [ 0 ], 'c' ) . ' ON (' . $db -> quoteName ( 'a.' . $targetJoin [ 0 ]) . ' = ' . $db -> quoteName ( 'c.' . $targetKeys [ 0 ]) . ')' );
// set the correct name
$target [ 'name' ] = $targetJoin [ 0 ];
}
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> loadRowList ())
{
$bucket = array ();
$hugeDataSet = $db -> loadAssocList ();
foreach ( $hugeDataSet as $data )
{
foreach ( $data as $key => $value )
{
if ( 'id' !== $key && $target [ 'name' ] !== $key )
{
if ( ! isset ( $target [ 'not_base64' ][ $key ]))
{
2023-10-18 07:26:30 +00:00
$value = Base64Helper :: open ( $value , null );
2019-02-23 13:28:54 +00:00
}
elseif ( 'json' === $target [ 'not_base64' ][ $key ] && 'xml' === $key ) // just for field search
{
$value = json_decode ( $value );
}
// check if we should search for base64 string inside the text
if ( isset ( $target [ 'base64_search' ]) && isset ( $target [ 'base64_search' ][ $key ])
&& isset ( $target [ 'base64_search' ][ $key ][ 'start' ]) && strpos ( $value , $target [ 'base64_search' ][ $key ][ 'start' ]) !== false )
{
// search and open the base64 strings
$this -> searchOpenBase64 ( $value , $target [ 'base64_search' ][ $key ]);
}
// when searching for custom code placeholders
if ( 'placeholder' === 'functioName' )
{
// check if placeholder found
if ( strpos ( $value , '[CUSTOMC' . 'ODE=' . ( string ) $placeholder . ']' ) !== false || strpos ( $value , '[CUSTOMC' . 'ODE=' . ( int ) $id . ']' ) !== false || strpos ( $value , '[CUSTOMC' . 'ODE=' . ( string ) $placeholder . '+' ) !== false || strpos ( $value , '[CUSTOMC' . 'ODE=' . ( int ) $id . '+' ) !== false )
{
// found it so add to bucket
if ( ! isset ( $bucket [ $data [ 'id' ]]))
{
$bucket [ $data [ 'id' ]] = array ();
$bucket [ $data [ 'id' ]][ 'name' ] = $data [ $target [ 'name' ]];
$bucket [ $data [ 'id' ]][ 'fields' ] = array ();
}
$bucket [ $data [ 'id' ]][ 'fields' ][] = $key ;
}
}
// when searching for just placeholders
elseif ( 'placeholder' === 'placeholder' )
{
// make sure the placeholder is wrapped
$placeholder = preg_replace ( " /[^A-Za-z0-9_]/ " , '' , $placeholder );
// add the padding (needed)
$placeholder = '[[[' . trim ( $placeholder ) . ']]]' ;
// check if placeholder found
if ( strpos ( $value , ( string ) $placeholder ) !== false )
{
// found it so add to bucket
if ( ! isset ( $bucket [ $data [ 'id' ]]))
{
$bucket [ $data [ 'id' ]] = array ();
$bucket [ $data [ 'id' ]][ 'name' ] = $data [ $target [ 'name' ]];
$bucket [ $data [ 'id' ]][ 'fields' ] = array ();
}
$bucket [ $data [ 'id' ]][ 'fields' ][] = $key ;
}
}
}
}
}
// check if any values found
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $bucket ))
2019-02-23 13:28:54 +00:00
{
// get input
$jinput = JFactory :: getApplication () -> input ;
$return_here = $jinput -> get ( 'return_here' , null , 'base64' );
// set the return here value if not found
2023-10-18 07:26:30 +00:00
if ( StringHelper :: check ( $return_here ))
2019-02-23 13:28:54 +00:00
{
$return_here = '&return=' . $return_here ;
}
else
{
$return_here = '&ref=placeholder&refid=' . ( int ) $id ;
}
$placedin = array ();
foreach ( $bucket as $editId => $values )
{
if (( $button = ComponentbuilderHelper :: getEditTextButton ( $values [ 'name' ], $editId , $target [ 'table' ], $target [ 'views' ], $return_here , 'com_componentbuilder' , false , '' ))
2023-10-18 07:26:30 +00:00
&& StringHelper :: check ( $button ))
2019-02-23 13:28:54 +00:00
{
$placedin [] = $button . ' (' . implode ( ', ' , $values [ 'fields' ]) . ')' ;
}
}
$html = '<ul><li>' . implode ( '</li><li>' , $placedin ) . '</li></ul>' ;
return array ( 'in' => $html , 'id' => $targeting );
}
}
}
return false ;
}
2018-03-27 09:57:16 +00:00
// Used in validation_rule
public function getExistingValidationRuleCode ( $name )
{
// make sure we have all the exiting rule names
if ( $names = ComponentbuilderHelper :: getExistingValidationRuleNames ())
{
// check that this is a valid rule file
if ( ComponentbuilderHelper :: checkArray ( $names ) && in_array ( $name , $names ))
{
// get the full path to rule file
$path = JPATH_LIBRARIES . '/src/Form/Rule/' . $name . 'Rule.php' ;
// get all the code
if ( $code = ComponentbuilderHelper :: getFileContents ( $path ))
{
// remove the class details and the ending }
$codeArray = ( array ) explode ( " FormRule \n { \n " , $code );
if ( isset ( $codeArray [ 1 ]))
{
return array ( 'values' => rtrim ( rtrim ( rtrim ( $codeArray [ 1 ]), '}' )));
}
}
}
}
return false ;
}
public function checkRuleName ( $name , $id )
{
2023-10-18 07:26:30 +00:00
$name = StringHelper :: safe ( $name );
2018-03-27 09:57:16 +00:00
if ( $found = ComponentbuilderHelper :: getVar ( 'validation_rule' , $name , 'name' , 'id' ))
{
if (( int ) $id !== ( int ) $found )
{
return array (
'message' => JText :: sprintf ( 'COM_COMPONENTBUILDER_SORRY_THIS_VALIDATION_RULE_NAME_S_ALREADY_EXIST_IN_YOUR_SYSTEM' , $name ),
'status' => 'danger' ,
'timeout' => 6000 );
}
}
// now check the existing once
if ( $names = ComponentbuilderHelper :: getExistingValidationRuleNames ( true ))
{
if ( in_array ( $name , $names ))
{
return array (
'message' => JText :: sprintf ( 'COM_COMPONENTBUILDER_SORRY_THIS_VALIDATION_RULE_NAME_S_ALREADY_EXIST_AS_PART_OF_THE_JOOMLA_CORE_NO_NEED_TO_CREATE_IT_IF_YOU_ARE_ADAPTING_IT_GIVE_IT_YOUR_OWN_UNIQUE_NAME' , $name ),
'status' => 'danger' ,
'timeout' => 10000 );
}
}
return array (
'name' => $name ,
'message' => JText :: sprintf ( 'COM_COMPONENTBUILDER_GREAT_THIS_VALIDATION_RULE_NAME_S_WILL_WORK' , $name ),
'status' => 'success' ,
'timeout' => 5000 );
}
public function getValidationRulesTable ( $id )
{
// get all the validation rules
if ( $rules = $this -> getValidationRules ())
{
// build table
$table = '<div class="control-group"><table class="uk-table uk-table-hover uk-table-striped uk-table-condensed">' ;
$table .= '<caption>' . JText :: sprintf ( 'COM_COMPONENTBUILDER_THE_AVAILABLE_VALIDATION_RULES_FOR_THE_VALIDATE_ATTRIBUTE_ARE' ) . '</caption>' ;
$table .= '<thead><tr><th class="uk-text-right">' . JText :: _ ( 'COM_COMPONENTBUILDER_VALIDATE' ) . '</th><th>' . JText :: _ ( 'COM_COMPONENTBUILDER_DESCRIPTION' ) . '</th></tr></thead>' ;
$table .= '<tbody>' ;
foreach ( $rules as $name => $decs )
{
// just load the values
$decs = ( ComponentbuilderHelper :: checkString ( $decs ) && ! is_numeric ( $decs )) ? $decs : '' ;
$table .= '<tr><td class="uk-text-right"><code>' . $name . '</code></td><td>' . $decs . '</td></tr>' ;
}
return $table . '</tbody></table></div>' ;
}
return false ;
}
public function getValidationRules ()
{
// custom rule names
$names = array ();
// make sure we have all the exiting rule names
if ( ! $exitingNames = ComponentbuilderHelper :: getExistingValidationRuleNames ( true ))
{
// stop (something is wrong)
return false ;
}
// convert names to keys
$exitingNames = array_flip ( $exitingNames );
// load the descriptions (taken from https://docs.joomla.org/Server-side_form_validation)
$exitingNames [ " boolean " ] = JText :: _ ( " COM_COMPONENTBUILDER_ACCEPTS_ONLY_THE_VALUES_ZERO_ONE_TRUE_OR_FALSE_CASEINSENSITIVE " );
$exitingNames [ " color " ] = JText :: _ ( " COM_COMPONENTBUILDER_ACCEPTS_ONLY_EMPTY_VALUES_CONVERTED_TO_ZERO_AND_STRINGS_IN_THE_FORM_RGB_OR_RRGGBB_WHERE_R_G_AND_B_ARE_HEX_VALUES " );
$exitingNames [ " email " ] = JText :: _ ( " COM_COMPONENTBUILDER_ACCEPTS_AN_EMAIL_ADDRESS_SATISFIES_A_BASIC_SYNTAX_CHECK_IN_THE_PATTERN_OF_QUOTXYZZQUOT_WITH_NO_INVALID_CHARACTERS " );
2018-03-28 09:46:14 +00:00
$exitingNames [ " equals " ] = JText :: sprintf ( " COM_COMPONENTBUILDER_REQUIRES_THE_VALUE_TO_BE_THE_SAME_AS_THAT_HELD_IN_THE_FIELD_NAMED_QUOTFIELDQUOT_EGS " , '<br /><code><input<br /> type="text"<br /> name="email_check"<br /> validate="equals"<br /> field="email"<br />/></code>' );
2018-03-27 09:57:16 +00:00
$exitingNames [ " options " ] = JText :: _ ( " COM_COMPONENTBUILDER_REQUIRES_THE_VALUE_ENTERED_BE_ONE_OF_THE_OPTIONS_IN_AN_ELEMENT_OF_TYPEQUOTLISTQUOT_THAT_IS_THAT_THE_ELEMENT_IS_A_SELECT_LIST " );
$exitingNames [ " tel " ] = JText :: _ ( " COM_COMPONENTBUILDER_REQUIRES_THE_VALUE_TO_BE_A_TELEPHONE_NUMBER_COMPLYING_WITH_THE_STANDARDS_OF_NANPA_ITUT_TRECEONE_HUNDRED_AND_SIXTY_FOUR_OR_IETF_RFCFOUR_THOUSAND_NINE_HUNDRED_AND_THIRTY_THREE " );
2018-03-28 09:46:14 +00:00
$exitingNames [ " url " ] = JText :: sprintf ( " COM_COMPONENTBUILDER_VALIDATES_THAT_THE_VALUE_IS_A_URL_WITH_A_VALID_SCHEME_WHICH_CAN_BE_RESTRICTED_BY_THE_OPTIONAL_COMMASEPARATED_FIELD_SCHEME_AND_PASSES_A_BASIC_SYNTAX_CHECK_EGS " , '<br /><code><input<br /> type="text"<br /> name="link"<br /> validate="url"<br /> scheme="http,https,mailto"<br />/></code>' );
2018-03-27 09:57:16 +00:00
$exitingNames [ " username " ] = JText :: _ ( " COM_COMPONENTBUILDER_VALIDATES_THAT_THE_VALUE_DOES_NOT_APPEAR_AS_A_USERNAME_ON_THE_SYSTEM_THAT_IS_THAT_IT_IS_A_VALID_NEW_USERNAME_DOES_NOT_SYNTAX_CHECK_IT_AS_A_VALID_NAME " );
// now get the custom created rules
$db = JFactory :: getDbo ();
// Create a new query object.
$query = $db -> getQuery ( true );
$query -> select ( $db -> quoteName ( array ( 'a.name' , 'a.short_description' )));
$query -> from ( $db -> quoteName ( '#__componentbuilder_validation_rule' , 'a' ));
$query -> where ( $db -> quoteName ( 'a.published' ) . ' >= 1' );
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
{
$names = $db -> loadAssocList ( 'name' , 'short_description' );
}
// merge the arrays
2023-10-18 07:26:30 +00:00
$rules = UtilitiesArrayHelper :: merge ( array ( $exitingNames , $names ));
2018-03-27 09:57:16 +00:00
// sort the array
ksort ( $rules );
// return the validation rules
return $rules ;
}
2018-01-15 15:54:05 +00:00
// Used in field
2018-04-13 15:24:06 +00:00
// the current extras available
protected $extraFieldProperties = array (
'listclass' => 'COM_COMPONENTBUILDER_SET_A_CLASS_VALUE_FOR_THE_LIST_VIEW_OF_THIS_FIELD' ,
'escape' => 'COM_COMPONENTBUILDER_SHOULD_THIS_FIELD_BE_ESCAPED_IN_THE_LIST_VIEW' ,
2018-04-24 22:36:05 +00:00
'display' => 'COM_COMPONENTBUILDER_DISPLAY_SWITCH_FOR_DYNAMIC_PLACEMENT_IN_RELATION_TO_THE_USE_OF_THE_FIELD_IN_MENU_AND_GLOBAL_CONFIGURATION_OPTIONS_SO_THE_CONFIG_OPTION_WILL_ONLY_ADD_THE_FIELD_TO_THE_GLOBAL_CONFIGURATION_AREA_MENU_WILL_ADD_THE_FIELD_ONLY_TO_THE_MENU_AREA' ,
2018-04-13 15:24:06 +00:00
'validate' => 'COM_COMPONENTBUILDER_TO_ADD_VALIDATION_TO_A_FIELD_IF_VALIDATION_IS_NOT_PART_OF_FIELD_TYPE_PROPERTIES_LOADED_ABOVE_SO_IF_YOU_HAVE_VALIDATION_SET_AS_A_FIELD_PROPERTY_THIS_EXTRA_PROPERTY_WILL_NOT_BE_NEEDED' );
2020-01-11 16:29:54 +00:00
public function getFieldTypeProperties ( $fieldtype )
2018-01-15 15:54:05 +00:00
{
2018-04-11 20:05:47 +00:00
// get the xml
$xml = $this -> getFieldXML ( $fieldtype );
// now get the field options
2020-01-11 16:29:54 +00:00
if ( $field = ComponentbuilderHelper :: getFieldTypeProperties ( $fieldtype , 'id' , null , $xml , true ))
2018-01-15 15:54:05 +00:00
{
2018-04-13 15:24:06 +00:00
// get subform field properties object
$properties = $this -> buildFieldOptionsSubform ( $field [ 'subform' ], $field [ 'nameListOptions' ]);
// load the extra options
$extraValues = $this -> getFieldExtraValues ( $xml , $field [ 'nameListOptions' ]);
// set the nameListOption
$extraNameListOption = $this -> extraFieldProperties ;
array_walk ( $extraNameListOption , function ( & $value , $key ) {
$value = $key ;
});
2018-04-11 20:05:47 +00:00
// get subform field object
2018-04-13 15:24:06 +00:00
$extras = $this -> buildFieldOptionsSubform ( $extraValues , $extraNameListOption , 'extraproperties' , 'COM_COMPONENTBUILDER_EXTRA_PROPERTIES_LIKE_LISTCLASS_ESCAPE_DISPLAY_VALIDATEBR_SMALLHERE_YOU_CAN_SET_THE_EXTRA_PROPERTIES_FOR_THIS_FIELDSMALL' );
2018-04-11 20:05:47 +00:00
// load the html
2018-04-13 15:24:06 +00:00
$field [ 'subform' ] = '<div class="control-label prop_removal">' . $properties -> label . '</div><div class="controls prop_removal">' . $properties -> input . '</div>' ;
$field [ 'extra' ] = '<div class="control-label prop_removal">' . $extras -> label . '</div><div class="controls prop_removal">' . $extras -> input . '</div>' ;
2018-04-14 22:52:48 +00:00
// check if we have PHP values
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $field [ 'php' ]))
2018-04-14 22:52:48 +00:00
{
$field [ 'textarea' ] = array ();
foreach ( $field [ 'php' ] as $name => $values )
{
$value = implode ( PHP_EOL , $values [ 'value' ]);
2019-07-15 20:00:46 +00:00
$textarea = $this -> buildFieldTextarea ( $name , $values [ 'desc' ], $value , substr_count ( $value , PHP_EOL ));
2018-04-14 22:52:48 +00:00
// load the html
$field [ 'textarea' ][] = '<div class="control-label prop_removal">' . $textarea -> label . '</div><div class="controls prop_removal">' . $textarea -> input . '</div><br />' ;
}
}
// remove some unneeded values
unset ( $field [ 'values' ]);
2018-01-15 15:54:05 +00:00
// return found field options
return $field ;
}
return false ;
2018-04-11 20:05:47 +00:00
}
2018-04-13 15:24:06 +00:00
protected function getFieldExtraValues ( $xml , $options )
{
// get the value
$values = array ();
// value to check since there are false and null values even 0 in the values returned
$confirmation = '8qvZHoyuFYQqpj0YQbc6F3o5DhBlmS-_-a8pmCZfOVSfANjkmV5LG8pCdAY2JNYu6cB' ;
$nr = 0 ;
foreach ( $this -> extraFieldProperties as $extra => $desc )
{
if ( ! in_array ( $extra , $options ))
{
2023-10-18 07:26:30 +00:00
$value = FieldHelper :: getValue ( $xml , $extra , $confirmation );
2018-04-13 15:24:06 +00:00
if ( $confirmation !== $value )
{
$values [ 'extraproperties' . $nr ] = array ( 'name' => $extra , 'value' => $value , 'desc' => JText :: _ ( $desc ));
$nr ++ ;
}
}
}
// return only if extras founb
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $values ))
2018-04-13 15:24:06 +00:00
{
return $values ;
}
return null ;
}
2019-07-15 20:00:46 +00:00
protected function buildFieldTextarea ( $name , $desc , $default , $rows )
2018-04-14 22:52:48 +00:00
{
// get the textarea
$textarea = JFormHelper :: loadFieldType ( 'textarea' , true );
// start building the name field XML
$textareaXML = new SimpleXMLElement ( '<field/>' );
// textarea attributes
$textareaAttribute = array (
'type' => 'textarea' ,
'name' => 'property_' . $name ,
'label' => $desc ,
'rows' => ( int ) ( $rows >= 3 ) ? $rows : $rows + 2 ,
'cols' => '15' ,
'class' => 'text_area span12' ,
'filter' => 'RAW' ,
'hint' => 'COM_COMPONENTBUILDER__ADD_YOUR_PHP_SCRIPT_HERE' );
// load the textarea attributes
ComponentbuilderHelper :: xmlAddAttributes ( $textareaXML , $textareaAttribute );
// setup subform with values
$textarea -> setup ( $textareaXML , $default );
// return textarea object
return $textarea ;
}
2018-04-13 15:24:06 +00:00
protected function buildFieldOptionsSubform ( $values , $nameListOptions = null , $name = 'properties' , $label = 'COM_COMPONENTBUILDER_PROPERTIESBR_SMALLHERE_YOU_CAN_SET_THE_PROPERTIES_FOR_THIS_FIELDSMALL' )
2018-04-11 20:05:47 +00:00
{
// get the subform
$subform = JFormHelper :: loadFieldType ( 'subform' , true );
// start building the subform field XML
$subformXML = new SimpleXMLElement ( '<field/>' );
// subform attributes
$subformAttribute = array (
'type' => 'subform' ,
2018-04-13 15:24:06 +00:00
'name' => $name ,
'label' => $label ,
2018-04-11 20:05:47 +00:00
'layout' => 'joomla.form.field.subform.repeatable-table' ,
'multiple' => 'true' ,
'icon' => 'list' ,
2023-10-18 07:26:30 +00:00
'max' => ( UtilitiesArrayHelper :: check ( $nameListOptions )) ? ( int ) count ( $nameListOptions ) : 4 );
2018-04-11 20:05:47 +00:00
// load the subform attributes
ComponentbuilderHelper :: xmlAddAttributes ( $subformXML , $subformAttribute );
// now add the subform child form
$childForm = $subformXML -> addChild ( 'form' );
// child form attributes
$childFormAttribute = array (
'hidden' => 'true' ,
'name' => 'list_properties' ,
'repeat' => 'true' );
// load the child form attributes
ComponentbuilderHelper :: xmlAddAttributes ( $childForm , $childFormAttribute );
// start building the name field XML
$nameXML = new SimpleXMLElement ( '<field/>' );
// subform attributes
$nameAttribute = array (
2023-10-18 07:26:30 +00:00
'type' => ( UtilitiesArrayHelper :: check ( $nameListOptions )) ? 'list' : 'text' ,
2018-04-11 20:05:47 +00:00
'name' => 'name' ,
'label' => 'COM_COMPONENTBUILDER_PROPERTY' ,
'size' => '40' ,
'maxlength' => '150' ,
2023-10-18 07:26:30 +00:00
'class' => ( UtilitiesArrayHelper :: check ( $nameListOptions )) ? 'list_class field_list_name_options' : 'text_area' ,
2018-04-11 20:05:47 +00:00
'filter' => 'STRING' );
// add the hint only if not name list and description if name list is an array
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $nameListOptions ))
2018-04-11 20:05:47 +00:00
{
$nameAttribute [ 'description' ] = 'COM_COMPONENTBUILDER_SELECTION' ;
$nameAttribute [ 'multiple' ] = 'false' ;
2018-04-13 15:24:06 +00:00
$nameAttribute [ 'onchange' ] = " getFieldPropertyDesc(this, ' " . $name . " ') " ;
2018-04-11 20:05:47 +00:00
}
else
{
$nameAttribute [ 'hint' ] = 'COM_COMPONENTBUILDER_PROPERTY_NAME' ;
}
// load the subform attributes
ComponentbuilderHelper :: xmlAddAttributes ( $nameXML , $nameAttribute );
// add name list if found
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $nameListOptions ))
2018-04-11 20:05:47 +00:00
{
ComponentbuilderHelper :: xmlAddOptions ( $nameXML , $nameListOptions );
}
// now add the fields to the child form
ComponentbuilderHelper :: xmlAppend ( $childForm , $nameXML );
// start building the name field XML
$valueXML = new SimpleXMLElement ( '<field/>' );
// subform attributes
$valueAttribute = array (
'type' => 'textarea' ,
'name' => 'value' ,
'label' => 'COM_COMPONENTBUILDER_VALUE' ,
'rows' => '1' ,
'cols' => '15' ,
'class' => 'text_area span12' ,
'filter' => 'STRING' ,
'hint' => 'COM_COMPONENTBUILDER_PROPERTY_VALUE' );
// load the subform attributes
ComponentbuilderHelper :: xmlAddAttributes ( $valueXML , $valueAttribute );
// now add the fields to the child form
ComponentbuilderHelper :: xmlAppend ( $childForm , $valueXML );
// start building the desc field XML
$descXML = new SimpleXMLElement ( '<field/>' );
// subform attributes
$descAttribute = array (
'type' => 'textarea' ,
'name' => 'desc' ,
'label' => 'COM_COMPONENTBUILDER_DESCRIPTION' ,
'rows' => '3' ,
'cols' => '25' ,
'readonly' => 'true' ,
'class' => 'text_area span12' ,
'filter' => 'WORD' ,
'hint' => 'COM_COMPONENTBUILDER_SELECT_A_PROPERTY' );
// load the desc attributes
ComponentbuilderHelper :: xmlAddAttributes ( $descXML , $descAttribute );
// now add the fields to the child form
ComponentbuilderHelper :: xmlAppend ( $childForm , $descXML );
// setup subform with values
$subform -> setup ( $subformXML , $values );
// return subfrom object
return $subform ;
}
2018-04-13 15:24:06 +00:00
public function getFieldPropertyDesc ( $_property , $fieldtype )
2018-04-11 20:05:47 +00:00
{
2018-04-13 15:24:06 +00:00
if ( is_numeric ( $fieldtype ))
{
// Get a db connection.
$db = JFactory :: getDbo ();
2018-04-11 20:05:47 +00:00
2018-04-13 15:24:06 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
$query -> select ( $db -> quoteName ( array ( 'properties' , 'short_description' , 'description' )));
$query -> from ( $db -> quoteName ( '#__componentbuilder_fieldtype' ));
$query -> where ( $db -> quoteName ( 'id' ) . ' = ' . ( int ) $fieldtype );
2018-04-11 20:05:47 +00:00
2018-04-13 15:24:06 +00:00
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
2018-04-11 20:05:47 +00:00
{
2018-04-13 15:24:06 +00:00
// get the result
$result = $db -> loadObject ();
// get the xml
$xml = $this -> getFieldXML ( $fieldtype );
// open the properties
$properties = json_decode ( $result -> properties , true );
// value to check since there are false and null values even 0 in the values returned
$confirmation = '8qvZHoyuFYQqpj0YQbc6F3o5DhBlmS-_-a8pmCZfOVSfANjkmV5LG8pCdAY2JNYu6cB' ;
// make sure we have an array
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $properties ))
2018-04-11 20:05:47 +00:00
{
2018-04-13 15:24:06 +00:00
foreach ( $properties as $property )
2018-04-11 20:05:47 +00:00
{
2018-04-13 15:24:06 +00:00
if ( isset ( $property [ 'name' ]) && $_property === $property [ 'name' ])
2018-04-11 20:05:47 +00:00
{
2018-04-13 15:24:06 +00:00
// check if we should load the value
2023-10-18 07:26:30 +00:00
$value = FieldHelper :: getValue ( $xml , $property [ 'name' ], $confirmation );
2018-04-13 15:24:06 +00:00
if ( $confirmation === $value )
{
2023-10-18 07:26:30 +00:00
$value = ( isset ( $property [ 'example' ]) && StringHelper :: check ( $property [ 'example' ])) ? $property [ 'example' ] : '' ;
2018-04-13 15:24:06 +00:00
}
// return the found values
return array ( 'value' => $value , 'desc' => $property [ 'description' ]);
2018-04-11 20:05:47 +00:00
}
}
}
}
}
2018-04-13 15:24:06 +00:00
elseif ( isset ( $this -> extraFieldProperties [ $_property ]))
{
return array ( 'value' => '' , 'desc' => JText :: _ ( $this -> extraFieldProperties [ $_property ]));
}
2018-04-11 20:05:47 +00:00
return false ;
}
protected function getFieldXML ( $fieldtype )
{
// reset xml to null
$xml = null ;
// get the view name & id
$global = $this -> getViewID ();
// get the xml if this view already has it set
if ( ! is_null ( $global [ 'a_id' ]) && $global [ 'a_id' ] > 0 && isset ( $global [ 'a_view' ]) && 'field' === $global [ 'a_view' ])
{
// first check field type
$_fieldType = ComponentbuilderHelper :: getVar ( 'field' , $global [ 'a_id' ], 'id' , 'fieldtype' );
2021-08-11 12:15:35 +00:00
$xmlDB = ComponentbuilderHelper :: getVar ( 'field' , $global [ 'a_id' ], 'id' , 'xml' );
// check if it is a string
2023-10-18 07:26:30 +00:00
if ( StringHelper :: check ( $xmlDB ))
2018-04-11 20:05:47 +00:00
{
2021-08-11 12:15:35 +00:00
$xml = json_decode ( $xmlDB );
}
// remove the field type if not the same
if ( $xml && $fieldtype != $_fieldType )
{
// unset some stuff
$pattern = array ();
$pattern [] = '/type=".+?"/i' ; // to force the new type to be set
$pattern [] = '/class=".+?"/i' ; // to remove all classes
$pattern [] = '/type_php.+?".+?"/i' ; // to remove any PHP code stuff
// also add a special switch to force adding all properties of the new type
$xml = preg_replace ( $pattern , '..__FORCE_LOAD_ALL_PROPERTIES__..' , $xml );
2018-04-11 20:05:47 +00:00
}
}
return $xml ;
2018-01-15 15:54:05 +00:00
}
2018-05-24 13:56:56 +00:00
// Used in admin_fields_relations
public function getCodeGlueOptions ( $listfield , $joinfields , $type , $area )
{
// CONCATENATE GLUE
if ( $type == 1 )
{
// MODEL
2018-05-29 03:45:16 +00:00
if ( $area == 1 || $area == 3 )
2018-05-24 13:56:56 +00:00
{
return ', ' ;
}
// VIEW
elseif ( $area == 2 )
{
return '<br />' ;
}
}
// CUSTOM CODE
elseif ( $type == 2 )
{
// build fields array
2018-07-21 07:10:37 +00:00
if ( 'none' !== $joinfields )
{
$fields = array_map ( function ( $id ) {
return ( int ) $id ;
}, ( array ) explode ( ',' , $joinfields ));
// add the list field to array
array_unshift ( $fields , ( int ) $listfield );
}
else
{
$fields = array (( int ) $listfield );
}
2018-05-24 13:56:56 +00:00
// get field names
$names = array_map ( function ( $id ) {
return '[' . $id . ']=> ' . ComponentbuilderHelper :: getVar ( 'field' , $id , 'id' , 'name' );
}, $fields );
// MODEL
2018-05-26 10:03:08 +00:00
if ( $area == 1 || $area == 3 )
2018-05-24 13:56:56 +00:00
{
2018-05-26 10:03:08 +00:00
// create note
$note = " // " . implode ( '; ' , $names );
return $note . PHP_EOL . '$item->{' . ( int ) $listfield . '} = $item->{' . implode ( " } . ', ' . \$ item-> { " , $fields ) . '};' ;
2018-05-24 13:56:56 +00:00
}
// VIEW
elseif ( $area == 2 )
{
2018-05-26 10:03:08 +00:00
// create note
$note = " <!-- " . implode ( '; ' , $names ) . " --> " ;
return '[field=' . implode ( " ]<br />[field= " , $fields ) . ']' . PHP_EOL . PHP_EOL . $note ;
2018-05-24 13:56:56 +00:00
}
}
return false ;
}
2022-09-14 15:40:02 +00:00
// Used in search
/**
* Search for value in a table
*
* @ param string $tableName The main table to search
2022-11-02 19:48:20 +00:00
* @ param int $typeSearch The type of search being done
2022-09-14 15:40:02 +00:00
* @ param string $searchValue The value to search for
* @ param int $matchCase The switch to control match case
* @ param int $wholeWord The switch to control whole word
* @ param int $regexSearch The switch to control regex search
* @ param int $componentId The option to filter by component
*
* @ return array | null
* @ since 3.2 . 0
**/
2022-11-02 19:48:20 +00:00
public function doSearch ( string $tableName , int $typeSearch , string $searchValue ,
2022-09-14 15:40:02 +00:00
int $matchCase , int $wholeWord , int $regexSearch , int $componentId ) : ? array
{
// check if this is a valid table
2022-09-16 21:41:41 +00:00
if ( SearchFactory :: _ ( 'Table' ) -> exist ( $tableName ))
2022-09-14 15:40:02 +00:00
{
2022-11-02 19:48:20 +00:00
try
{
// load the configurations
SearchFactory :: _ ( 'Config' ) -> table_name = $tableName ;
SearchFactory :: _ ( 'Config' ) -> type_search = $typeSearch ;
SearchFactory :: _ ( 'Config' ) -> search_value = $searchValue ;
SearchFactory :: _ ( 'Config' ) -> match_case = $matchCase ;
SearchFactory :: _ ( 'Config' ) -> whole_word = $wholeWord ;
SearchFactory :: _ ( 'Config' ) -> regex_search = $regexSearch ;
SearchFactory :: _ ( 'Config' ) -> component_id = $componentId ;
if (( $items = SearchFactory :: _ ( 'Agent' ) -> table ( $tableName )) !== null )
{
2022-11-04 20:18:05 +00:00
return [
'success' => JText :: sprintf ( 'COM_COMPONENTBUILDER_WE_FOUND_SOME_INSTANCES_IN_S' , $tableName ),
'items' => $items ,
'fields_count' => SearchFactory :: _ ( 'Config' ) -> field_counter ,
'line_count' => SearchFactory :: _ ( 'Config' ) -> line_counter
];
2022-11-02 19:48:20 +00:00
}
2022-09-16 21:41:41 +00:00
2022-11-04 20:18:05 +00:00
return [
'not_found' => JText :: sprintf ( 'COM_COMPONENTBUILDER_NO_INSTANCES_WHERE_FOUND_IN_S' , $tableName ),
'fields_count' => SearchFactory :: _ ( 'Config' ) -> field_counter ,
'line_count' => SearchFactory :: _ ( 'Config' ) -> line_counter
];
2022-11-02 19:48:20 +00:00
}
catch ( Exception $error )
2022-09-14 15:40:02 +00:00
{
2022-11-02 19:48:20 +00:00
return [ 'error' => $error -> getMessage ()];
2022-09-14 15:40:02 +00:00
}
}
return [ 'error' => JText :: _ ( 'COM_COMPONENTBUILDER_THERE_HAS_BEEN_AN_ERROR_PLEASE_TRY_AGAIN' )];
}
/**
* Search and replace value in a table
*
* @ param string $tableName The main table to search
* @ param string $searchValue The value to search for
2022-10-20 14:40:18 +00:00
* @ param string | null $replaceValue The value to replace search value
* @ param int $matchCase The switch to control match case
* @ param int $wholeWord The switch to control whole word
* @ param int $regexSearch The switch to control regex search
* @ param int $componentId The option to filter by component
2022-09-14 15:40:02 +00:00
*
* @ return array | null
* @ since 3.2 . 0
**/
2022-10-30 22:34:54 +00:00
public function replaceAll ( string $tableName , string $searchValue , ? string $replaceValue = null ,
2022-09-14 15:40:02 +00:00
int $matchCase , int $wholeWord , int $regexSearch , int $componentId ) : ? array
{
// check if this is a valid table
2022-10-20 14:40:18 +00:00
if ( SearchFactory :: _ ( 'Table' ) -> exist ( $tableName ))
2022-09-14 15:40:02 +00:00
{
2022-11-02 19:48:20 +00:00
try
{
// load the configurations
SearchFactory :: _ ( 'Config' ) -> table_name = $tableName ;
SearchFactory :: _ ( 'Config' ) -> search_value = $searchValue ;
SearchFactory :: _ ( 'Config' ) -> replace_value = $replaceValue ;
SearchFactory :: _ ( 'Config' ) -> match_case = $matchCase ;
SearchFactory :: _ ( 'Config' ) -> whole_word = $wholeWord ;
SearchFactory :: _ ( 'Config' ) -> regex_search = $regexSearch ;
SearchFactory :: _ ( 'Config' ) -> component_id = $componentId ;
2022-09-14 15:40:02 +00:00
2022-11-02 19:48:20 +00:00
if (( $number = SearchFactory :: _ ( 'Agent' ) -> replace ()) !== 0 )
{
return [ 'success' => JText :: sprintf ( 'COM_COMPONENTBUILDER_ALL_FOUND_INSTANCES_IN_S_WHERE_REPLACED' , $tableName )];
}
return [ 'not_found' => JText :: sprintf ( 'COM_COMPONENTBUILDER_NO_INSTANCES_WHERE_FOUND_IN_S' , $tableName )];
}
catch ( Exception $error )
{
return [ 'error' => $error -> getMessage ()];
}
2022-09-14 15:40:02 +00:00
}
return [ 'error' => JText :: _ ( 'COM_COMPONENTBUILDER_THERE_HAS_BEEN_AN_ERROR_PLEASE_TRY_AGAIN' )];
}
2022-10-20 14:40:18 +00:00
/**
* Get a selected search value from a given table and row
*
* @ param string $fieldName The field key
* @ param int $rowId The item ID
* @ param string $tableName The table
2022-11-02 19:48:20 +00:00
* @ param string $searchValue The value to search for
* @ param string | null $replaceValue The value to replace search value
* @ param int $matchCase The switch to control match case
* @ param int $wholeWord The switch to control whole word
* @ param int $regexSearch The switch to control regex search
2022-10-20 14:40:18 +00:00
*
* @ return array
* @ since 3.2 . 0
**/
2022-11-02 19:48:20 +00:00
public function getSearchValue ( string $fieldName , int $rowId , string $tableName ,
string $searchValue , ? string $replaceValue = null , int $matchCase , int $wholeWord , int $regexSearch ) : array
2022-10-20 14:40:18 +00:00
{
// check if this is a valid table and field
2022-10-30 22:34:54 +00:00
if ( $rowId > 0 && SearchFactory :: _ ( 'Table' ) -> exist ( $tableName , $fieldName ))
2022-10-20 14:40:18 +00:00
{
2022-11-02 19:48:20 +00:00
try
{
// load the configurations
SearchFactory :: _ ( 'Config' ) -> table_name = $tableName ;
SearchFactory :: _ ( 'Config' ) -> type_search = 1 ;
SearchFactory :: _ ( 'Config' ) -> search_value = $searchValue ;
SearchFactory :: _ ( 'Config' ) -> replace_value = $replaceValue ;
SearchFactory :: _ ( 'Config' ) -> match_case = $matchCase ;
SearchFactory :: _ ( 'Config' ) -> whole_word = $wholeWord ;
SearchFactory :: _ ( 'Config' ) -> regex_search = $regexSearch ;
2022-10-30 22:34:54 +00:00
2022-11-02 19:48:20 +00:00
if (( $value = SearchFactory :: _ ( 'Agent' ) -> getValue ( $rowId , $fieldName , 0 , $tableName )) !== null )
{
// load the value
return [ 'value' => $value ];
}
}
catch ( Exception $error )
2022-10-30 22:34:54 +00:00
{
2022-11-02 19:48:20 +00:00
return [ 'error' => $error -> getMessage ()];
2022-10-30 22:34:54 +00:00
}
2022-10-20 14:40:18 +00:00
}
return [ 'error' => JText :: _ ( 'COM_COMPONENTBUILDER_THERE_HAS_BEEN_AN_ERROR_PLEASE_TRY_AGAIN' )];
}
/**
* Get a replaced search value from a given table and row
*
* @ param string $fieldName The field key
* @ param int $rowId The item ID
* @ param mixed $line The line line
* @ param string $tableName The table
* @ param string $searchValue The value to search for
* @ param string | null $replaceValue The value to replace search value
* @ param int $matchCase The switch to control match case
* @ param int $wholeWord The switch to control whole word
* @ param int $regexSearch The switch to control regex search
*
* @ return array
* @ since 3.2 . 0
**/
public function getReplaceValue ( string $fieldName , int $rowId , $line , string $tableName ,
string $searchValue , ? string $replaceValue = null , int $matchCase , int $wholeWord , int $regexSearch ) : array
{
// check if this is a valid table and field
2022-10-30 22:34:54 +00:00
if ( $rowId > 0 && SearchFactory :: _ ( 'Table' ) -> exist ( $tableName , $fieldName ))
2022-10-20 14:40:18 +00:00
{
2022-11-02 19:48:20 +00:00
try
{
// load the configurations
SearchFactory :: _ ( 'Config' ) -> table_name = $tableName ;
SearchFactory :: _ ( 'Config' ) -> type_search = 2 ;
SearchFactory :: _ ( 'Config' ) -> search_value = $searchValue ;
SearchFactory :: _ ( 'Config' ) -> replace_value = $replaceValue ;
SearchFactory :: _ ( 'Config' ) -> match_case = $matchCase ;
SearchFactory :: _ ( 'Config' ) -> whole_word = $wholeWord ;
SearchFactory :: _ ( 'Config' ) -> regex_search = $regexSearch ;
2022-10-20 14:40:18 +00:00
2022-11-02 19:48:20 +00:00
// load the value
if (( $value = SearchFactory :: _ ( 'Agent' ) -> getValue ( $rowId , $fieldName , $line , $tableName , true )) !== null )
{
return [ 'value' => $value ];
}
}
catch ( Exception $error )
2022-10-20 14:40:18 +00:00
{
2022-11-02 19:48:20 +00:00
return [ 'error' => $error -> getMessage ()];
2022-10-20 14:40:18 +00:00
}
}
return [ 'error' => JText :: _ ( 'COM_COMPONENTBUILDER_THERE_HAS_BEEN_AN_ERROR_PLEASE_TRY_AGAIN' )];
}
/**
* Set selected search value in a given table and row
*
* @ param mixed $value The field value
* @ param int $rowId The item ID
* @ param string $fieldName The field key
* @ param string $tableName The table
*
* @ return array
* @ since 3.2 . 0
**/
public function setValue ( $value , int $rowId , string $fieldName , string $tableName ) : array
{
// check if this is a valid table and field
2022-10-30 22:34:54 +00:00
if ( $rowId > 0 && SearchFactory :: _ ( 'Table' ) -> exist ( $tableName , $fieldName ) &&
SearchFactory :: _ ( 'Agent' ) -> setValue ( $value , $rowId , $fieldName , $tableName ))
2022-10-20 14:40:18 +00:00
{
return [ 'success' => JText :: sprintf (
'<b>%s</b> (%s:%s) was successfully updated!' ,
$tableName , $rowId , $fieldName )];
}
return [ 'error' => JText :: _ ( 'COM_COMPONENTBUILDER_THERE_HAS_BEEN_AN_ERROR_PLEASE_TRY_AGAIN' )];
}
2022-09-14 15:40:02 +00:00
2018-01-15 15:54:05 +00:00
// Used in get_snippets
2018-02-27 12:17:38 +00:00
2018-01-15 15:54:05 +00:00
public function getSnippets ( $libraries )
{
2023-10-18 07:26:30 +00:00
if ( JsonHelper :: check ( $libraries ))
2018-01-15 15:54:05 +00:00
{
$libraries = json_decode ( $libraries , true );
}
// check if we have an array
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $libraries ))
2018-01-15 15:54:05 +00:00
{
// insure we only have int values
if ( $libraries = $this -> checkLibraries ( $libraries ))
{
// Get a db connection.
$db = JFactory :: getDbo ();
// Create a new query object.
$query = $db -> getQuery ( true );
$query -> select ( $db -> quoteName ( array ( 'a.id' ) ));
$query -> from ( $db -> quoteName ( '#__componentbuilder_snippet' , 'a' ));
$query -> where ( $db -> quoteName ( 'a.published' ) . ' = 1' );
// check for country and region
$query -> where ( $db -> quoteName ( 'a.library' ) . ' IN (' . implode ( ',' , $libraries ) . ')' );
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
{
return $db -> loadColumn ();
}
}
}
return false ;
}
protected function checkLibraries ( $libraries )
{
$bucket = array ();
$libraries = array_map ( function ( $id ) use ( & $bucket ) {
// now get bundled libraries
$type = ComponentbuilderHelper :: getVar ( 'library' , ( int ) $id , 'id' , 'type' );
if ( 2 == $type && $bundled = ComponentbuilderHelper :: getVar ( 'library' , ( int ) $id , 'id' , 'libraries' ))
{
// make sure we have an array if it was json
2023-10-18 07:26:30 +00:00
if ( JsonHelper :: check ( $bundled ))
2018-01-15 15:54:05 +00:00
{
$bundled = json_decode ( $bundled , true );
}
// load in the values if we have an array
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $bundled ))
2018-01-15 15:54:05 +00:00
{
foreach ( $bundled as $lib )
{
$bucket [ $lib ] = $lib ;
}
}
elseif ( is_numeric ( $bundled ))
{
$bucket [( int ) $bundled ] = ( int ) $bundled ;
}
}
else
{
return ( int ) $id ;
}
}, $libraries );
// check if we have any bundled libraries
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $bucket ))
2018-01-15 15:54:05 +00:00
{
foreach ( $bucket as $lib )
{
$libraries [] = ( int ) $lib ;
}
}
// check that we have libraries
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $libraries ))
2018-01-15 15:54:05 +00:00
{
$libraries = array_values ( array_unique ( array_filter ( $libraries , function ( $id ){ return is_int ( $id );})));
// check if we have any libraries remaining
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $libraries ))
2018-01-15 15:54:05 +00:00
{
return $libraries ;
}
}
return false ;
2018-02-27 12:17:38 +00:00
}
2017-10-06 14:53:22 +00:00
public function getSnippetDetails ( $id )
{
// Get a db connection.
$db = JFactory :: getDbo ();
// Create a new query object.
$query = $db -> getQuery ( true );
2017-11-16 04:37:32 +00:00
$query -> select ( $db -> quoteName ( array ( 'a.name' , 'a.heading' , 'a.usage' , 'a.description' , 'b.name' , 'a.snippet' , 'a.url' , 'c.name' ), array ( 'name' , 'heading' , 'usage' , 'description' , 'type' , 'snippet' , 'url' , 'library' )));
$query -> from ( $db -> quoteName ( '#__componentbuilder_snippet' , 'a' ));
// From the componentbuilder_snippet_type table.
$query -> join ( 'LEFT' , $db -> quoteName ( '#__componentbuilder_snippet_type' , 'b' ) . ' ON (' . $db -> quoteName ( 'a.type' ) . ' = ' . $db -> quoteName ( 'b.id' ) . ')' );
// From the componentbuilder_library table.
$query -> join ( 'LEFT' , $db -> quoteName ( '#__componentbuilder_library' , 'c' ) . ' ON (' . $db -> quoteName ( 'a.library' ) . ' = ' . $db -> quoteName ( 'c.id' ) . ')' );
$query -> where ( $db -> quoteName ( 'a.published' ) . ' >= 1' );
$query -> where ( $db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $id );
2017-10-06 14:53:22 +00:00
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
{
$snippet = $db -> loadObject ();
2017-11-16 04:37:32 +00:00
$snippet -> snippet = base64_decode ( $snippet -> snippet );
2017-10-06 14:53:22 +00:00
// return found snippet settings
return $snippet ;
}
return false ;
2017-11-17 16:18:47 +00:00
}
public function setSnippetGithub ( $path , $status )
{
// get user
$user = JFactory :: getUser ();
$access = $user -> authorise ( 'snippet.access' , 'com_componentbuilder' );
if ( $access )
{
// secure path
2023-10-18 07:26:30 +00:00
$path = StringHelper :: safe ( str_replace ( '.json' , '' , $path ), 'filename' , '' , false ) . '.json' ;
2019-09-10 16:47:39 +00:00
// base path
$base_path = basename ( $path );
2017-11-17 16:18:47 +00:00
// set url
2019-09-10 16:47:39 +00:00
$url = ComponentbuilderHelper :: $snippetPath . rawurlencode ( $base_path );
2017-11-17 16:18:47 +00:00
// get the snippets
2020-01-05 21:19:20 +00:00
if (( $snippet = ComponentbuilderHelper :: getGithubRepoData ( 'lib_snippet_' . $base_path , $url , null , 'array' )) !== false )
2017-11-17 16:18:47 +00:00
{
2019-09-10 16:47:39 +00:00
return $this -> saveSnippet ( $snippet , $status , $user );
2017-11-17 16:18:47 +00:00
}
2020-01-05 21:19:20 +00:00
// see if we have any errors from github
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( ComponentbuilderHelper :: $githubRepoDataErrors ))
2020-01-05 21:19:20 +00:00
{
return array ( 'message' => JText :: sprintf ( 'COM_COMPONENTBUILDER_ERROR_BR_S' , implode ( '<br />' , ComponentbuilderHelper :: $githubRepoDataErrors )), 'status' => 'danger' );
}
2017-11-17 16:18:47 +00:00
return array ( 'message' => JText :: _ ( 'COM_COMPONENTBUILDER_ERROR_THE_PATH_HAS_A_MISMATCH_AND_COULD_THEREFORE_NOT_RETRIEVE_THE_SNIPPET_FROM_GITHUB' ), 'status' => 'danger' );
}
return array ( 'message' => JText :: _ ( 'COM_COMPONENTBUILDER_ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THE_SNIPPETS' ), 'status' => 'danger' );
}
protected function saveSnippet ( $item , $status , $user )
{
// set some defaults
$todayDate = JFactory :: getDate () -> toSql ();
// get the type id
$item [ 'type' ] = ( $id = ComponentbuilderHelper :: getVar ( 'snippet_type' , $item [ 'type' ], 'name' , 'id' )) ? $id : $this -> createNew ( $item [ 'type' ], 'snippet_type' , $user , $todayDate );
// get the library id
$item [ 'library' ] = ( $id = ComponentbuilderHelper :: getVar ( 'library' , $item [ 'library' ], 'name' , 'id' )) ? $id : $this -> createNew ( $item [ 'library' ], 'library' , $user , $todayDate );
// remove type if zero
if ( $item [ 'type' ] == 0 )
{
unset ( $item [ 'type' ]);
}
// remove library if zero
if ( $item [ 'library' ] == 0 )
{
unset ( $item [ 'library' ]);
}
// get the snippet ID
$item [ 'id' ] = $this -> getSnippetId ( $item );
if ( $item [ 'id' ] == 0 )
{
$canCreate = $user -> authorise ( 'snippet.create' , 'com_componentbuilder' );
if ( 'new' === $status && ! $canCreate )
{
return array ( 'message' => JText :: _ ( 'COM_COMPONENTBUILDER_ERROR_YOU_DO_NOT_HAVE_PERMISSION_TO_CREATE_THE_SNIPPET' ), 'status' => 'danger' );
}
}
// get the snippet model
$model = ComponentbuilderHelper :: getModel ( 'snippet' , JPATH_COMPONENT_ADMINISTRATOR );
// save the snippet
if ( $model -> save ( $item ))
{
if ( $item [ 'id' ] == 0 )
{
// get the saved item
$updatedItem = $model -> getItem ();
$item [ 'id' ] = $updatedItem -> get ( 'id' );
}
// we have to force modified date since the model does not allow you
if ( $this -> forchDateFix ( $item ))
{
return array ( 'message' => JText :: _ ( 'COM_COMPONENTBUILDER_SUCCESS_THE_SNIPPET_WAS_SAVED' ), 'status' => 'success' );
}
// return error
return array ( 'message' => JText :: _ ( 'COM_COMPONENTBUILDER_SUCCESS_THE_SNIPPET_WAS_SAVED_BUT_THE_MODIFIED_DATE_COULD_NOT_BE_ADJUSTED_BR_BR_BTHIS_MEANS_THE_SNIPPETS_WILL_CONTINUE_TO_APPEAR_OUT_OF_DATEB' ), 'status' => 'warning' );
}
// return error
return array ( 'message' => JText :: _ ( 'COM_COMPONENTBUILDER_ERROR_THE_SNIPPET_IS_FAULTY_AND_COULD_NOT_BE_SAVED' ), 'status' => 'danger' );
}
protected function forchDateFix ( $item )
{
$object = new stdClass ();
$object -> id = ( int ) $item [ 'id' ];
$object -> created = $item [ 'created' ];
$object -> modified = $item [ 'modified' ];
// force update
return JFactory :: getDbo () -> updateObject ( '#__componentbuilder_snippet' , $object , 'id' );
}
protected function getSnippetId ( $item )
{
// Get a db connection.
$db = JFactory :: getDbo ();
// Create a new query object.
$query = $db -> getQuery ( true );
$query -> select ( $db -> quoteName ( array ( 'a.id' )));
$query -> from ( $db -> quoteName ( '#__componentbuilder_snippet' , 'a' ));
$query -> where ( $db -> quoteName ( 'a.name' ) . ' = ' . ( string ) $db -> quote ( $item [ 'name' ]));
if ( is_numeric ( $item [ 'type' ]))
{
$query -> where ( $db -> quoteName ( 'a.type' ) . ' = ' . ( int ) $item [ 'type' ]);
}
if ( is_numeric ( $item [ 'library' ]))
{
$query -> where ( $db -> quoteName ( 'a.library' ) . ' = ' . ( int ) $item [ 'library' ]);
}
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
{
return $db -> loadResult ();
}
return 0 ;
}
protected function createNew ( $name , $type , $user , $todayDate )
{
// verify that we can continue
if ( ComponentbuilderHelper :: getActions ( $type ) -> get ( 'core.create' ))
{
// get the snippet model
$model = ComponentbuilderHelper :: getModel ( $type , JPATH_COMPONENT_ADMINISTRATOR );
// build array to save
$item [ 'id' ] = 0 ;
$item [ 'name' ] = $name ;
$item [ 'published' ] = 1 ;
$item [ 'version' ] = 1 ;
$item [ 'created' ] = $todayDate ;
$item [ 'created_by' ] = $user -> id ;
// save the new
$model -> save ( $item );
// get the saved item
$item = $model -> getItem ();
return $item -> get ( 'id' );
}
return 0 ;
2021-03-05 03:08:47 +00:00
}
}