Linux multi-monitor fullscreen support
[ryzomcore.git] / web / public_php / api / common / dfm.php
blob57bbe70d3431a4291ddc45d9cd11e7ca31a8d087
1 <?php
3 /* Copyright (C) 2009 Winch Gate Property Limited
5 * This file is part of ryzom_api.
6 * ryzom_api is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * ryzom_api is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
20 function getDirLinks($url_params, $path, $getvar, $home) {
21 $ret = '';
22 $dirs = explode('/', $path);
23 $dirpath = '';
24 $ret .= _l($home, $url_params, array($getvar => ''));
25 foreach($dirs as $dirname) {
26 if ($dirname) {
27 $ret .= ' &raquo; '._l($dirname, $url_params, array($getvar => '/'.$dirpath.$dirname));
28 $dirpath .= $dirname.'/';
31 return $ret;
34 function isEmptyDir($dir)
36 if (($files = scandir($dir)) && count($files) <= 2) {
37 return true;
39 return false;
42 class ryDataFileManager {
44 public $id;
45 public $log_dir;
46 public $data_dir;
47 public $user_dir;
48 public $app_name;
50 function __construct($id, $app_name=APP_NAME) {
51 $this->app_name = $app_name;
52 $id = (strlen($id) == 0?'0':'').$id;
53 $id = (strlen($id) == 1?'0':'').$id;
54 $this->id = $id;
55 $this->log_dir = RYAPP_PATH.$app_name.'/data/logs/';
56 $this->data_dir = RYAPP_PATH.$app_name.'/data/app/';
57 $this->user_dir = RYAPP_PATH.$app_name.'/data/chars/'.$id[0].'/'.$id[1].'/'.$id.'/';
59 if (!is_dir($this->user_dir))
60 @mkdir($this->user_dir, 0777, true);
62 if (!is_dir($this->log_dir)) {
63 @mkdir($this->log_dir, 0777, true);
64 @mkdir($this->data_dir, 0777, true);
68 /*** Generic datafiles access methods ***/
70 function getData($name, $default=null) {
71 if (file_exists($name))
72 return unserialize(file_get_contents($name));
73 if ($default !== NULL) {
74 @file_put_contents($name, serialize($default));
75 return $default;
77 return NULL;
80 function saveData($name, $datas, $create_folders=true) {
81 if ($create_folders) {
82 if (!is_dir(dirname($name)))
83 @mkdir(dirname($name), 0777, true);
85 if ($datas !== NULL)
86 @file_put_contents($name, serialize($datas));
87 else
88 @unlink($name);
91 function listDataFiles($dir) {
92 $ret = array();
93 if ($handle = @opendir($dir)) {
94 while (false !== ($file = readdir($handle))) {
95 if ($file != '.' && $file != '..' && $file[0] != '.')
96 $ret[] = $file;
99 return $ret;
102 /*** App Datas ***/
104 function loadAppData($name, $default=null) {
105 return $this->getData($this->data_dir.$name, $default);
108 function saveAppData($name, $datas, $create_folders=true) {
109 return $this->saveData($this->data_dir.$name, $datas, $create_folders);
112 function listAppDataFiles($basedir='') {
113 return $this->listDataFiles($this->data_dir.$basedir);
117 /*** User Datas ***/
119 function loadUserData($name, $default=null) {
120 return $this->getData($this->user_dir.$name, $default);
123 function saveUserData($name, $datas, $create_folders=true) {
124 return $this->saveData($this->user_dir.$name, $datas, $create_folders);
127 function listUserDataFiles($basedir='') {
128 return $this->listDataFiles($this->user_dir.$basedir);
131 function loadUserDataFromApp($name, $app, $default=null) {
132 $id = $this->id;
133 $file = RYAPP_PATH.$app.'/data/chars/'.$id[0].'/'.$id[1].'/'.$id.'/'.$name;
134 if (file_exists($file))
135 return unserialize(file_get_contents($file));
136 if ($default !== null)
137 return $default;
138 return null;
141 function saveUserDataFromApp($name, $app, $datas) {
142 $id = $this->id;
143 $dir = RYAPP_PATH.$app.'/data/chars/'.$id[0].'/'.$id[1].'/'.$id.'/';
144 if (!is_dir($dir))
145 @mkdir($dir, 0777, true);
146 file_put_contents($dir.$name, serialize($datas));