@@ -3,20 +3,20 @@ |
||
3 | 3 | class ACL_Roles extends Records |
4 | 4 | { |
5 | 5 | |
6 | - protected $_hasMany = array("Users"); |
|
6 | + protected $_hasMany = array("Users"); |
|
7 | 7 | |
8 | - /** |
|
9 | - * Singleton |
|
10 | - * |
|
11 | - * @return ACL_Roles |
|
12 | - */ |
|
13 | - public static function instance() |
|
14 | - { |
|
15 | - static $instance; |
|
16 | - if (!($instance instanceof self)) { |
|
17 | - $instance = new self(); |
|
18 | - } |
|
19 | - return $instance; |
|
20 | - } |
|
8 | + /** |
|
9 | + * Singleton |
|
10 | + * |
|
11 | + * @return ACL_Roles |
|
12 | + */ |
|
13 | + public static function instance() |
|
14 | + { |
|
15 | + static $instance; |
|
16 | + if (!($instance instanceof self)) { |
|
17 | + $instance = new self(); |
|
18 | + } |
|
19 | + return $instance; |
|
20 | + } |
|
21 | 21 | |
22 | 22 | } |
23 | 23 | \ No newline at end of file |
@@ -3,91 +3,91 @@ |
||
3 | 3 | class ACL_Role extends Record |
4 | 4 | { |
5 | 5 | |
6 | - public function insert() |
|
7 | - { |
|
8 | - parent::insert(); |
|
9 | - $this->insertPermissions(); |
|
10 | - } |
|
11 | - |
|
12 | - public function update($permissions = true) |
|
13 | - { |
|
14 | - if ($permissions) { |
|
15 | - $this->updatePermissions(); |
|
16 | - } |
|
17 | - parent::update(); |
|
18 | - } |
|
19 | - |
|
20 | - public function delete() |
|
21 | - { |
|
22 | - $this->deletePermissions(); |
|
23 | - $this->deleteUsers(); |
|
24 | - parent::delete(); |
|
25 | - } |
|
26 | - |
|
27 | - public function insertPermission($resource, $type) |
|
28 | - { |
|
29 | - $this->getACL()->insertPermission($resource, $this, $type); |
|
30 | - } |
|
31 | - |
|
32 | - public function insertPermissions() |
|
33 | - { |
|
34 | - if ($this->permissions) { |
|
35 | - foreach ($this->permissions as $resource => $types) { |
|
36 | - foreach ($types as $type => $value) { |
|
37 | - if (!$this->allowed($resource, $type)) { |
|
38 | - $this->getACL()->insertPermission($resource, $this, $type); |
|
39 | - } |
|
40 | - } |
|
41 | - } |
|
42 | - } |
|
43 | - return $this; |
|
44 | - } |
|
45 | - |
|
46 | - public function deletePermissions($resource = false) |
|
47 | - { |
|
48 | - $this->getACL()->removePermissions($this, $resource); |
|
49 | - return $this; |
|
50 | - } |
|
51 | - |
|
52 | - public function updatePermissions() |
|
53 | - { |
|
54 | - $this->deletePermissions(); |
|
55 | - $this->insertPermissions(); |
|
56 | - } |
|
57 | - |
|
58 | - public function allowed($resource, $type) |
|
59 | - { |
|
60 | - return $this->getACL()->check($this, $resource, $type); |
|
61 | - } |
|
62 | - |
|
63 | - public function getACL() |
|
64 | - { |
|
65 | - return ACL::instance(); |
|
66 | - } |
|
67 | - |
|
68 | - public function getRoleID() |
|
69 | - { |
|
70 | - return get_class($this) . "." . $this->id; |
|
71 | - } |
|
72 | - |
|
73 | - public function validate($request = array()) |
|
74 | - { |
|
75 | - $this->name = clean($request['name']); |
|
76 | - $this->permissions = $request['permission'] ? $request['permission'] : array(); |
|
77 | - |
|
78 | - $errors = array(); |
|
79 | - |
|
80 | - if (!$this->name) { |
|
81 | - $errors['name'] = 'Denumirea este obligatorie'; |
|
82 | - } |
|
83 | - |
|
84 | - $this->errors = $errors; |
|
85 | - |
|
86 | - if ($this->errors) { |
|
87 | - return false; |
|
88 | - } |
|
89 | - |
|
90 | - return true; |
|
91 | - } |
|
6 | + public function insert() |
|
7 | + { |
|
8 | + parent::insert(); |
|
9 | + $this->insertPermissions(); |
|
10 | + } |
|
11 | + |
|
12 | + public function update($permissions = true) |
|
13 | + { |
|
14 | + if ($permissions) { |
|
15 | + $this->updatePermissions(); |
|
16 | + } |
|
17 | + parent::update(); |
|
18 | + } |
|
19 | + |
|
20 | + public function delete() |
|
21 | + { |
|
22 | + $this->deletePermissions(); |
|
23 | + $this->deleteUsers(); |
|
24 | + parent::delete(); |
|
25 | + } |
|
26 | + |
|
27 | + public function insertPermission($resource, $type) |
|
28 | + { |
|
29 | + $this->getACL()->insertPermission($resource, $this, $type); |
|
30 | + } |
|
31 | + |
|
32 | + public function insertPermissions() |
|
33 | + { |
|
34 | + if ($this->permissions) { |
|
35 | + foreach ($this->permissions as $resource => $types) { |
|
36 | + foreach ($types as $type => $value) { |
|
37 | + if (!$this->allowed($resource, $type)) { |
|
38 | + $this->getACL()->insertPermission($resource, $this, $type); |
|
39 | + } |
|
40 | + } |
|
41 | + } |
|
42 | + } |
|
43 | + return $this; |
|
44 | + } |
|
45 | + |
|
46 | + public function deletePermissions($resource = false) |
|
47 | + { |
|
48 | + $this->getACL()->removePermissions($this, $resource); |
|
49 | + return $this; |
|
50 | + } |
|
51 | + |
|
52 | + public function updatePermissions() |
|
53 | + { |
|
54 | + $this->deletePermissions(); |
|
55 | + $this->insertPermissions(); |
|
56 | + } |
|
57 | + |
|
58 | + public function allowed($resource, $type) |
|
59 | + { |
|
60 | + return $this->getACL()->check($this, $resource, $type); |
|
61 | + } |
|
62 | + |
|
63 | + public function getACL() |
|
64 | + { |
|
65 | + return ACL::instance(); |
|
66 | + } |
|
67 | + |
|
68 | + public function getRoleID() |
|
69 | + { |
|
70 | + return get_class($this) . "." . $this->id; |
|
71 | + } |
|
72 | + |
|
73 | + public function validate($request = array()) |
|
74 | + { |
|
75 | + $this->name = clean($request['name']); |
|
76 | + $this->permissions = $request['permission'] ? $request['permission'] : array(); |
|
77 | + |
|
78 | + $errors = array(); |
|
79 | + |
|
80 | + if (!$this->name) { |
|
81 | + $errors['name'] = 'Denumirea este obligatorie'; |
|
82 | + } |
|
83 | + |
|
84 | + $this->errors = $errors; |
|
85 | + |
|
86 | + if ($this->errors) { |
|
87 | + return false; |
|
88 | + } |
|
89 | + |
|
90 | + return true; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | } |
94 | 94 | \ No newline at end of file |
@@ -3,207 +3,207 @@ |
||
3 | 3 | class ACL |
4 | 4 | { |
5 | 5 | |
6 | - protected $_resources; |
|
7 | - protected $_roles; |
|
8 | - protected $_permissions; |
|
9 | - protected $_permissionMap; |
|
10 | - protected $_permissionTypes = array("view", "edit", "delete"); |
|
11 | - |
|
12 | - public function addResource($resource) |
|
13 | - { |
|
14 | - $this->_resources[$this->getResourcePathString($resource)] = $resource; |
|
15 | - } |
|
16 | - |
|
17 | - public function addRole($role) |
|
18 | - { |
|
19 | - $this->_roles[$this->getRoleID($role)] = $role; |
|
20 | - } |
|
21 | - |
|
22 | - /** |
|
23 | - * Adds $type acces for $role to $resource |
|
24 | - * |
|
25 | - * @param mixed $resource |
|
26 | - * @param mixed $role |
|
27 | - * @param string $type |
|
28 | - */ |
|
29 | - public function addPermission($resource, $role, $type = "view") |
|
30 | - { |
|
31 | - $resource = $this->getResource($resource); |
|
32 | - $role = $this->getRole($role); |
|
33 | - $this->_permissionMap[$this->getRoleID($role)][$this->getResourcePathString($resource)][$type] = true; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Stores $type access for $role to $resource |
|
38 | - * Checks to see if permission already exists before insertion |
|
39 | - * |
|
40 | - * @param mixed $resource |
|
41 | - * @param mixed $role |
|
42 | - * @param string $type |
|
43 | - */ |
|
44 | - public function insertPermission($resource, $role, $type) |
|
45 | - { |
|
46 | - if (!$this->check($role, $resource, $type)) { |
|
47 | - $permission = ACL_Permissions::instance()->getNew(); |
|
48 | - |
|
49 | - $permission->setRole($this->getRole($role)); |
|
50 | - $permission->setResource($this->getResource($resource)); |
|
51 | - |
|
52 | - $permission->type = $type; |
|
53 | - $permission->insert(); |
|
54 | - |
|
55 | - $this->addPermission($resource, $role, $type); |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Remove all permissions for $role [to $resource] |
|
61 | - * @param mixed $role |
|
62 | - */ |
|
63 | - public function removePermissions($role = false, $resource = false) |
|
64 | - { |
|
65 | - $permissions = $this->getPermissions($role, $resource); |
|
66 | - if ($permissions) { |
|
67 | - foreach ($permissions as $permission) { |
|
68 | - $permission->delete(); |
|
69 | - } |
|
70 | - } |
|
71 | - if ($role) { |
|
72 | - if ($resource) { |
|
73 | - unset($this->_permissionMap[$this->getRoleID($role)][$this->getResourcePathString($resource)]); |
|
74 | - } else { |
|
75 | - unset($this->_permissionMap[$this->getRoleID($role)]); |
|
76 | - } |
|
77 | - } else { |
|
78 | - if ($resource) { |
|
79 | - foreach ($this->_permissionMap as $roleID => $resources) { |
|
80 | - unset($this->_permissionMap[$roleID][$this->getResourcePathString($resource)]); |
|
81 | - } |
|
82 | - } |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Checks if $role has $type acces to $resource |
|
88 | - * |
|
89 | - * @param mixed $role |
|
90 | - * @param mixed $resource |
|
91 | - * @param string $type |
|
92 | - * @return bool |
|
93 | - */ |
|
94 | - public function check($role, $resource, $type) |
|
95 | - { |
|
96 | - $role = $this->getRoleID($role); |
|
97 | - $resource = $this->getResourcePathString($resource); |
|
98 | - |
|
99 | - return $this->_permissionMap[$role][$resource][$type] == true; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @param mixed $resource |
|
104 | - * @return ACL_Resource |
|
105 | - */ |
|
106 | - public function getResource($resource) |
|
107 | - { |
|
108 | - if (!($resource instanceof ACL_Resource)) { |
|
109 | - $resource = $this->_resources[$resource]; |
|
110 | - } |
|
111 | - return $resource; |
|
112 | - } |
|
113 | - |
|
114 | - public function getResourcePathString($resource) |
|
115 | - { |
|
116 | - return $this->getResource($resource)->getPathString(); |
|
117 | - } |
|
118 | - |
|
119 | - public function getRole($role) |
|
120 | - { |
|
121 | - if (!($role instanceof ACL_Role)) { |
|
122 | - $role = $this->_roles[$role]; |
|
123 | - } |
|
124 | - return $role; |
|
125 | - } |
|
126 | - |
|
127 | - public function getRoleID($role) |
|
128 | - { |
|
129 | - return $this->getRole($role)->getRoleID(); |
|
130 | - } |
|
131 | - |
|
132 | - public function getPermissions($role = false, $resource = false) |
|
133 | - { |
|
134 | - if (!$this->_permissions) { |
|
135 | - $permissions = ACL_Permissions::instance()->findAll(); |
|
136 | - if ($permissions) { |
|
137 | - foreach ($permissions as $permission) { |
|
138 | - $this->addPermission($permission->id_acl_resource, $permission->id_acl_role, $permission->type); |
|
139 | - } |
|
140 | - } |
|
141 | - $this->_permissions = $permissions; |
|
142 | - } |
|
143 | - |
|
144 | - $return = array(); |
|
145 | - if ($this->_permissions) { |
|
146 | - foreach ($this->_permissions as $permission) { |
|
147 | - if ($role) { |
|
148 | - if ($permission->id_acl_role != $this->getRoleID($role)) { |
|
149 | - continue; |
|
150 | - } |
|
151 | - } |
|
152 | - if ($resource) { |
|
153 | - if ($permission->id_acl_resource != $this->getResourcePathString($resource)) { |
|
154 | - continue; |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - $return[] = $permission; |
|
159 | - } |
|
160 | - } |
|
161 | - return $return; |
|
162 | - } |
|
163 | - |
|
164 | - public function getResources() |
|
165 | - { |
|
166 | - if (!$this->_resources) { |
|
167 | - $resources = ACL_Resources::instance()->findAll(); |
|
168 | - if ($resources) { |
|
169 | - foreach ($resources as $resource) { |
|
170 | - $this->addResource($resource); |
|
171 | - } |
|
172 | - } |
|
173 | - } |
|
174 | - return $this->_resources; |
|
175 | - } |
|
176 | - |
|
177 | - public function getRoles() |
|
178 | - { |
|
179 | - if (!$this->_roles) { |
|
180 | - $roles = ACL_Roles::instance()->findAll(); |
|
181 | - |
|
182 | - if ($roles) { |
|
183 | - foreach ($roles as $role) { |
|
184 | - $this->addRole($role); |
|
185 | - } |
|
186 | - } |
|
187 | - } |
|
188 | - return $this->_roles; |
|
189 | - } |
|
190 | - |
|
191 | - public function getPermissionTypes() |
|
192 | - { |
|
193 | - return $this->_permissionTypes; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Singleton |
|
198 | - * @return ACL |
|
199 | - */ |
|
200 | - public static function instance() |
|
201 | - { |
|
202 | - static $instance; |
|
203 | - if (!($instance instanceof self)) { |
|
204 | - $instance = new self(); |
|
205 | - } |
|
206 | - return $instance; |
|
207 | - } |
|
6 | + protected $_resources; |
|
7 | + protected $_roles; |
|
8 | + protected $_permissions; |
|
9 | + protected $_permissionMap; |
|
10 | + protected $_permissionTypes = array("view", "edit", "delete"); |
|
11 | + |
|
12 | + public function addResource($resource) |
|
13 | + { |
|
14 | + $this->_resources[$this->getResourcePathString($resource)] = $resource; |
|
15 | + } |
|
16 | + |
|
17 | + public function addRole($role) |
|
18 | + { |
|
19 | + $this->_roles[$this->getRoleID($role)] = $role; |
|
20 | + } |
|
21 | + |
|
22 | + /** |
|
23 | + * Adds $type acces for $role to $resource |
|
24 | + * |
|
25 | + * @param mixed $resource |
|
26 | + * @param mixed $role |
|
27 | + * @param string $type |
|
28 | + */ |
|
29 | + public function addPermission($resource, $role, $type = "view") |
|
30 | + { |
|
31 | + $resource = $this->getResource($resource); |
|
32 | + $role = $this->getRole($role); |
|
33 | + $this->_permissionMap[$this->getRoleID($role)][$this->getResourcePathString($resource)][$type] = true; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Stores $type access for $role to $resource |
|
38 | + * Checks to see if permission already exists before insertion |
|
39 | + * |
|
40 | + * @param mixed $resource |
|
41 | + * @param mixed $role |
|
42 | + * @param string $type |
|
43 | + */ |
|
44 | + public function insertPermission($resource, $role, $type) |
|
45 | + { |
|
46 | + if (!$this->check($role, $resource, $type)) { |
|
47 | + $permission = ACL_Permissions::instance()->getNew(); |
|
48 | + |
|
49 | + $permission->setRole($this->getRole($role)); |
|
50 | + $permission->setResource($this->getResource($resource)); |
|
51 | + |
|
52 | + $permission->type = $type; |
|
53 | + $permission->insert(); |
|
54 | + |
|
55 | + $this->addPermission($resource, $role, $type); |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Remove all permissions for $role [to $resource] |
|
61 | + * @param mixed $role |
|
62 | + */ |
|
63 | + public function removePermissions($role = false, $resource = false) |
|
64 | + { |
|
65 | + $permissions = $this->getPermissions($role, $resource); |
|
66 | + if ($permissions) { |
|
67 | + foreach ($permissions as $permission) { |
|
68 | + $permission->delete(); |
|
69 | + } |
|
70 | + } |
|
71 | + if ($role) { |
|
72 | + if ($resource) { |
|
73 | + unset($this->_permissionMap[$this->getRoleID($role)][$this->getResourcePathString($resource)]); |
|
74 | + } else { |
|
75 | + unset($this->_permissionMap[$this->getRoleID($role)]); |
|
76 | + } |
|
77 | + } else { |
|
78 | + if ($resource) { |
|
79 | + foreach ($this->_permissionMap as $roleID => $resources) { |
|
80 | + unset($this->_permissionMap[$roleID][$this->getResourcePathString($resource)]); |
|
81 | + } |
|
82 | + } |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Checks if $role has $type acces to $resource |
|
88 | + * |
|
89 | + * @param mixed $role |
|
90 | + * @param mixed $resource |
|
91 | + * @param string $type |
|
92 | + * @return bool |
|
93 | + */ |
|
94 | + public function check($role, $resource, $type) |
|
95 | + { |
|
96 | + $role = $this->getRoleID($role); |
|
97 | + $resource = $this->getResourcePathString($resource); |
|
98 | + |
|
99 | + return $this->_permissionMap[$role][$resource][$type] == true; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @param mixed $resource |
|
104 | + * @return ACL_Resource |
|
105 | + */ |
|
106 | + public function getResource($resource) |
|
107 | + { |
|
108 | + if (!($resource instanceof ACL_Resource)) { |
|
109 | + $resource = $this->_resources[$resource]; |
|
110 | + } |
|
111 | + return $resource; |
|
112 | + } |
|
113 | + |
|
114 | + public function getResourcePathString($resource) |
|
115 | + { |
|
116 | + return $this->getResource($resource)->getPathString(); |
|
117 | + } |
|
118 | + |
|
119 | + public function getRole($role) |
|
120 | + { |
|
121 | + if (!($role instanceof ACL_Role)) { |
|
122 | + $role = $this->_roles[$role]; |
|
123 | + } |
|
124 | + return $role; |
|
125 | + } |
|
126 | + |
|
127 | + public function getRoleID($role) |
|
128 | + { |
|
129 | + return $this->getRole($role)->getRoleID(); |
|
130 | + } |
|
131 | + |
|
132 | + public function getPermissions($role = false, $resource = false) |
|
133 | + { |
|
134 | + if (!$this->_permissions) { |
|
135 | + $permissions = ACL_Permissions::instance()->findAll(); |
|
136 | + if ($permissions) { |
|
137 | + foreach ($permissions as $permission) { |
|
138 | + $this->addPermission($permission->id_acl_resource, $permission->id_acl_role, $permission->type); |
|
139 | + } |
|
140 | + } |
|
141 | + $this->_permissions = $permissions; |
|
142 | + } |
|
143 | + |
|
144 | + $return = array(); |
|
145 | + if ($this->_permissions) { |
|
146 | + foreach ($this->_permissions as $permission) { |
|
147 | + if ($role) { |
|
148 | + if ($permission->id_acl_role != $this->getRoleID($role)) { |
|
149 | + continue; |
|
150 | + } |
|
151 | + } |
|
152 | + if ($resource) { |
|
153 | + if ($permission->id_acl_resource != $this->getResourcePathString($resource)) { |
|
154 | + continue; |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + $return[] = $permission; |
|
159 | + } |
|
160 | + } |
|
161 | + return $return; |
|
162 | + } |
|
163 | + |
|
164 | + public function getResources() |
|
165 | + { |
|
166 | + if (!$this->_resources) { |
|
167 | + $resources = ACL_Resources::instance()->findAll(); |
|
168 | + if ($resources) { |
|
169 | + foreach ($resources as $resource) { |
|
170 | + $this->addResource($resource); |
|
171 | + } |
|
172 | + } |
|
173 | + } |
|
174 | + return $this->_resources; |
|
175 | + } |
|
176 | + |
|
177 | + public function getRoles() |
|
178 | + { |
|
179 | + if (!$this->_roles) { |
|
180 | + $roles = ACL_Roles::instance()->findAll(); |
|
181 | + |
|
182 | + if ($roles) { |
|
183 | + foreach ($roles as $role) { |
|
184 | + $this->addRole($role); |
|
185 | + } |
|
186 | + } |
|
187 | + } |
|
188 | + return $this->_roles; |
|
189 | + } |
|
190 | + |
|
191 | + public function getPermissionTypes() |
|
192 | + { |
|
193 | + return $this->_permissionTypes; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Singleton |
|
198 | + * @return ACL |
|
199 | + */ |
|
200 | + public static function instance() |
|
201 | + { |
|
202 | + static $instance; |
|
203 | + if (!($instance instanceof self)) { |
|
204 | + $instance = new self(); |
|
205 | + } |
|
206 | + return $instance; |
|
207 | + } |
|
208 | 208 | |
209 | 209 | } |
210 | 210 | \ No newline at end of file |
@@ -22,9 +22,9 @@ |
||
22 | 22 | |
23 | 23 | $dDiff = $dStart->diff($dEnd); |
24 | 24 | |
25 | - $years = (int)$dDiff->format("%y"); |
|
26 | - $months = (int)$dDiff->format("%m"); |
|
27 | - $days = (int)$dDiff->format("%d"); |
|
25 | + $years = (int) $dDiff->format("%y"); |
|
26 | + $months = (int) $dDiff->format("%m"); |
|
27 | + $days = (int) $dDiff->format("%d"); |
|
28 | 28 | |
29 | 29 | return array($years, $months, $days); |
30 | 30 | } |
@@ -11,64 +11,64 @@ |
||
11 | 11 | |
12 | 12 | class Nip_Helper_Fulltext extends Nip\Helpers\AbstractHelper { |
13 | 13 | |
14 | - public function buildString($keywords, $mode = 'any') { |
|
15 | - $return = ""; |
|
14 | + public function buildString($keywords, $mode = 'any') { |
|
15 | + $return = ""; |
|
16 | 16 | |
17 | - $keywords = explode(" ", $keywords); |
|
17 | + $keywords = explode(" ", $keywords); |
|
18 | 18 | |
19 | - switch ($mode) { |
|
20 | - case "any": |
|
21 | - foreach ($keywords as $item) { |
|
22 | - $return .= $this->matchNumbers($item).'* '; |
|
23 | - } |
|
24 | - break; |
|
19 | + switch ($mode) { |
|
20 | + case "any": |
|
21 | + foreach ($keywords as $item) { |
|
22 | + $return .= $this->matchNumbers($item).'* '; |
|
23 | + } |
|
24 | + break; |
|
25 | 25 | |
26 | - case "all": |
|
27 | - if (count($keywords) == 1) { |
|
28 | - $return .= $this->matchNumbers(reset($keywords)).'* '; |
|
29 | - } else { |
|
30 | - foreach ($keywords as $item) { |
|
31 | - $return .= '+'. $this->matchNumbers($item).'* '; |
|
32 | - } |
|
33 | - } |
|
26 | + case "all": |
|
27 | + if (count($keywords) == 1) { |
|
28 | + $return .= $this->matchNumbers(reset($keywords)).'* '; |
|
29 | + } else { |
|
30 | + foreach ($keywords as $item) { |
|
31 | + $return .= '+'. $this->matchNumbers($item).'* '; |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | - break; |
|
36 | - case "exact": |
|
37 | - foreach ($keywords as $item) { |
|
38 | - $return .= $this->matchNumbers($item).' '; |
|
39 | - } |
|
40 | - $return = '+"'.$return.'"'; |
|
41 | - break; |
|
42 | - } |
|
35 | + break; |
|
36 | + case "exact": |
|
37 | + foreach ($keywords as $item) { |
|
38 | + $return .= $this->matchNumbers($item).' '; |
|
39 | + } |
|
40 | + $return = '+"'.$return.'"'; |
|
41 | + break; |
|
42 | + } |
|
43 | 43 | |
44 | - $return = strtolower(trim($return)); |
|
44 | + $return = strtolower(trim($return)); |
|
45 | 45 | |
46 | - return $return; |
|
47 | - } |
|
46 | + return $return; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - private function matchNumbers($input) { |
|
51 | - $stripped = array("%", ",", "."); |
|
52 | - $replaced = array("__", "_", "_"); |
|
50 | + private function matchNumbers($input) { |
|
51 | + $stripped = array("%", ",", "."); |
|
52 | + $replaced = array("__", "_", "_"); |
|
53 | 53 | |
54 | - if (is_numeric(str_replace($stripped, "", $input))) { |
|
55 | - return str_replace($stripped, $replaced, $input); |
|
56 | - } else { |
|
57 | - return $input; |
|
58 | - } |
|
59 | - } |
|
54 | + if (is_numeric(str_replace($stripped, "", $input))) { |
|
55 | + return str_replace($stripped, $replaced, $input); |
|
56 | + } else { |
|
57 | + return $input; |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * Returns singleton instance |
|
64 | - * |
|
65 | - * @return Nip_Helper_Fulltext |
|
66 | - */ |
|
67 | - static public function instance() { |
|
68 | - static $instance; |
|
69 | - if (!($instance instanceof self)) { |
|
70 | - $instance = new self(); |
|
71 | - } |
|
72 | - return $instance; |
|
73 | - } |
|
62 | + /** |
|
63 | + * Returns singleton instance |
|
64 | + * |
|
65 | + * @return Nip_Helper_Fulltext |
|
66 | + */ |
|
67 | + static public function instance() { |
|
68 | + static $instance; |
|
69 | + if (!($instance instanceof self)) { |
|
70 | + $instance = new self(); |
|
71 | + } |
|
72 | + return $instance; |
|
73 | + } |
|
74 | 74 | } |
75 | 75 | \ No newline at end of file |
@@ -19,25 +19,25 @@ |
||
19 | 19 | switch ($mode) { |
20 | 20 | case "any": |
21 | 21 | foreach ($keywords as $item) { |
22 | - $return .= $this->matchNumbers($item).'* '; |
|
22 | + $return .= $this->matchNumbers($item) . '* '; |
|
23 | 23 | } |
24 | 24 | break; |
25 | 25 | |
26 | 26 | case "all": |
27 | 27 | if (count($keywords) == 1) { |
28 | - $return .= $this->matchNumbers(reset($keywords)).'* '; |
|
28 | + $return .= $this->matchNumbers(reset($keywords)) . '* '; |
|
29 | 29 | } else { |
30 | 30 | foreach ($keywords as $item) { |
31 | - $return .= '+'. $this->matchNumbers($item).'* '; |
|
31 | + $return .= '+' . $this->matchNumbers($item) . '* '; |
|
32 | 32 | } |
33 | 33 | } |
34 | 34 | |
35 | 35 | break; |
36 | 36 | case "exact": |
37 | 37 | foreach ($keywords as $item) { |
38 | - $return .= $this->matchNumbers($item).' '; |
|
38 | + $return .= $this->matchNumbers($item) . ' '; |
|
39 | 39 | } |
40 | - $return = '+"'.$return.'"'; |
|
40 | + $return = '+"' . $return . '"'; |
|
41 | 41 | break; |
42 | 42 | } |
43 | 43 |
@@ -2,33 +2,33 @@ |
||
2 | 2 | class Nip_Helper_Async extends Nip\Helpers\AbstractHelper |
3 | 3 | { |
4 | 4 | |
5 | - public function sendMessage($message, $type = 'success', $format ='json') |
|
6 | - { |
|
5 | + public function sendMessage($message, $type = 'success', $format ='json') |
|
6 | + { |
|
7 | 7 | $data = array( |
8 | 8 | 'type' => $type, |
9 | 9 | 'message' => $message, |
10 | 10 | ); |
11 | 11 | return $this->$format($data); |
12 | - } |
|
12 | + } |
|
13 | 13 | |
14 | - public function json($data) |
|
15 | - { |
|
16 | - header("Content-type: text/x-json"); |
|
17 | - echo(is_string($data) ? $data : json_encode($data)); |
|
18 | - exit(); |
|
19 | - } |
|
14 | + public function json($data) |
|
15 | + { |
|
16 | + header("Content-type: text/x-json"); |
|
17 | + echo(is_string($data) ? $data : json_encode($data)); |
|
18 | + exit(); |
|
19 | + } |
|
20 | 20 | |
21 | - public function txt($data) |
|
22 | - { |
|
23 | - header("Content-type: text/plain"); |
|
24 | - echo($data); |
|
25 | - exit(); |
|
26 | - } |
|
21 | + public function txt($data) |
|
22 | + { |
|
23 | + header("Content-type: text/plain"); |
|
24 | + echo($data); |
|
25 | + exit(); |
|
26 | + } |
|
27 | 27 | |
28 | - public function html($data) |
|
29 | - { |
|
30 | - header("Content-type: text/html"); |
|
31 | - echo($data); |
|
32 | - exit(); |
|
33 | - } |
|
28 | + public function html($data) |
|
29 | + { |
|
30 | + header("Content-type: text/html"); |
|
31 | + echo($data); |
|
32 | + exit(); |
|
33 | + } |
|
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -2,7 +2,7 @@ |
||
2 | 2 | class Nip_Helper_Async extends Nip\Helpers\AbstractHelper |
3 | 3 | { |
4 | 4 | |
5 | - public function sendMessage($message, $type = 'success', $format ='json') |
|
5 | + public function sendMessage($message, $type = 'success', $format = 'json') |
|
6 | 6 | { |
7 | 7 | $data = array( |
8 | 8 | 'type' => $type, |
@@ -82,43 +82,43 @@ |
||
82 | 82 | return $string; |
83 | 83 | } |
84 | 84 | |
85 | - public function moneyFormat($number) |
|
86 | - { |
|
87 | - return money_format('%n', $number); |
|
88 | - } |
|
85 | + public function moneyFormat($number) |
|
86 | + { |
|
87 | + return money_format('%n', $number); |
|
88 | + } |
|
89 | 89 | |
90 | - public function cronoTimeInSeconds($time) |
|
91 | - { |
|
92 | - $parts = explode(':', $time); |
|
93 | - $seconds = array_pop($parts); |
|
94 | - $minutes = array_pop($parts); |
|
95 | - $hours = array_pop($parts); |
|
96 | - $days = array_pop($parts); |
|
97 | - |
|
98 | - return (($days*24 + $hours)*60 + $minutes)*60 + $seconds; |
|
99 | - } |
|
90 | + public function cronoTimeInSeconds($time) |
|
91 | + { |
|
92 | + $parts = explode(':', $time); |
|
93 | + $seconds = array_pop($parts); |
|
94 | + $minutes = array_pop($parts); |
|
95 | + $hours = array_pop($parts); |
|
96 | + $days = array_pop($parts); |
|
97 | + |
|
98 | + return (($days*24 + $hours)*60 + $minutes)*60 + $seconds; |
|
99 | + } |
|
100 | 100 | |
101 | - public function secondsInCronoTime($seconds) |
|
102 | - { |
|
103 | - if ($days = intval((floor($seconds / 86400)))) { |
|
101 | + public function secondsInCronoTime($seconds) |
|
102 | + { |
|
103 | + if ($days = intval((floor($seconds / 86400)))) { |
|
104 | 104 | $seconds = $seconds - $days*86400; |
105 | - $return .= ($return ? ':' : '') . str_pad($days, 2, 0,STR_PAD_LEFT); |
|
106 | - } |
|
107 | - if ($hours = intval((floor($seconds / 3600))) OR $return) { |
|
105 | + $return .= ($return ? ':' : '') . str_pad($days, 2, 0,STR_PAD_LEFT); |
|
106 | + } |
|
107 | + if ($hours = intval((floor($seconds / 3600))) OR $return) { |
|
108 | 108 | $seconds = $seconds - $hours*3600; |
109 | - $return .= ($return ? ':' : '') . str_pad($hours, 2, 0,STR_PAD_LEFT); |
|
110 | - } |
|
111 | - if ($minutes = intval((floor($seconds / 60))) OR $return) { |
|
112 | - $seconds = $seconds - $minutes*60; |
|
113 | - $return .= ($return ? ':' : '') . str_pad($minutes, 2, 0, STR_PAD_LEFT); |
|
114 | - } |
|
115 | - $seconds = round($seconds, 2); |
|
116 | - $return .= ($return ? ':' : '') . str_pad($seconds, 2, 0, STR_PAD_LEFT); |
|
109 | + $return .= ($return ? ':' : '') . str_pad($hours, 2, 0,STR_PAD_LEFT); |
|
110 | + } |
|
111 | + if ($minutes = intval((floor($seconds / 60))) OR $return) { |
|
112 | + $seconds = $seconds - $minutes*60; |
|
113 | + $return .= ($return ? ':' : '') . str_pad($minutes, 2, 0, STR_PAD_LEFT); |
|
114 | + } |
|
115 | + $seconds = round($seconds, 2); |
|
116 | + $return .= ($return ? ':' : '') . str_pad($seconds, 2, 0, STR_PAD_LEFT); |
|
117 | 117 | |
118 | - return $return; |
|
119 | - } |
|
118 | + return $return; |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
121 | + /** |
|
122 | 122 | * Singleton |
123 | 123 | * |
124 | 124 | * @return Nip_Helper_String |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | foreach ($matches as &$match) { |
76 | 76 | if (preg_match('/<(a|img)\b/', $match) && !preg_match('/(?:http|#|mailto)/', $match)) { |
77 | - $match = preg_replace('/^([^"]+")([^"]+)/', '$1'.$base.'$2', $match); |
|
77 | + $match = preg_replace('/^([^"]+")([^"]+)/', '$1' . $base . '$2', $match); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
@@ -95,21 +95,21 @@ discard block |
||
95 | 95 | $hours = array_pop($parts); |
96 | 96 | $days = array_pop($parts); |
97 | 97 | |
98 | - return (($days*24 + $hours)*60 + $minutes)*60 + $seconds; |
|
98 | + return (($days * 24 + $hours) * 60 + $minutes) * 60 + $seconds; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | public function secondsInCronoTime($seconds) |
102 | 102 | { |
103 | 103 | if ($days = intval((floor($seconds / 86400)))) { |
104 | - $seconds = $seconds - $days*86400; |
|
105 | - $return .= ($return ? ':' : '') . str_pad($days, 2, 0,STR_PAD_LEFT); |
|
104 | + $seconds = $seconds - $days * 86400; |
|
105 | + $return .= ($return ? ':' : '') . str_pad($days, 2, 0, STR_PAD_LEFT); |
|
106 | 106 | } |
107 | 107 | if ($hours = intval((floor($seconds / 3600))) OR $return) { |
108 | - $seconds = $seconds - $hours*3600; |
|
109 | - $return .= ($return ? ':' : '') . str_pad($hours, 2, 0,STR_PAD_LEFT); |
|
108 | + $seconds = $seconds - $hours * 3600; |
|
109 | + $return .= ($return ? ':' : '') . str_pad($hours, 2, 0, STR_PAD_LEFT); |
|
110 | 110 | } |
111 | 111 | if ($minutes = intval((floor($seconds / 60))) OR $return) { |
112 | - $seconds = $seconds - $minutes*60; |
|
112 | + $seconds = $seconds - $minutes * 60; |
|
113 | 113 | $return .= ($return ? ':' : '') . str_pad($minutes, 2, 0, STR_PAD_LEFT); |
114 | 114 | } |
115 | 115 | $seconds = round($seconds, 2); |
@@ -3,37 +3,37 @@ |
||
3 | 3 | class Nip_Helper_View_TinyMCE extends Nip_Helper_View_Abstract |
4 | 4 | { |
5 | 5 | |
6 | - protected $_enabled = false; |
|
6 | + protected $_enabled = false; |
|
7 | 7 | |
8 | - public function setEnabled($enabled = true) |
|
9 | - { |
|
10 | - $this->_enabled = $enabled; |
|
11 | - } |
|
8 | + public function setEnabled($enabled = true) |
|
9 | + { |
|
10 | + $this->_enabled = $enabled; |
|
11 | + } |
|
12 | 12 | |
13 | - public function init() |
|
14 | - { |
|
15 | - if ($this->_enabled) { |
|
16 | - $this->getView()->Scripts()->setPack(false) |
|
17 | - ->add('tinymce/jquery.tinymce.min', 'tinymce') |
|
18 | - ->add('tinymce/tinymce.min', 'tinymce') |
|
19 | - ->add('tinymce/init', 'tinymce'); |
|
20 | - } |
|
13 | + public function init() |
|
14 | + { |
|
15 | + if ($this->_enabled) { |
|
16 | + $this->getView()->Scripts()->setPack(false) |
|
17 | + ->add('tinymce/jquery.tinymce.min', 'tinymce') |
|
18 | + ->add('tinymce/tinymce.min', 'tinymce') |
|
19 | + ->add('tinymce/init', 'tinymce'); |
|
20 | + } |
|
21 | 21 | |
22 | - return $this->getView()->Scripts()->render('tinymce'); |
|
23 | - } |
|
22 | + return $this->getView()->Scripts()->render('tinymce'); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Singleton |
|
27 | - * |
|
28 | - * @return Nip_Helper_View_TinyMCE |
|
29 | - */ |
|
30 | - static public function instance() |
|
31 | - { |
|
32 | - static $instance; |
|
33 | - if (!($instance instanceof self)) { |
|
34 | - $instance = new self(); |
|
35 | - } |
|
36 | - return $instance; |
|
37 | - } |
|
25 | + /** |
|
26 | + * Singleton |
|
27 | + * |
|
28 | + * @return Nip_Helper_View_TinyMCE |
|
29 | + */ |
|
30 | + static public function instance() |
|
31 | + { |
|
32 | + static $instance; |
|
33 | + if (!($instance instanceof self)) { |
|
34 | + $instance = new self(); |
|
35 | + } |
|
36 | + return $instance; |
|
37 | + } |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | \ No newline at end of file |
@@ -3,21 +3,21 @@ |
||
3 | 3 | class Nip_Helper_View_Icontext extends Nip_Helper_View_Abstract |
4 | 4 | { |
5 | 5 | |
6 | - protected $_symbols = array( |
|
7 | - 'unknown' => 'f016', |
|
8 | - 'image' => 'f03e', |
|
9 | - 'refresh' => 'f021', |
|
10 | - 'chevron_right' => 'f054', |
|
11 | - 'twitter' => 'f099', |
|
12 | - 'facebook' => 'f09a' |
|
13 | - ); |
|
6 | + protected $_symbols = array( |
|
7 | + 'unknown' => 'f016', |
|
8 | + 'image' => 'f03e', |
|
9 | + 'refresh' => 'f021', |
|
10 | + 'chevron_right' => 'f054', |
|
11 | + 'twitter' => 'f099', |
|
12 | + 'facebook' => 'f09a' |
|
13 | + ); |
|
14 | 14 | |
15 | - public function __call($name, $arguments) |
|
16 | - { |
|
17 | - if (!in_array($name, array_keys($this->_symbols))) { |
|
18 | - $name = 'unknown'; |
|
19 | - } |
|
20 | - return '&#x' . $this->_symbols[$name] . ';'; |
|
21 | - } |
|
15 | + public function __call($name, $arguments) |
|
16 | + { |
|
17 | + if (!in_array($name, array_keys($this->_symbols))) { |
|
18 | + $name = 'unknown'; |
|
19 | + } |
|
20 | + return '&#x' . $this->_symbols[$name] . ';'; |
|
21 | + } |
|
22 | 22 | |
23 | 23 | } |
24 | 24 | \ No newline at end of file |