AAAAhome/academiac/www/libraries/joomla/form/rules/rules.php 0000644 00000006656 15137266545 0017437 0 ustar 00 tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param object &$input An optional JRegistry object with the entire data set to validate against the entire form.
* @param object &$form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 11.1
* @throws JException on invalid rule.
*/
public function test(&$element, $value, $group = null, &$input = null, &$form = null)
{
// Get the possible field actions and the ones posted to validate them.
$fieldActions = self::getFieldActions($element);
$valueActions = self::getValueActions($value);
// Make sure that all posted actions are in the list of possible actions for the field.
foreach ($valueActions as $action)
{
if (!in_array($action, $fieldActions))
{
return false;
}
}
return true;
}
/**
* Method to get the list of permission action names from the form field value.
*
* @param mixed $value The form field value to validate.
*
* @return array A list of permission action names from the form field value.
*
* @since 11.1
*/
protected function getValueActions($value)
{
// Initialise variables.
$actions = array();
// Iterate over the asset actions and add to the actions.
foreach ((array) $value as $name => $rules)
{
$actions[] = $name;
}
return $actions;
}
/**
* Method to get the list of possible permission action names for the form field.
*
* @param object $element The SimpleXMLElement object representing the tag for the
* form field object.
*
* @return array A list of permission action names from the form field element definition.
*
* @since 11.1
*/
protected function getFieldActions($element)
{
// Initialise variables.
$actions = array();
// Initialise some field attributes.
$section = $element['section'] ? (string) $element['section'] : '';
$component = $element['component'] ? (string) $element['component'] : '';
// Get the asset actions for the element.
$elActions = JAccess::getActions($component, $section);
// Iterate over the asset actions and add to the actions.
foreach ($elActions as $item)
{
$actions[] = $item->name;
}
// Iterate over the children and add to the actions.
foreach ($element->children() as $el)
{
if ($el->getName() == 'action')
{
$actions[] = (string) $el['name'];
}
}
return $actions;
}
}
home/academiac/www/libraries/joomla/access/rules.php 0000644 00000012327 15137273666 0016575 0 ustar 00 array(-42 => true, 3 => true, 4 => false))
* or an equivalent JSON encoded string, or an object where properties are arrays.
*
* @param mixed $input A JSON format string (probably from the database) or a nested array.
*
* @since 11.1
*/
public function __construct($input = '')
{
// Convert in input to an array.
if (is_string($input))
{
$input = json_decode($input, true);
}
elseif (is_object($input))
{
$input = (array) $input;
}
if (is_array($input))
{
// Top level keys represent the actions.
foreach ($input as $action => $identities)
{
$this->mergeAction($action, $identities);
}
}
}
/**
* Get the data for the action.
*
* @return array A named array of JAccessRule objects.
*
* @since 11.1
*/
public function getData()
{
return $this->data;
}
/**
* Method to merge a collection of JAccessRules.
*
* @param mixed $input JAccessRule or array of JAccessRules
*
* @return void
*
* @since 11.1
*/
public function mergeCollection($input)
{
// Check if the input is an array.
if (is_array($input))
{
foreach ($input as $actions)
{
$this->merge($actions);
}
}
}
/**
* Method to merge actions with this object.
*
* @param mixed $actions JAccessRule object, an array of actions or a JSON string array of actions.
*
* @return void
*
* @since 11.1
*/
public function merge($actions)
{
if (is_string($actions))
{
$actions = json_decode($actions, true);
}
if (is_array($actions))
{
foreach ($actions as $action => $identities)
{
$this->mergeAction($action, $identities);
}
}
elseif ($actions instanceof JAccessRules)
{
$data = $actions->getData();
foreach ($data as $name => $identities)
{
$this->mergeAction($name, $identities);
}
}
}
/**
* Merges an array of identities for an action.
*
* @param string $action The name of the action.
* @param array $identities An array of identities
*
* @return void
*
* @since 11.1
*/
public function mergeAction($action, $identities)
{
if (isset($this->data[$action]))
{
// If exists, merge the action.
$this->data[$action]->mergeIdentities($identities);
}
else
{
// If new, add the action.
$this->data[$action] = new JAccessRule($identities);
}
}
/**
* Checks that an action can be performed by an identity.
*
* The identity is an integer where +ve represents a user group,
* and -ve represents a user.
*
* @param string $action The name of the action.
* @param mixed $identity An integer representing the identity, or an array of identities
*
* @return mixed Object or null if there is no information about the action.
*
* @since 11.1
*/
public function allow($action, $identity)
{
// Check we have information about this action.
if (isset($this->data[$action]))
{
return $this->data[$action]->allow($identity);
}
return null;
}
/**
* Get the allowed actions for an identity.
*
* @param mixed $identity An integer representing the identity or an array of identities
*
* @return object Allowed actions for the identity or identities
*
* @since 11.1
*/
public function getAllowed($identity)
{
// Sweep for the allowed actions.
$allowed = new JObject;
foreach ($this->data as $name => &$action)
{
if ($action->allow($identity))
{
$allowed->set($name, true);
}
}
return $allowed;
}
/**
* Magic method to convert the object to JSON string representation.
*
* @return string JSON representation of the actions array
*
* @since 11.1
*/
public function __toString()
{
$temp = array();
foreach ($this->data as $name => $rule)
{
// Convert the action to JSON, then back into an array otherwise
// re-encoding will quote the JSON for the identities in the action.
$temp[$name] = json_decode((string) $rule);
}
return json_encode($temp);
}
}
/**
* Deprecated class placeholder. You should use JAccessRules instead.
*
* @package Joomla.Platform
* @subpackage Access
* @since 11.1
* @deprecated 12.3
*/
class JRules extends JAccessRules
{
/**
* Constructor.
*
* The input array must be in the form: array('action' => array(-42 => true, 3 => true, 4 => false))
* or an equivalent JSON encoded string, or an object where properties are arrays.
*
* @param mixed $input A JSON format string (probably from the database) or a nested array.
*
* @since 11.1
* @deprecated 12.3
*/
public function __construct($input = '')
{
JLog::add('JRules is deprecated. Use JAccessRules instead.', JLog::WARNING, 'deprecated');
parent::__construct($input);
}
}
home/academiac/www/libraries/joomla/html/html/rules.php 0000644 00000017731 15137274056 0017242 0 ustar 00 ';
$html[] = JHtml::_('tabs.start', 'acl-rules-' . $assetId, array('useCookie' => 1));
$html[] = JHtml::_('tabs.panel', JText::_('JLIB_HTML_ACCESS_SUMMARY'), 'summary');
$html[] = '
';
}
$html[] = JHtml::_('tabs.end');
// Build the footer with legend and special purpose buttons.
$html[] = ' ';
$html[] = '
';
$html[] = '
' . JText::_('JLIB_RULES_ALLOWED') . '
';
$html[] = '
' . JText::_('JLIB_RULES_DENIED') . '
';
$html[] = '
';
$html[] = '';
return implode("\n", $html);
}
/**
* Get the id of the parent asset
*
* @param integer $assetId The asset for which the parentid will be returned
*
* @return integer The id of the parent asset
*
* @since 11.1
*/
protected static function _getParentAssetId($assetId)
{
// Get a database object.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
// Get the user groups from the database.
$query->select($db->quoteName('parent_id'));
$query->from($db->quoteName('#__assets'));
$query->where($db->quoteName('id') . ' = ' . (int) $assetId);
$db->setQuery($query);
return (int) $db->loadResult();
}
/**
* Get the user groups
*
* @return array Array of user groups
*
* @since 11.1
*/
protected static function _getUserGroups()
{
// Get a database object.
$db = JFactory::getDBO();
// Get the user groups from the database.
$db->setQuery(
'SELECT a.id AS value, a.title AS text, b.id as parent'
. ' FROM #__usergroups AS a' . ' LEFT JOIN #__usergroups AS b ON a.lft >= b.lft AND a.rgt <= b.rgt'
. ' ORDER BY a.lft ASC, b.lft ASC'
);
$result = $db->loadObjectList();
$options = array();
// Pre-compute additional values.
foreach ($result as $option)
{
$end = end($options);
if ($end === false || $end->value != $option->value)
{
$end = $option;
$end->level = 0;
$options[] = $end;
}
else
{
$end->level++;
}
$end->identities[] = $option->parent;
}
return $options;
}
/**
* Get the array of images associate with specific permissions
*
* @return array An associative array of permissions and images
*
* @since 11.1
*/
protected static function _getImagesArray()
{
$images['allow-l'] = '';
$images['deny-l'] = '';
$images['allow'] = '';
$images['deny'] = '';
$images['allow-i'] = '';
$images['deny-i'] = '';
return $images;
}
}