annotate Settings.class.php @ 30:1c5f618dc210

add: Settings class
author Sushi-k <epgrec@park.mda.or.jp>
date Mon, 27 Jul 2009 11:21:57 +0900
parents
children 6bb8f29c80c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
1 <?php
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
2 include_once('config.php');
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
3
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
4 class Settings extends SimpleXMLElement {
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
5
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
6 const CONFIG_XML = "/settings/config.xml";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
7
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
8 public static function factory() {
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
9
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
10 if( file_exists( INSTALL_PATH . self::CONFIG_XML ) ) {
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
11 $xmlfile = file_get_contents(INSTALL_PATH . self::CONFIG_XML);
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
12 return new self($xmlfile);
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
13 }
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
14 else {
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
15 // 初回起動
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
16 $xmlfile = '<?xml version="1.0" encoding="UTF-8" ?><epgrec></epgrec>';
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
17 $xml = new self($xmlfile);
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
18
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
19 // 旧config.phpを読み取って設定
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
20 if(defined("SPOOL") ) $xml->spool = SPOOL;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
21 else $xml->spool = "/video";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
22
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
23 if(defined("THUMBS") ) $xml->thumbs = THUMBS;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
24 else $xml->thumbs = "/thumbs";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
25
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
26 if(defined("INSTALL_URL")) $xml->install_url = INSTALL_URL;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
27 else $xml->install_url = "http://localhost/epgrec";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
28
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
29 if(defined("BS_TUNERS")) $xml->bs_tuners = BS_TUNERS;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
30 else $xml->bs_tuenrs = 0;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
31
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
32 if(defined("GR_TUNERS")) $xml->gr_tuenrs = GR_TUNERS;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
33 else $xml->gr_tuners = 1;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
34
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
35 if(defined("USE_KUROBON")) $xml->use_kurobon = USE_KUROBON;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
36 else $xml->use_kurobon = 0;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
37
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
38 if(defined("FORMER_TIME")) $xml->former_time = FORMER_TIME;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
39 else $xml->former_time = 20;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
40
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
41 if(defined("EXTRA_TIME")) $xml->extra_time = EXTRA_TIME;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
42 else $xml->extra_time = 0;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
43
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
44 if(defined("FORCE_CONT_REC")) $xml->force_cont_rec = FORCE_CONT_REC;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
45 else $xml->force_cont_rec = 0;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
46
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
47 if(defined("REC_SWITCH_TIME")) $xml->rec_switch_time = REC_SWITCH_TIME;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
48 else $xml->rec_switch_time = 5;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
49
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
50 if(defined("USE_THUMBS")) $xml->use_thumbs = USE_THUMBS;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
51 else $xml->use_thumbs = 0;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
52
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
53 if(defined("MEDIATOMB_UPDATE")) $xml->mediatomb_update = MEDIATOMB_UPDATE;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
54 else $xml->mediatomb_update = 0;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
55
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
56 if(defined("FILENAME_FORMAT")) $xml->filename_format = FILENAME_FORMAT;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
57 else $xml->filename_format = "%TYPE%%CH%_%ST%_%ET%";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
58
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
59 if(defined("DB_HOST")) $xml->db_host = DB_HOST;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
60 else $xml->db_host = "localhost";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
61
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
62 if(defined("DB_NAME")) $xml->db_name = DB_NAME;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
63 else $xml->db_name = "yourdbname";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
64
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
65 if(defined("DB_USER")) $xml->db_user = DB_USER;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
66 else $xml->db_user = "yourname";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
67
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
68 if(defined("DB_PASS")) $xml->db_pass = DB_PASS;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
69 else $xml->db_pass = "yourpass";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
70
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
71 if(defined("TBL_PREFIX")) $xml->tbl_prefix = TBL_PREFIX;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
72 else $xml->tbl_prefix = "Recorder_";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
73
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
74 if(defined("EPGDUMP")) $xml->epgdump = EPGDUMP;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
75 else $xml->epgdump = "/usr/local/bin/epgdump";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
76
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
77 if(defined("AT")) $xml->at = AT;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
78 else $xml->at = "/usr/bin/at";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
79
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
80 if(defined( "ATRM" )) $xml->atrm = ATRM;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
81 else $xml->atrm = "/usr/bin/atrm";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
82
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
83 if(defined( "SLEEP" )) $xml->sleep = SLEEP;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
84 else $xml->sleep = "/bin/sleep";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
85
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
86 if(defined( "FFMPEG" )) $xml->ffmpeg = FFMPEG;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
87 else $xml->ffmpeg = "/usr/bin/ffmpeg";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
88
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
89 if(defined("TEMP_DATA" )) $xml->temp_data = TEMP_DATA;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
90 else $xml->temp_data = "/tmp/__temp.ts";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
91
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
92 if(defined("TEMP_XML")) $xml->temp_xml = TEMP_XML;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
93 else $xml->temp_xml = "/tmp/__temp.xml";
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
94
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
95 // index.phpで使う設定値
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
96 // 表示する番組表の長さ(時間)
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
97 $xml->top_program_length = 8;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
98 // 1局の幅
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
99 $xml->top_ch_set_width = 150;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
100 // 1分あたりの高さ
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
101 $xml->top_height_per_min = 2;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
102
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
103 $xml->save();
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
104
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
105 return $xml;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
106 }
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
107 }
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
108
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
109 public function exists( $property ) {
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
110 return (int)count( $this->{$property} );
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
111 }
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
112
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
113 public function post() {
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
114 global $_POST;
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
115
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
116 foreach( $POST as $key => $value ) {
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
117
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
118 if( $this->exists($key) ) {
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
119 $this->{$key} = trim($value);
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
120 }
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
121 }
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
122 }
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
123
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
124 public function save() {
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
125 $this->asXML(INSTALL_PATH . self::CONFIG_XML);
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
126 }
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
127 }
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
128
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
129 $settings = Settings::factory();
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
130
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
131 print_r( get_object_vars( $settings ) );
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
132
1c5f618dc210 add: Settings class
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
133 ?>