PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.9
VikBooking Hotel Booking Engine & PMS v1.6.9
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / libraries / mvc / admin / models / override.php

override.php in VikBooking Hotel Booking Engine & PMS 1.6.9, at libraries/mvc/admin/models/override.php

134 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2023 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access to this file
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 JLoader::import('adapter.mvc.models.form');
15
16 /**
17 * VikBooking plugin Override model.
18 * @wponly
19 *
20 * @since 1.6.5
21 * @see JModelForm
22 */
23 class VikBookingModelOverride extends JModelForm
24 {
25 /**
26 * @override
27 * Saves the override.
28 *
29 * @param array &$data The array containing the override data.
30 *
31 * @return bool True on success, otherwise false.
32 */
33 public function save(&$data)
34 {
35 // make sure we have a destination file
36 if (empty($data['file']))
37 {
38 $this->setError('Missing destination file');
39
40 return false;
41 }
42
43 // make sure we have a code to write
44 if (!isset($data['code']))
45 {
46 $this->setError('Missing override code');
47
48 return false;
49 }
50
51 // generate override
52 return JFile::write($data['file'], $data['code']);
53 }
54
55 /**
56 * Deletes the specified records.
57 *
58 * @param mixed $ids The PK value (or a list of values) of the record(s) to remove.
59 *
60 * @return bool True if at least a record has been removed, otherwise false.
61 */
62 public function delete($ids)
63 {
64 $deleted = false;
65
66 // iterate files
67 foreach ((array) $ids as $file)
68 {
69 $src = $file;
70
71 // in case the override doesn't exist, try to
72 // look for an unpublished override
73 if (!JFile::exists($file))
74 {
75 // use the unpublished version
76 $src = JPath::clean(dirname($file) . '/__' . basename($file));
77 }
78
79 // try to delete the file
80 $deleted = JFile::delete($src) || $deleted;
81 }
82
83 return $deleted;
84 }
85
86 /**
87 * Changes the state of the specified records.
88 *
89 * @param mixed $ids The PK value (or a list of values) of the record(s) to update.
90 *
91 * @return mixed True if at least a record has been affected, otherwise false.
92 * In case of a single record, the new path will be returned.
93 */
94 public function publish($ids, $state)
95 {
96 $changed = $dest = false;
97
98 $ids = (array) $ids;
99
100 // iterate files
101 foreach ($ids as $file)
102 {
103 $dest = dirname($file);
104 $name = basename($file);
105
106 if ($state)
107 {
108 // start from unpublished file
109 $src = JPath::clean($dest . '/__' . $name);
110 // restore default override
111 $dest = $file;
112 }
113 else
114 {
115 // start from existing override
116 $src = $file;
117 // move to unpublished status
118 $dest = JPath::clean($dest . '/__' . $name);
119 }
120
121 // try to rename the file
122 $changed = rename($src, $dest) || $changed;
123 }
124
125 // in case of a single file, return its new path
126 if ($changed && count($ids) == 1)
127 {
128 return $dest;
129 }
130
131 return $changed;
132 }
133 }
134