Major improment to user helper methods. Fixed custom field building options to allow options to be set. Fixed gh-569 to use correct paths in module custom fields and rules. Imporved the fancy date helper methods. Added the new Text::_() languange string search for language strings. Add the option to add header custom code to custom fields.

This commit is contained in:
2020-07-07 17:13:04 +02:00
parent e86ab88f5c
commit 354565d96a
24 changed files with 2242 additions and 1755 deletions

View File

@ -5535,14 +5535,61 @@ abstract class ComponentbuilderHelper
*
*/
public static function getEditURL(&$item, $view, $views, $ref = '', $component = 'com_componentbuilder', $jRoute = true)
{
// build record
$record = new stdClass();
// check if user can edit
if (self::canEditItem($record, $item, $view, $views, $component))
{
// set the edit link
if ($jRoute)
{
return JRoute::_("index.php?option=" . $component . "&view=" . $views . "&task=" . $view . ".edit&id=" . $record->id . $ref);
}
return "index.php?option=" . $component . "&view=" . $views . "&task=" . $view . ".edit&id=" . $record->id . $ref;
}
return false;
}
/**
* Can Edit (either any, or own)
*
* @param int $item The item to edit
* @param string $view The type of item to edit
* @param string $views The list view controller name
* @param string $component The component these views belong to
*
* @return bool if user can edit returns true els
*
*/
public static function allowEdit(&$item, $view, $views, $component = 'com_componentbuilder')
{
// build record
$record = new stdClass();
return self::canEditItem($record, $item, $view, $views, $component);
}
/**
* Can Edit (either any, or own)
*
* @param int $item The item to edit
* @param string $view The type of item to edit
* @param string $views The list view controller name
* @param string $component The component these views belong to
*
* @return bool if user can edit returns true els
*
*/
protected static function canEditItem(&$record, &$item, $view, $views, $component = 'com_componentbuilder')
{
// make sure the user has access to view
if (!JFactory::getUser()->authorise($view. '.access', $component))
{
return false;
}
// build record
$record = new stdClass();
// we start with false.
$can_edit = false;
// check that we have the ID
if (self::checkObject($item) && isset($item->id))
{
@ -5572,25 +5619,14 @@ abstract class ComponentbuilderHelper
// get user action permission to edit
$action = self::getActions($view, $record, $views, 'edit', str_replace('com_', '', $component));
// check if the view permission is set
if (($edit = $action->get($view . '.edit', 'none-set')) === 'none-set')
if (($can_edit = $action->get($view . '.edit', 'none-set')) === 'none-set')
{
// fall back on the core permission then
$edit = $action->get('core.edit', 'none-set');
}
// can edit
if ($edit)
{
// set the edit link
if ($jRoute)
{
return JRoute::_("index.php?option=" . $component . "&view=" . $views . "&task=" . $view . ".edit&id=" . $record->id . $ref);
}
return "index.php?option=" . $component . "&view=" . $views . "&task=" . $view . ".edit&id=" . $record->id . $ref;
// fall back on the core permission then (this can be an issue)
$can_edit = ($action->get('core.edit', false) || $action->get('core.edit.own', false));
}
}
return false;
return $can_edit;
}
/**
* set subform type table
@ -5633,9 +5669,9 @@ abstract class ComponentbuilderHelper
/**
* Change to nice fancy date
*/
public static function fancyDate($date)
public static function fancyDate($date, $check_stamp = true)
{
if (!self::isValidTimeStamp($date))
if ($check_stamp && !self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
@ -5645,9 +5681,9 @@ abstract class ComponentbuilderHelper
/**
* get date based in period past
*/
public static function fancyDynamicDate($date)
public static function fancyDynamicDate($date, $check_stamp = true)
{
if (!self::isValidTimeStamp($date))
if ($check_stamp && !self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
@ -5671,9 +5707,9 @@ abstract class ComponentbuilderHelper
/**
* Change to nice fancy day time and date
*/
public static function fancyDayTimeDate($time)
public static function fancyDayTimeDate($time, $check_stamp = true)
{
if (!self::isValidTimeStamp($time))
if ($check_stamp && !self::isValidTimeStamp($time))
{
$time = strtotime($time);
}
@ -5683,9 +5719,9 @@ abstract class ComponentbuilderHelper
/**
* Change to nice fancy time and date
*/
public static function fancyDateTime($time)
public static function fancyDateTime($time, $check_stamp = true)
{
if (!self::isValidTimeStamp($time))
if ($check_stamp && !self::isValidTimeStamp($time))
{
$time = strtotime($time);
}
@ -5695,9 +5731,9 @@ abstract class ComponentbuilderHelper
/**
* Change to nice hour:minutes time
*/
public static function fancyTime($time)
public static function fancyTime($time, $check_stamp = true)
{
if (!self::isValidTimeStamp($time))
if ($check_stamp && !self::isValidTimeStamp($time))
{
$time = strtotime($time);
}
@ -5707,9 +5743,9 @@ abstract class ComponentbuilderHelper
/**
* set the date day as Sunday through Saturday
*/
public static function setDayName($date)
public static function setDayName($date, $check_stamp = true)
{
if (!self::isValidTimeStamp($date))
if ($check_stamp && !self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
@ -5719,9 +5755,9 @@ abstract class ComponentbuilderHelper
/**
* set the date month as January through December
*/
public static function setMonthName($date)
public static function setMonthName($date, $check_stamp = true)
{
if (!self::isValidTimeStamp($date))
if ($check_stamp && !self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
@ -5731,9 +5767,9 @@ abstract class ComponentbuilderHelper
/**
* set the date day as 1st
*/
public static function setDay($date)
public static function setDay($date, $check_stamp = true)
{
if (!self::isValidTimeStamp($date))
if ($check_stamp && !self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
@ -5743,9 +5779,9 @@ abstract class ComponentbuilderHelper
/**
* set the date month as 5
*/
public static function setMonth($date)
public static function setMonth($date, $check_stamp = true)
{
if (!self::isValidTimeStamp($date))
if ($check_stamp && !self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
@ -5755,9 +5791,9 @@ abstract class ComponentbuilderHelper
/**
* set the date year as 2004 (for charts)
*/
public static function setYear($date)
public static function setYear($date, $check_stamp = true)
{
if (!self::isValidTimeStamp($date))
if ($check_stamp && !self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
@ -5767,9 +5803,9 @@ abstract class ComponentbuilderHelper
/**
* set the date as 2004/05 (for charts)
*/
public static function setYearMonth($date, $spacer = '/')
public static function setYearMonth($date, $spacer = '/', $check_stamp = true)
{
if (!self::isValidTimeStamp($date))
if ($check_stamp && !self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
@ -5779,9 +5815,9 @@ abstract class ComponentbuilderHelper
/**
* set the date as 2004/05/03 (for charts)
*/
public static function setYearMonthDay($date, $spacer = '/')
public static function setYearMonthDay($date, $spacer = '/', $check_stamp = true)
{
if (!self::isValidTimeStamp($date))
if ($check_stamp && !self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
@ -5791,9 +5827,9 @@ abstract class ComponentbuilderHelper
/**
* set the date as 03/05/2004
*/
public static function setDayMonthYear($date, $spacer = '/')
public static function setDayMonthYear($date, $spacer = '/', $check_stamp = true)
{
if (!self::isValidTimeStamp($date))
if ($check_stamp && !self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
@ -5810,6 +5846,16 @@ abstract class ComponentbuilderHelper
&& ($timestamp >= ~PHP_INT_MAX);
}
/**
* Check if string is a valid date
* https://www.php.net/manual/en/function.checkdate.php#113205
*/
public static function isValidateDate($date, $format = 'Y-m-d H:i:s')
{
$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
/**
* Load the Composer Vendors