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