1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4/**
5 * Class ilCloudPluginService
6 *
7 * Basic frame for the plugin service class probably needs to be overwritten
8 *
9 * @author  Timon Amstutz timon.amstutz@ilub.unibe.ch
10 * @version $Id$
11 * @ingroup ModulesCloud
12 */
13class ilCloudPluginService
14{
15
16    /**
17     * @var ilCloudPlugin $object
18     */
19    protected $plugin_object = null;
20
21
22    /**
23     * @param $service_name
24     * @param $obj_id
25     */
26    public function __construct($service_name, $obj_id)
27    {
28        $this->plugin_object = ilCloudConnector::getPluginClass($service_name, $obj_id);
29    }
30
31
32    /**
33     * @return ilCloudPlugin
34     */
35    public function getPluginObject()
36    {
37        return $this->plugin_object;
38    }
39
40
41    /**
42     * For shorter access
43     *
44     * @return ilCloudHookPlugin
45     */
46    public function getPluginHookObject()
47    {
48        return $this->getPluginObject()->getPluginHookObject();
49    }
50
51
52    /**
53     * For shorter access
54     *
55     * @return ilCloudPluginConfig
56     */
57    public function getAdminConfigObject()
58    {
59        return $this->getPluginObject()->getAdminConfigObject();
60    }
61
62
63    /**
64     * Called after the cloud object is created to authenticate the service if needed. The callback can be used to get
65     * back to the correct place in ILIAS (the afterAuth Method) after the remote authentication.
66     *
67     * @param string $callback_url
68     */
69    public function authService($callback_url = "")
70    {
71        header("Location: " . htmlspecialchars_decode($callback_url));
72    }
73
74
75    /**
76     * Place were the callback should lead to after authentication. Can be used to updated plugin settings.
77     *
78     * @return bool
79     */
80    public function afterAuthService()
81    {
82        return true;
83    }
84
85
86    public function getServiceObject()
87    {
88    }
89
90
91    /**
92     * Called when RootId (id of the folder which is set to root) is needed.
93     * Mostly after the base directory is changed by the user or after creating the cloud Obect
94     *
95     * @param $root_path
96     *
97     * @return string
98     */
99    public function getRootId($root_path)
100    {
101        return "root";
102    }
103
104
105    /**
106     * Updates the file tree when the user navigates through files and folders
107     *
108     * @param ilCloudFileTree $file_tree
109     * @param string          $parent_folder
110     */
111    public function addToFileTree(ilCloudFileTree $file_tree, $parent_folder = "/")
112    {
113    }
114
115
116
117    /**
118     * Updates the file tree when the user navigates through files and folders.
119     * Uses the id instead of the path.
120     *
121     * @param ilCloudFileTree $file_tree
122     * @param string          $id
123     *
124     * @return bool
125     */
126    public function addToFileTreeWithId(ilCloudFileTree $file_tree, $id)
127    {
128        return false;
129    }
130
131    /**
132     * Called when a file is accessed for download by the user
133     *
134     * @param null            $path
135     * @param ilCloudFileTree $file_tree
136     */
137    public function getFile($path = null, ilCloudFileTree $file_tree = null)
138    {
139    }
140
141
142
143    /**
144     * Called when a file is accessed for download by the user
145     * Uses the id instead of the path.
146     *
147     * @param string $id
148     *
149     * @return bool
150     */
151    public function getFileById($id)
152    {
153        return false;
154    }
155
156    /**
157     * Called when a folder is created by the user
158     *
159     * @param null            $path
160     * @param ilCloudFileTree $file_tree
161     */
162    public function createFolder($path = null, ilCloudFileTree $file_tree = null)
163    {
164    }
165
166
167
168    /**
169     * Called when a folder is created by the user
170     * Uses the id instead of the path.
171     * @param string $parent_id
172     * @param string $folder_name
173     *
174     * @return string|bool
175     */
176    public function createFolderById($parent_id, $folder_name)
177    {
178        return false;
179    }
180
181
182    /**
183     * Called when a file is uploaded by the user
184     *
185     * @param                 $file
186     * @param                 $name
187     * @param string          $path
188     * @param ilCloudFileTree $file_tree
189     */
190    public function putFile($file, $name, $path = '', ilCloudFileTree $file_tree = null)
191    {
192    }
193
194
195    /**
196     * Called when a file is uploaded by the user
197     * Uses the id instead of the path.
198     *
199     * @param string $tmp_name
200     * @param string $file_name
201     * @param string $id
202     *
203     * @return bool
204     */
205    public function putFileById($tmp_name, $file_name, $id)
206    {
207        return false;
208    }
209
210    /**
211     * Called when an item is deleted by the user
212     *
213     * @param null            $path
214     * @param ilCloudFileTree $file_tree
215     */
216    public function deleteItem($path = null, ilCloudFileTree $file_tree = null)
217    {
218    }
219
220
221
222    /**
223     * Called when an item is deleted by the user
224     * Uses the id instead of the path.
225     *
226     * @param string $id
227     *
228     * @return bool
229     */
230    public function deleteItemById($id)
231    {
232        return false;
233    }
234
235    /**
236     * by default false
237     *
238     * @return bool
239     */
240    public function isCaseSensitive()
241    {
242        return false;
243    }
244
245
246    /**
247     * @param int $bytes
248     *
249     * @return string
250     */
251    public function formatBytes($bytes)
252    {
253        $unit = array('B', 'KB', 'MB', 'GB', 'TB');
254        $bytes = max($bytes, 0);
255        $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
256        $pow = min($pow, count($unit) - 1);
257        $bytes /= pow(1024, $pow);
258
259        return round($bytes, 2) . ' ' . $unit[$pow];
260    }
261
262
263    /**
264     * A little helper function returning the currently used protocol as string
265     *
266     * @return string
267     */
268    public function getProtokol()
269    {
270        return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'HTTPS' : 'HTTP';
271    }
272}
273