示例#1
0
<?php

require $_SERVER['DOCUMENT_ROOT'] . '/includes/config.inc';
$meta = decode_json(realpath("meta.json"));
extract($meta, EXTR_OVERWRITE);
setPageTitle($title);
require "../../../resources/template.inc";
示例#2
0
 /**
  * Evaluates the XML converted to array and applies the expected format
  *
  * @param array $master The main array
  * @param boolean $isChild Stablish if iterating over a master or a child
  *
  * @return array The well formated array for further processing
  */
 protected function _parseXML($master, $isChild = false)
 {
     $fields = array();
     if (count($master)) {
         foreach ($master as $val) {
             // init vars
             $name = $val['name'];
             $attrs = $val['attributes'];
             $childs = isset($val['childs']) ? $val['childs'] : array();
             if ($name == 'loadfield') {
                 // get field from json
                 if ($json = $this->app->path->path("zlfield:json/{$attrs['type']}.json.php")) {
                     $fields[] = decode_json(include $json, true);
                 } else {
                     $fields[] = array('notice' => array("type" => "info", "specific" => array("text" => JText::_('PLG_ZLFRAMEWORK_ZLFD_FIELD_NOT_FOUND'))));
                 }
             } else {
                 if ($isChild) {
                     $fields = array_merge($fields, array($name => array_merge($attrs, $this->_parseXML($childs, true))));
                 } else {
                     // get field id and remove from attributes
                     $id = $attrs['id'];
                     unset($attrs['id']);
                     // merge val attributes
                     $field = array($id => array_merge($attrs, $this->_parseXML($childs, true)));
                     // merge result
                     $fields = array_merge($fields, $field);
                 }
             }
         }
     }
     return $fields;
 }
