3 PIO - Pixmicat! data source I/O
\r
10 function FlagHelper($status=''){
\r
11 $this->_write($status);
\r
14 function _write($status=''){
\r
15 $this->_status = $status;
\r
18 function toString(){
\r
19 return $this->_status;
\r
22 function get($flag){
\r
23 $result = preg_match('/_('.$flag.'(\:(.*))*)_/U', $this->toString(), $match);
\r
24 return $result ? $match[1] : false;
\r
27 function exists($flag){
\r
28 return $this->get($flag) !== false;
\r
31 function value($flag){
\r
32 $wholeflag = $this->get($flag);
\r
33 if($scount = substr_count($wholeflag, ':')){
\r
34 $wholeflag = preg_replace('/^'.$flag.'\:/', '', $wholeflag);
\r
35 return ($scount > 1 ? explode(':', $wholeflag) : $wholeflag);
\r
36 }else return $wholeflag !== false;
\r
39 function add($flag, $value=null){
\r
40 return $this->update($flag, $value);
\r
43 function update($flag, $value=null){
\r
45 $ifexist = $this->get($flag);
\r
46 if($ifexist !== $flag) $this->_write($this->toString()."_${flag}_");
\r
48 if(is_array($value)) $value = $this->join($value); // Array Flatten
\r
49 $ifexist = $this->get($flag);
\r
50 if($ifexist !== $flag.':'.$value){
\r
51 if($ifexist) $this->_write($this->replace($ifexist, "$flag:$value")); // 已立flag,不同值
\r
52 else $this->_write($this->toString()."_$flag:${value}_"); // 無flag
\r
58 function replace($from, $to){
\r
59 return str_replace("_${from}_", "_${to}_", $this->toString());
\r
62 function remove($flag){
\r
63 $wholeflag = $this->get($flag);
\r
64 $this->_write(str_replace("_${wholeflag}_", '', $this->toString()));
\r
68 function toggle($flag){
\r
69 return ($this->get($flag) ? $this->remove($flag) : $this->add($flag));
\r
72 function offsetValue($flag, $d=0){
\r
73 $v = intval($this->value($flag));
\r
74 return $this->update($flag, $v + $d);
\r
77 function plus($flag){ return $this->offsetValue($flag, 1); }
\r
78 function minus($flag){ return $this->offsetValue($flag, -1); }
\r
81 $arg = func_get_args();
\r
83 foreach($arg as $a){
\r
84 if(is_array($a)) array_push($newval, implode(':', $a));
\r
85 else array_push($newval, $a);
\r
87 return implode(':', $newval);
\r
92 include(PHP_DIRECTORY.'lib/lib_pio.cond.php');
\r
94 /*public static */function check($type, $condobj){
\r
95 foreach($condobj as $i => $j){
\r
97 if(call_user_func_array(array($i, 'check'), array($type, $j))===true) return true;
\r
102 /*public static */function listee($type, $condobj){
\r
103 $tmparray = array(); // 項目陣列
\r
104 foreach($condobj as $i => $j){
\r
106 $tmparray = array_merge($tmparray, call_user_func_array(array($i, 'listee'), array($type, $j)));
\r
108 sort($tmparray); // 由舊排到新 (小到大)
\r
109 return array_unique($tmparray);
\r
112 /*public static */function info($condobj){
\r
114 foreach($condobj as $i => $j){
\r
115 $sensorinfo .= call_user_func_array(array($i, 'info'), array($j))."\n";
\r
117 return $sensorinfo;
\r
122 if(preg_match('/^(.*):\/\//i', CONNECTION_STRING, $backend)) define('PIXMICAT_BACKEND', $backend[1]);
\r
125 $pio_file = PHP_DIRECTORY.'lib/pio/pio.'.PIXMICAT_BACKEND.'.php';
\r
126 $PIOEnv = array( // PIO 環境常數
\r
128 'LUTCACHE' => './'.LUT_CACHE,
\r
129 'NONAME' => DEFAULT_NONAME,
\r
130 'NOTITLE' => DEFAULT_NOTITLE,
\r
131 'NOCOMMENT' => DEFAULT_NOCOMMENT,
\r
132 'PERIOD.POST' => RENZOKU,
\r
133 'PERIOD.IMAGEPOST' => RENZOKU2
\r
135 if(is_file($pio_file)) include_once($pio_file);
\r
137 // PIO Kernel Switcher
\r
138 $pioSwitch = 'PIO'.PIXMICAT_BACKEND;
\r
139 $PIO = new $pioSwitch(CONNECTION_STRING, $PIOEnv);
\r