Exemple #1
0
 /**
  * Adds a value to insert/update a column
  * @todo create or use string class
  * @param mixed $value
  */
 public function set($value)
 {
     switch (\gettype($value)) {
         case 'string':
             $this->value = new \Variable\String($value, $this->name);
             return true;
             break;
         case 'integer':
             $this->value = new \Variable\Integer($value, $this->name);
             return true;
             break;
         case 'double':
             $this->value = new \Variable\Double($value, $this->name);
             return true;
             break;
         case 'object':
             switch (\get_class($value)) {
                 case 'Expression':
                 case 'Function':
                 case 'Field':
                     $this->value = $value;
                     break;
             }
             /**
              * This should work for all Variable objects and anything else someone else
              * someone puts in
              */
             if (is_string_like($value)) {
                 //if ($value instanceof \Variable) {
                 $this->value = $value;
                 //} elseif (method_exists($value, '__toString')) {
                 //$this->value = new \Variable\String($value->__toString(), $this->name);
             } else {
                 throw new \Exception(t('Unacceptable value type (%s)', gettype($value)));
             }
             return true;
             break;
         case 'array':
             $this->value = new \Variable\String(serialize($value), $this->name);
             return true;
             break;
         case 'NULL':
             $this->value = null;
             return true;
             break;
     }
     throw new \Exception(t('Unacceptable value type (%s)', gettype($value)));
 }
Exemple #2
0
 /**
  * @param string $type
  * @param string $name
  * @param array $value
  * @return \Form\Choice
  * @throws \Exception
  */
 public function addChoice($type, $name, $value = null)
 {
     if (!is_string_like($name) || preg_match('/[^\\w\\-\\[\\]]/', $name)) {
         throw new \Exception(t('Improperly formatted choice name: %s', $name));
     }
     $class_name = 'Form\\Choice\\' . ucfirst(strtolower($type));
     $input = new $class_name($name, $value);
     $this->inputs[$name][] = $input;
     return $input;
 }
Exemple #3
0
 /**
  * Returns an array of variables that can produce printable strings.
  * @return array
  * @throws \Exception
  */
 public function getStringVars()
 {
     $vars = $this->getVars();
     if (empty($vars)) {
         throw new \Exception(t('No variables returned from Data object'));
     }
     foreach ($vars as $key => $val) {
         if (is_string_like($val)) {
             $new_vars[$key] = (string) $val;
         }
     }
     if (!empty($new_vars)) {
         return $new_vars;
     } else {
         throw new \Exception(t('No string variable in Data object'));
     }
 }
 private function quoteValue($value)
 {
     switch (gettype($value)) {
         case 'integer':
             return $value;
         case 'object':
             if (method_exists($value, 'stringAsConditional')) {
                 return $value->stringAsConditional();
             } elseif (is_string_like($value)) {
                 return $this->db->quote($value->__toString());
             } else {
                 throw new \Exception(t('Could not use object variable in a query comparison'));
             }
         case 'NULL':
             return 'NULL';
         case 'array':
             $value = $this->db->quote($value);
             return '(' . implode(',', $value) . ')';
         default:
             return $this->db->quote($value);
     }
 }
Exemple #5
0
function download_file($filename, $download_display = null)
{
    apache_setenv('no-gzip', 1);
    header('Content-Type: application/octet-stream');
    //如果是IE,要轉成 BIG5
    $bigf = $filename;
    if (is_string_like(user_agent(), '%MSIE%') || is_string_like(user_agent(), '%rv_11%')) {
        $bigf = utf8tobig5($bigf);
    }
    if ($download_display == null) {
        $download_display = basename($bigf);
    } else {
        if (is_string_like(user_agent(), '%MSIE%') || is_string_like(user_agent(), '%11%')) {
            $download_display = utf8tobig5($download_display);
        }
    }
    header("Content-Disposition: attachment; filename=\"{$download_display}\"");
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($filename));
    if (in_array('mod_xsendfile', apache_get_modules())) {
        header("X-Sendfile: {$filename}");
        header("X-LIGHTTPD-send-file: {$filename}");
        header("X-Accel-Redirect : {$filename}");
    } else {
        readfile($filename);
    }
}
Exemple #6
0
function get_netstat()
{
    //系統負載
    $data = "";
    if (stristr(PHP_OS, 'win')) {
        $data = `netstat -an`;
        $data = mb_convert_encoding($data, 'UTF-8', 'BIG5');
        $m_need = array();
        $m = explode("\n", $data);
        for ($i = 0, $max_i = count($m); $i < $max_i; $i++) {
            $m[$i] = trim(strtoupper($m[$i]));
            if (is_string_like($m[$i], "%0.0.0.0%") && is_string_like($m[$i], "TCP%") && is_string_like($m[$i], "%LISTEN%")) {
                for ($j = 0, $max_j = mb_strlen($m[$i]); $j < $max_j; $j++) {
                    $m[$i] = str_replace("  ", " ", $m[$i]);
                }
                $mFields = explode(" ", $m[$i]);
                array_push($m_need, "{$mFields[0]} {$mFields[1]}");
            }
        }
        echo implode("<br>", $m_need);
    } else {
        $data = `LANG=c netstat -an|grep '^tcp '|grep LISTEN|grep '0.0.0.0'`;
        $m_need_0 = array();
        $m_need_127 = array();
        $m = explode("\n", $data);
        for ($i = 0, $max_i = count($m); $i < $max_i; $i++) {
            $m[$i] = trim(strtoupper($m[$i]));
            if (is_string_like($m[$i], "%0.0.0.0%") && is_string_like($m[$i], "TCP%") && is_string_like($m[$i], "%LISTEN%")) {
                for ($j = 0, $max_j = mb_strlen($m[$i]); $j < $max_j; $j++) {
                    $m[$i] = str_replace("  ", " ", $m[$i]);
                }
                $mFields = explode(" ", $m[$i]);
                if (is_string_like($mFields[3], "0%")) {
                    array_push($m_need_0, "{$mFields[0]} {$mFields[3]}");
                } else {
                    array_push($m_need_127, "{$mFields[0]} {$mFields[3]}");
                }
            }
        }
        natsort($m_need_0);
        natsort($m_need_127);
        echo implode("<br>", $m_need_0);
        echo "<br>";
        echo implode("<br>", $m_need_127);
    }
}
Exemple #7
0
 /**
  * Set the text content of the tag.
  * @param string $text
  */
 public function setText($text)
 {
     if (is_bool($text)) {
         $text = $text ? 1 : 0;
     }
     if (!is_string_like($text)) {
         throw new \Exception(t('setText received a %s variable, not a string parameter', gettype($text)));
     }
     $this->text = (string) $text;
 }