示例#3
0
文件: index.php 项目: hunanhd/cbm
function mockups_to_soui_xml($jsonfile, $bMainWnd = true)
{
    if (!is_file($jsonfile)) {
        return '';
    }
    //从文件中读取json字符串
    $json = file_get_contents($jsonfile);
    // var_dump(decode_json($json, true));
    //解析成json数组对象
    $mockup = decode_json($json, true)['mockup'];
    //创建一个XML文档并设置XML版本和编码
    $doc = new DomDocument();
    //$doc->preserveWhiteSpace = false;
    //$doc->formatOutput = true;
    //xml输出的时候要加上编码,否则输出的中文变成一堆奇怪的符号
    $doc->encoding = 'UTF-8';
    //界面的宽度和高度
    $wnd_width = intval($mockup['mockupW']);
    $wnd_height = intval($mockup['mockupH']);
    //图形的宽度和高度(包含多出的空白部分)
    $fig_width = intval($mockup['measuredW']);
    $fig_height = intval($mockup['measuredH']);
    //left和top的偏移量
    $dx = $fig_width - $wnd_width;
    $dy = $fig_height - $wnd_height;
    $root_attribs = null;
    if ($bMainWnd) {
        $root_attribs = array('width' => $wnd_width, 'height' => $wnd_height);
    }
    //创建根节点
    $root = create_root($doc, $root_attribs);
    //所有子控件
    $controls = $mockup['controls']['control'];
    foreach ($controls as $control) {
        //定义属性数组
        $attribs = array();
        //控件的坐标位置
        $left = intval($control['x']) - $dx;
        $top = intval($control['y']) - $dy;
        $attribs['pos'] = $left . "," . $top;
        //控件的宽度和高度属性
        $attribs['width'] = intval($control['measuredW']);
        $attribs['height'] = intval($control['measuredH']);
        if (isset($control['w'])) {
            $attribs['width'] = intval($control['w']);
        }
        if (isset($control['h'])) {
            $attribs['height'] = intval($control['h']);
        }
        //微调(margin-x和margin-y设为1后导致label显示不全,稍微增大宽度和高度用于抵消被margin吃掉的空间)
        $attribs['width'] = $attribs['width'] + 2;
        // $attribs['height'] = $attribs['height'] + 2;
        //控件类型(mockups类型映射到soui控件类型)
        $type = mockups_type_to_soui_type($control['typeID']);
        if ($type == 'unknown') {
            if ($control['typeID'] == 'StickyNote') {
                //从Comment中提取skin(字符串用换行分隔)
                $skin_text = $control['properties']['text'];
                $skins = explode("\\n", $skin_text);
                foreach ($skins as $skin_name) {
                    addToSkin($doc, $skin_name, "img");
                    // addToSkin($doc, $skin_name, "ico");
                }
            } else {
                echo '<h1>暂不支持' . $control['typeID'] . '控件!!!</h1><br>';
            }
            //销毁内存
            unset($attribs);
            //跳过该次循环
            continue;
        } else {
            echo '<h1>' . $control['typeID'] . '-->' . $type . '</h1><br>';
        }
        if (isset($control['properties']['state'])) {
            if ($control['properties']['state'] == 'disabled') {
                // $attribs['enable'] = 0;
            }
        }
        //控件的字体属性
        $font_attrib = '';
        if (isset($control['properties']['underline'])) {
            $font_attrib = $font_attrib . ',underline:' . intval($control['properties']['underline'] == 'true');
        }
        if (isset($control['properties']['italic'])) {
            $font_attrib = $font_attrib . ',italic:' . intval($control['properties']['italic'] == 'true');
        }
        if (isset($control['properties']['bold'])) {
            $font_attrib = $font_attrib . ',bold:' . intval($control['properties']['bold'] == 'true');
        }
        if ($font_attrib != '') {
            $attribs['font'] = $font_attrib;
        }
        //所有控件增加边框,便于观察
        //后期可以用样式class进行替代或删除该属性
        // $attribs['ncSkin'] = '_skin.sys.border';
        if ($type == 'edit' || $type == 'richedit') {
            if (isset($control['properties']['state'])) {
                if ($control['properties']['state'] == 'disabled') {
                    unset($attribs['enable']);
                    // $attribs['readOnly'] = 1;
                }
            }
        }
        if ($type == 'check' || $type == 'radio') {
            $attribs['width'] = $attribs['width'] + 30;
            if (isset($control['properties']['state'])) {
                if ($control['properties']['state'] == 'selected') {
                    $attribs['checked'] = 1;
                }
            }
        }
        //listbox要特殊处理
        if ($type == 'listbox') {
            $attribs['itemHeight'] = '21';
            //高亮显示鼠标所在位置的item
            $attribs['hotTrack'] = 1;
            //$attribs['selectedIndex'] = '1';
            if (isset($control['properties']['rowHeight'])) {
                $attribs['itemHeight'] = $control['properties']['rowHeight'];
            }
        }
        //link要特殊处理
        if ($type == 'link') {
            $attribs['href'] = 'http://about:blank';
            // 默认打开空白页面
            if (isset($control['properties']['href'])) {
                $attribs['href'] = $control['properties']['href']['URL'];
                $attribs['class'] = 'cls_btn_weblink';
                //$attribs['cursor'] = "hand";
            }
        }
        //slider要特殊处理
        if ($type == 'sliderbar') {
            $attribs['value'] = '0';
            $attribs['min'] = '0';
            $attribs['max'] = '100';
            if (isset($control['properties']['value'])) {
                $attribs['value'] = $control['properties']['value'];
            }
            if ($control['typeID'] == 'VSlider') {
                $attribs['vertical'] = 1;
                //调整slider的宽度或高度,否则会出现一个多余的拖动按钮(原因未知!!)
                $attribs['width'] = $attribs['width'] + 8;
            } else {
                if ($control['typeID'] == 'HSlider') {
                    //调整slider的宽度或高度,否则会出现一个多余的拖动按钮(原因未知!!)
                    $attribs['height'] = $attribs['height'] + 8;
                }
            }
        }
        //进度条progress特殊处理
        if ($type == 'progress') {
            $attribs['scrollBarValue'] = '0';
            $attribs['min'] = '0';
            $attribs['max'] = '100';
            if (isset($control['properties']['scrollBarValue'])) {
                $attribs['value'] = $control['properties']['scrollBarValue'];
            }
            $attribs['showPercent'] = 1;
        }
        //设置水平或垂直线的线型
        if ($type == 'hr') {
            $attribs['lineStyle'] = 'solid';
            if (isset($control['properties']['stroke'])) {
                $lineStyle = $control['properties']['stroke'];
                if ($lineStyle == 'dashed') {
                    $lineStyle = 'dash';
                } else {
                    if ($lineStyle == 'dotted') {
                        $lineStyle = 'dot';
                    }
                }
                $attribs['lineStyle'] = $lineStyle;
            }
            //水平线或垂直线
            if ($control['typeID'] == 'HRule') {
                $attribs['mode'] = 'horizontal';
                $attribs['height'] = 1;
                //  强制修改水平线的宽度为1,如若按照原本的height显示效果比较难看!
            } else {
                if ($control['typeID'] == 'VRule') {
                    $attribs['mode'] = 'vertical';
                    $attribs['width'] = 1;
                    //  强制修改垂直线的宽度为1,如若按照原本的width显示效果比较难看!
                }
            }
        }
        //列表控件
        if ($type == 'listctrl') {
            $attribs['hotTrack'] = 1;
            $attribs['itemHeight'] = '20';
            $attribs['headerHeight'] = '30';
            if (isset($control['properties']['rowHeight'])) {
                $attribs['itemHeight'] = $control['properties']['rowHeight'];
                $attribs['headerHeight'] = $control['properties']['rowHeight'];
            }
            $attribs['align'] = 'left';
            if (isset($control['properties']['align'])) {
                $attribs['align'] = $control['properties']['align'];
            }
        }
        //treectrl控件
        if ($type == 'treectrl') {
            $attribs['itemHeight'] = "30";
            $attribs['checkBox'] = "1";
        }
        //combobox控件
        if ($type == 'combobox') {
            //下拉列表(edit不可编辑)
            $attribs['dropDown'] = 1;
            $attribs['curSel'] = 0;
        }
        //tab控件
        if ($type == 'tabctrl') {
            // $attribs['clipClient'] = 1;
            $attribs['tabAlign'] = 'top';
            //$attribs['tabWidth'] = "70";
            //$attribs['tabHeight'] = "38";
            //$attribs['tabInterSize'] = "0";
            //$attribs['tabPos'] = "10";
            //$attribs['dotted'] = "0";
            //$attribs['animateSteps'] = "10";
            if ($control['typeID'] == 'VerticalTabBar') {
                $attribs['tabAlign'] = 'left';
            } else {
                if ($control['typeID'] == 'TabBar') {
                    $attribs['tabAlign'] = 'top';
                }
            }
        }
        //group控件
        if ($type == 'group') {
            $attribs['align'] = 'left';
            // $attribs['clipClient'] = 1;
        }
        //window控件
        if ($type == 'window') {
            // $attribs['align'] = 'left';
            // $attribs['clipClient'] = 1;
        }
        //控件的其它属性
        //mockups提供了一种自定义属性功能(一个customID对应一个customData)
        //这2个字段可以是任意类型的数据
        //本程序规定customData以json格式传入自定义数据,从而补充mockups没有的一些属性和数据
        //比如name, min, max等等
        $zOrder = mockups_type_to_soui_type($control['zOrder']);
        // 图形的绘图顺序编号(也决定了图形的层位/遮挡关系)
        $name = mockups_type_to_soui_type($control['typeID']);
        $attribs['name'] = $name . $control['ID'];
        if (isset($control['properties']['customData'])) {
            $json_datas = trim($control['properties']['customData']);
            //json数据中的引号等符号被用url方式进行编码转义了,比如空格变成了%22,需要进行解码
            $json_datas = urldecode($json_datas);
            //将%u替换成\u
            $json_datas = str_replace('%u', '\\u', $json_datas);
            if (!empty($json_datas)) {
                //合并附加的json属性数据
                $more_attribs = decode_json($json_datas, true);
                if (!is_null($more_attribs)) {
                    foreach ($more_attribs as $key => $value) {
                        if (is_array($value)) {
                            $value = json_encode($value);
                        } else {
                            $value = escapeUnicodeString($value);
                        }
                        $more_attribs[$key] = $value;
                    }
                    //合并2个属性关联数组
                    $attribs = array_merge($attribs, $more_attribs);
                    //销毁内存
                    unset($more_attribs);
                }
            }
        }
        //控件上的文本内容
        $text = '';
        if (isset($control['properties']['text'])) {
            $text = $control['properties']['text'];
        }
        //创建子控件节点
        $control = create_node($doc, $type, $text, $attribs);
        $root->appendChild($control);
        //某些控件需要增加子节点,比如listbox
        postProcess($doc, $control, $type);
        //增加局部皮肤
        postProcessSkin($doc, $control, $type, "img");
        //销毁内存
        unset($attribs);
    }
    //调整节点顺序(主要是caption节点)
    adjust_node_seq($doc);
    return $doc->saveXML();
    //$doc->save($xmlfile);
}