Example #1
0
 public function get_mode_info($id, $cell_id = '', $css_id = '', $js_id = '', $param = array())
 {
     $ret = array();
     $sql = "SELECT * FROM " . DB_PREFIX . "cell_mode WHERE id = " . $id;
     $mode_info = $this->db->query_first($sql);
     $mode_info['default_param'] = $mode_info['default_param'] ? unserialize($mode_info['default_param']) : array();
     $sql = "SELECT * FROM " . DB_PREFIX . "cell_mode_variable  WHERE cell_mode_id=" . $id;
     $info = $this->db->query($sql);
     $mode_param = $data_param = array();
     while ($row = $this->db->fetch_array($info)) {
         if ($row['type'] == 'select') {
             $row['other_value'] = hg_string_to_array($row['other_value']);
         }
         ###合并参数
         $row['name'] = $row['name'] ? $row['name'] : $row['sign'];
         $row['value'] = isset($param['mode_param'][$row['sign']]) ? $param['mode_param'][$row['sign']] : $row['default_value'];
         $mode_param[$row['id']] = $row;
     }
     $sql = "SELECT * FROM " . DB_PREFIX . "cell_mode_code WHERE mode_id = " . $id . " AND type='js' AND del = 0 ";
     $mode_js_info = $this->db->query_first($sql);
     if ($mode_js_info) {
         $mode_js_info['para'] = unserialize($mode_js_info['para']);
         if (is_array($mode_js_info['para']) && count($mode_js_info['para']) > 0) {
             $relation = array();
             foreach ($mode_js_info['para'] as $k => $v) {
                 $v['js_other_value'] = hg_string_to_array($v['js_other_value']);
                 ###合并参数
                 $v['js_value'] = isset($param['js_param'][$v['js_sign']]) ? $param['js_param'][$v['js_sign']] : $v['js_default_value'];
                 ### 重新复制 使返回值名称统一
                 $variables[$v['js_sign']] = array('name' => $v['js_name'] ? $v['js_name'] : $v['js_sign'], 'sign' => $v['js_sign'], 'type' => $v['js_type'], 'other_value' => $v['js_other_value'], 'default_value' => $v['js_default_value'], 'value' => $v['js_value']);
                 $relation[$v['js_sign']] = $v['js_value'];
             }
             $ret['js_param'] = $variables;
         }
         $mode_js_info['code'] = html_entity_decode($mode_js_info['code'], ENT_QUOTES);
         if ($mode_js_info['code']) {
             if (!class_exists('Parse')) {
                 include_once CUR_CONF_PATH . 'lib/parse.class.php';
             }
             $parse = new Parse();
             $parse->parse_cssjs($mode_js_info['code'], $relation);
             $ret['js'] = $parse->built_cssjs($cell_id . '_' . $id . '_js' . '.php', true);
         }
     }
     $sql = "SELECT * FROM " . DB_PREFIX . "out_variable WHERE mod_id = 2  AND flag = 0 AND expand_id = " . $id;
     $q = $this->db->query($sql);
     while ($row = $this->db->fetch_array($q)) {
         $row['fuction_value'] = unserialize($row['fuction_value']);
         $row['fuction_value'] = $row['fuction_value'] ? $row['fuction_value'] : array();
         $row['fuction_value'] = implode("','", $row['fuction_value']);
         $row['fuction_value'] = "'" . $row['fuction_value'] . "'";
         $data_param[$row['id']] = $row;
     }
     ###css处理   js处理 命名空间替换、参数替换、格式化参数格式确保参数格式统一
     if ($css_id) {
         $sql = "SELECT * FROM " . DB_PREFIX . "cell_mode_code WHERE id = " . intval($css_id) . " AND del = 0 ";
         $q = $this->db->query($sql);
         while ($row = $this->db->fetch_array($q)) {
             $prefix = $row['type'];
             $relation = $variables = array();
             $row['para'] = unserialize($row['para']);
             if (is_array($row['para']) && count($row['para']) > 0) {
                 foreach ($row['para'] as $k => $v) {
                     $v[$prefix . '_other_value'] = hg_string_to_array($v[$prefix . '_other_value']);
                     ###合并参数
                     $v[$prefix . '_value'] = isset($param[$prefix . '_param'][$v[$prefix . '_sign']]) ? $param[$prefix . '_param'][$v[$prefix . '_sign']] : $v[$prefix . '_default_value'];
                     ### 重新复制 使返回值名称统一
                     $variables[$v[$prefix . '_sign']] = array('name' => $v[$prefix . '_name'] ? $v[$prefix . '_name'] : $v[$prefix . '_sign'], 'sign' => $v[$prefix . '_sign'], 'type' => $v[$prefix . '_type'], 'other_value' => $v[$prefix . '_other_value'], 'default_value' => $v[$prefix . '_default_value'], 'value' => $v[$prefix . '_value']);
                     $relation[$v[$prefix . '_sign']] = $v[$prefix . '_value'];
                 }
             }
             $ret[$prefix . '_code'] = html_entity_decode($row['code']);
             $ret[$prefix . '_param'] = $variables;
             if ($ret[$prefix . '_code']) {
                 if (!class_exists('Parse')) {
                     include_once CUR_CONF_PATH . 'lib/parse.class.php';
                 }
                 $parse = new Parse();
                 $parse->parse_cssjs($ret[$prefix . '_code'], $relation);
                 $ret[$prefix] = $parse->built_cssjs($cell_id . '_' . $id . '_' . $prefix . '.php', true);
             }
         }
     }
     ###css,js处理处理结束
     ##取样式的css列表
     $sql = "SELECT * FROM " . DB_PREFIX . "cell_mode_code WHERE mode_id = " . $id . " AND (cell_id = " . $cell_id . " OR cell_id = 0 ) AND type='css' AND del = 0 ";
     $q = $this->db->query($sql);
     $ret['css_list'] = array();
     while ($row = $this->db->fetch_array($q)) {
         $prefix = $row['type'];
         $row['para'] = unserialize($row['para']);
         if (is_array($row['para']) && count($row['para']) > 0) {
             $tmp = array();
             foreach ($row['para'] as $k => $v) {
                 $v[$prefix . '_other_value'] = hg_string_to_array($v[$prefix . '_other_value']);
                 $tmp[$v[$prefix . '_sign']] = array('name' => $v[$prefix . '_name'] ? $v[$prefix . '_name'] : $v[$prefix . '_sign'], 'sign' => $v[$prefix . '_sign'], 'type' => $v[$prefix . '_type'], 'other_value' => $v[$prefix . '_other_value'], 'default_value' => $v[$prefix . '_default_value'], 'value' => $v[$prefix . '_default_value']);
             }
             $row['para'] = $tmp;
         }
         //			$ret[$prefix . '_list'][$row['id']] = $row;
         $ret[$prefix . '_list'][] = $row;
     }
     $ret['mode_info'] = $mode_info;
     $ret['mode_param'] = $mode_param;
     $ret['data_param'] = $data_param;
     return $ret;
 }