/**
 * 将数组转化为xml格式
 *
 * @param	array	$arr		数组
 * @param	bool	$htmlon		是否开启html模式
 * @param	bool	$isnormal	是否不全空格
 * @param	intval	$level		当前级别
 * @return	string
 */
function dr_array2xml($arr, $htmlon = TRUE, $isnormal = FALSE, $level = 1)
{
    $space = str_repeat("\t", $level);
    $string = $level == 1 ? "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<result>\r\n" : '';
    foreach ($arr as $k => $v) {
        if (!is_array($v)) {
            $string .= $space . "<{$k}>" . ($htmlon ? '<![CDATA[' : '') . $v . ($htmlon ? ']]>' : '') . "</{$k}>\r\n";
        } else {
            $name = is_numeric($k) ? 'item' . $k : $k;
            $string .= $space . "<{$name}>\r\n" . dr_array2xml($v, $htmlon, $isnormal, $level + 1) . $space . "</{$name}>\r\n";
        }
    }
    $string = preg_replace("/([-\v-\f-])+/", ' ', $string);
    return $level == 1 ? $string . '</result>' : $string;
}
Exemplo n.º 2
0
 /**
  * 自定义数据调用(新版本)
  */
 public function data2()
 {
     // 安全认证码
     $auth = $this->input->get('auth');
     if ($auth != md5(SYS_KEY)) {
         // 安全认证码不正确
         $data = array('error' => '安全认证码不正确');
     } else {
         // 解析数据
         $data = $this->template->list_tag($this->input->get('param'));
     }
     // 接收参数
     $format = $this->input->get('format');
     // 页面输出
     if ($format == 'xml') {
         header('Content-Type: text/xml');
         echo dr_array2xml($data, FALSE);
     } elseif ($format == 'jsonp') {
         echo $this->input->get('callback') . '(' . json_encode($data) . ')';
     } else {
         echo json_encode($data);
     }
 }
Exemplo n.º 3
0
 /**
  * 自定义数据调用(新版本)
  */
 public function data2()
 {
     // 安全认证码
     $auth = $this->input->get('auth');
     if ($auth != md5(SYS_KEY)) {
         // 安全认证码不正确
         $data = array('error' => '安全认证码不正确');
     } else {
         // 解析数据
         $data = $this->template->list_tag($this->input->get('param'));
     }
     $title = $this->input->get('title');
     $description = $this->input->get('description');
     // 接收参数
     $format = $this->input->get('format');
     $data = arrayToObject($data);
     $data = object_array($data->return);
     foreach ($data as $k => $d) {
         $s[] = $d;
         if ($title) {
             $s[$k][title] = mb_substr($data[$k][title], 0, $title);
         }
         if ($description) {
             $s[$k][description] = mb_substr($data[$k][description], 0, $description);
         }
         $s[$k][newthumb] = dr_file_info($data[$k][thumb]);
         $s[$k][newthumb] = $s[$k][newthumb][attachment];
     }
     // 页面输出
     if ($format == 'xml') {
         header('Content-Type: text/xml');
         echo dr_array2xml($data, FALSE);
     } elseif ($format == 'jsonp') {
         echo $this->input->get('callback') . '(' . json_encode($s) . ')';
     } else {
         echo json_encode($data);
     }
 }
Exemplo n.º 4
0
 /**
  * 自定义数据调用(新版本)
  */
 public function data2()
 {
     // 安全认证码
     $auth = $this->input->get('auth');
     if ($auth != md5(SYS_KEY)) {
         // 安全认证码不正确
         $data = array('error' => '安全认证码不正确');
     } else {
         // 解析数据
         $param = $this->input->get('param');
         if ($param == 'login') {
             // 登录认证
             $code = $this->member_model->login($this->input->get('username'), $this->input->get('password'), 0, 1);
             if (is_array($code)) {
                 $data = $this->member_model->get_member($code['uid']);
             } elseif ($code == -1) {
                 $data = array('error' => lang('m-003'));
             } elseif ($code == -2) {
                 $data = array('error' => lang('m-004'));
             } elseif ($code == -3) {
                 $data = array('error' => lang('m-005'));
             } elseif ($code == -4) {
                 $data = array('error' => lang('m-006'));
             }
         } else {
             // list数据查询
             $data = $this->template->list_tag($param);
         }
     }
     // 接收参数
     $format = $this->input->get('format');
     // 页面输出
     if ($format == 'xml') {
         header('Content-Type: text/xml');
         echo dr_array2xml($data, FALSE);
     } elseif ($format == 'jsonp') {
         echo $this->input->get('callback') . '(' . json_encode($data) . ')';
     } else {
         echo json_encode($data);
     }
 }