-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathlog.php
More file actions
161 lines (141 loc) · 3.89 KB
/
log.php
File metadata and controls
161 lines (141 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/**
* @package Com.Api
*
* @copyright Copyright (C) 2005 - 2017 Techjoomla, Techjoomla Pvt. Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access
defined('_JEXEC') or die();
use Joomla\CMS\Table\Table;
use Joomla\Data\DataObject;
use Joomla\CMS\Factory;
use Joomla\Registry\Registry;
use Joomla\CMS\Access\Access;
use Joomla\Utilities\ArrayHelper;
/**
* Log Table class
*
* @since 1.0
*/
class ApiTablelog extends Table
{
/**
* Constructor
*
* @param DataObjectbaseDriver &$db Database object
*
* @since 1.0
*/
public function __construct(&$db)
{
parent::__construct('#__api_logs', 'id', $db);
}
/**
* Method to bind an associative array or object to the Table instance.This
* method only binds properties that are publicly accessible and optionally
* takes an array of properties to ignore when binding.
*
* @param array|object $array An associative array or object to bind to the Table instance.
* @param array|string $ignore An optional array or space separated list of properties to ignore while binding.
*
* @return boolean True on success.
*
* @since 1.0
* @throws \InvalidArgumentException
*/
public function bind($array, $ignore = '')
{
$input = Factory::getApplication()->input;
$task = $input->getString('task', '');
if ($array['id'] == 0)
{
$array['created_by'] = Factory::getUser()->id;
}
if (isset($array['params']) && is_array($array['params']))
{
$registry = new Registry;
$registry->loadArray($array['params']);
$array['params'] = (string) $registry;
}
if (isset($array['metadata']) && is_array($array['metadata']))
{
$registry = new Registry;
$registry->loadArray($array['metadata']);
$array['metadata'] = (string) $registry;
}
if (! Factory::getUser()->authorise('core.admin', 'com_api.key.' . $array['id']))
{
$actions = Access::getActionsFromFile(JPATH_ADMINISTRATOR . '/components/com_api/access.xml', "/access/section[@name='key']/");
$defaultActions = Access::getAssetRules('com_api.key.' . $array['id'])->getData();
$arrayJaccess = array();
foreach ($actions as $action)
{
$arrayJaccess[$action->name] = $defaultActions[$action->name];
}
$array['rules'] = $this->RulestoArray($arrayJaccess);
}
// Bind the rules for ACL where supported.
if (isset($array['rules']) && is_array($array['rules']))
{
$this->setRules($array['rules']);
}
return parent::bind($array, $ignore);
}
/**
* This function convert an array of Rule objects into an rules array.
*
* @param array $jaccessrules an array of Rule objects.
*
* @return array
*
* @since 1.0
*/
private function RulestoArray($jaccessrules)
{
$rules = array();
foreach ($jaccessrules as $action => $jaccess)
{
$actions = array();
foreach ($jaccess->getData() as $group => $allow)
{
$actions[$group] = ((bool) $allow);
}
$rules[$action] = $actions;
}
return $rules;
}
/**
* Method to store a row in the database from the Table instance properties.
*
* If a primary key value is set the row with that primary key value will be updated with the instance property values.
* If no primary key value is set a new row will be inserted into the database with the properties from the Table instance.
*
* @param boolean $updateNulls True to update fields even if they are null.
*
* @return boolean True on success.
*
* @since 1.0
*/
public function store($updateNulls = false)
{
if (is_array($this->post_data))
{
$this->post_data = ArrayHelper::toString($this->post_data, '=', '&');
}
return parent::store($updateNulls = false);
}
/**
* Method to load an asset by its name.
*
* @param string $hash The hash of the record.
*
* @return void
*
* @since 1.0
*/
public function loadByHash($hash)
{
$this->load(array('hash' => $hash));
}
}