Skip to content

Commit 32dfb40

Browse files
committed
uri bugs fixing
1 parent 2c38abe commit 32dfb40

File tree

8 files changed

+41
-148
lines changed

8 files changed

+41
-148
lines changed

src/Helpers/Url.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ function base_url($segments = null, $query = null)
2727

2828
if($uri->getSubDomain() !== globals()->get('app')) {
2929
if(!empty(globals()->app->getSegments())) {
30-
if(is_array($segments)) {
31-
$segments = array_merge(globals()->app->getSegments(), $segments);
32-
} elseif(is_string($segments)) {
33-
$segments = implode('/', globals()->app->getSegments()) . '/' . $segments;
30+
if(is_string($segments)) {
31+
$segments = explode('/', $segments);
32+
$segments = array_diff(globals()->app->getSegments(), $segments);
3433
}
34+
35+
$segments = array_merge(globals()->app->getSegments(), $segments);
3536
}
3637
}
3738

@@ -174,11 +175,11 @@ function storage_url($path)
174175
*
175176
* @return string
176177
*/
177-
function images_url($path)
178+
function images_url($path, $size = null)
178179
{
179180
$urlPath = str_replace(PATH_STORAGE, '', $path);
180181

181-
return base_url('images/' . $urlPath);
182+
return base_url('images/' . (isset($size) ? '/' . $size : '') . $urlPath);
182183
}
183184
}
184185

src/Http/Controllers/Images.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Images extends Controller
102102
public function __construct()
103103
{
104104
$this->storagePath = PATH_STORAGE . 'images' . DIRECTORY_SEPARATOR;
105-
$this->imageNotFoundFilename = $this->storagePath . 'default/not-found.jpg';
105+
$this->imageNotFoundFilename = $this->storagePath . 'default'. DIRECTORY_SEPARATOR . 'not-found.jpg';
106106
}
107107

108108
// ------------------------------------------------------------------------
@@ -115,7 +115,7 @@ public function route()
115115
$segments = server_request()->getUri()->segments->getArrayCopy();
116116

117117
if (false !== ($key = array_search('images', $segments))) {
118-
unset($segments[$key]);
118+
$segments = array_slice($segments, $key + 1);
119119
} else {
120120
array_shift($segments);
121121
}

src/Http/Controllers/Storage.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ public function route()
117117
}
118118

119119
header('Content-Type: ' . $fileInfo->getMime());
120-
header('Cache-Control: no-cache, no-store, must-revalidate');
121-
header('Pragma: no-cache');
122-
header('Expires: 0');
120+
header('Cache-Control: max-age=60');
123121
header('Content-Length:' . ($lengthEnd - $lengthStart));
124122
header("Content-Range: bytes " . ($lengthStart-$lengthEnd)/$fileInfo->getSize());
125123
header("Content-Disposition: inline; filename=" . $fileInfo->getFilename() . '.' . $fileInfo->getExtension());

src/Http/Presenter/Assets/Collections/Javascripts.php~39ed76c34d9f5c8cd9d313cb694f613d68afd7c1

-26
This file was deleted.

src/Http/Presenter/Assets/Collections/Javascripts.php~HEAD

-26
This file was deleted.

src/Http/Presenter/Assets/Collections/Styles.php~39ed76c34d9f5c8cd9d313cb694f613d68afd7c1

-26
This file was deleted.

src/Http/Presenter/Assets/Collections/Styles.php~HEAD

-26
This file was deleted.

src/Models/Sql/Traits/ModifierTrait.php

+31-33
Original file line numberDiff line numberDiff line change
@@ -701,43 +701,41 @@ public function insertIfNotExists(SplArrayStorage $data, array $conditions = [])
701701
*/
702702
public function update(SplArrayStorage $data, array $conditions = [])
703703
{
704-
if (empty($this->updateValidationRules)) {
705-
if (empty($this->primaryKeys)) {
706-
$primaryKey = empty($this->primaryKey) ? 'id' : $this->primaryKey;
707-
if ($data->offsetExists($primaryKey)) {
708-
if (!array_key_exists($primaryKey, $conditions)) {
704+
if(empty($conditions)) {
705+
if(count($this->primaryKeys)) {
706+
foreach ($this->primaryKeys as $primaryKey) {
707+
if($data->offsetExists($primaryKey)) {
709708
$conditions[$primaryKey] = $data->offsetGet($primaryKey);
710709
}
711-
}
712710

713-
$this->updateValidationRules[$primaryKey] = 'required';
714-
$this->updateValidationCustomErrors[$primaryKey] = [
715-
'required' => language('LABEL_' . strtoupper($primaryKey)) . ' cannot be empty!',
716-
];
717-
} else {
718-
foreach ($this->primaryKeys as $primaryKey) {
719-
if ($data->offsetExists($primaryKey)) {
720-
if (!array_key_exists($primaryKey, $conditions)) {
721-
$conditions[$primaryKey] = $data->offsetGet($primaryKey);
722-
}
711+
if(empty($this->updateValidationRules)) {
712+
$this->updateValidationRules[$primaryKey] = 'required';
713+
$this->updateValidationCustomErrors[$primaryKey] = [
714+
'required' => language('LABEL_' . strtoupper($primaryKey)) . ' cannot be empty!',
715+
];
723716
}
724-
725-
$this->updateValidationRules[$primaryKey] = 'required';
726-
$this->updateValidationCustomErrors[$primaryKey] = [
727-
'required' => language('LABEL_' . strtoupper($primaryKey)) . ' cannot be empty!',
728-
];
729717
}
730718
}
731-
} elseif (empty($conditions)) {
732-
if (empty($this->primaryKeys)) {
733-
foreach ($this->primaryKeys as $primaryKey) {
734-
if ($data->offsetExists($primaryKey)) {
735-
$conditions[$primaryKey] = $data->offsetGet($primaryKey);
719+
}
720+
721+
if($data instanceof AbstractInput) {
722+
if (count($this->updateValidationRules)) {
723+
$data->validation($this->updateValidationRules, $this->updateValidationCustomErrors);
724+
725+
if (!$data->validate()) {
726+
$this->addErrors($data->validator->getErrors());
727+
728+
if (services()->has('session') and $this->flashMessage) {
729+
$errors = new Unordered();
730+
foreach ($data->validator->getErrors() as $error) {
731+
$errors->createList($error);
732+
}
733+
734+
session()->setFlash('danger',
735+
language('FAILED_INSERT', $errors->__toString()));
736736
}
737-
}
738-
} else {
739-
if ($data->offsetExists($primaryKey)) {
740-
$conditions = [$primaryKey => $data->offsetGet($primaryKey)];
737+
738+
return false;
741739
}
742740
}
743741
}
@@ -877,11 +875,11 @@ public function update(SplArrayStorage $data, array $conditions = [])
877875
$data['settings'] = new SplArrayObject();
878876

879877
if (empty($this->primaryKeys)) {
880-
$ownershipId = $data->offsetGet($this->primaryKey);
878+
$ownershipId = $data[$this->primaryKey];
881879
} else {
882880
$ownershipId = [];
883881
foreach ($this->primaryKeys as $primaryKey) {
884-
array_push($ownershipId, $data->offsetGet($this->primaryKey));
882+
array_push($ownershipId, $data[$primaryKey]);
885883
}
886884

887885
$ownershipId = implode('-', $ownershipId);
@@ -1188,7 +1186,7 @@ private function deleteRow(Row $row)
11881186
} else {
11891187
$ownershipId = [];
11901188
foreach ($this->primaryKeys as $primaryKey) {
1191-
array_push($ownershipId, $data[$primaryKey]);
1189+
array_push($ownershipId, $row->offsetGet($primaryKey));
11921190
}
11931191

11941192
$ownershipId = implode('-', $ownershipId);

0 commit comments

Comments
 (0)