コード例 #1
0
ファイル: magic.class.php プロジェクト: h3len/Project
 /**
  * 处理单元、生成单元的html
  * 
  * @param array $info 单元详细信息
  * @param boolean $force 是否强制生成单元缓存
  * @param array $arData 数据、有此参数时用该数据生成单元hmtl 用于单元预览
  * @param array 处理过后的单元详细信息
  */
 public function cellProcess($info, $force = false, $arData = array())
 {
     if (!$info['cell_mode']) {
         //return array();
     }
     /**********专题栏目链接处理***************************/
     if (strpos($info['more_href'], 'COLURL') !== false) {
         $intColumnId = intval(str_replace('COLURL', '', $info['more_href']));
         if (!class_exists('special')) {
             include ROOT_PATH . 'lib/class/special.class.php';
         }
         $objSpecial = new special();
         $info['more_href'] = $objSpecial->get_special_col_url($intColumnId);
     }
     /**********专题栏目链接处理***************************/
     $mode_info = common::get_mode_info(intval($info['cell_mode']), $info['id'], intval($info['css_id']), intval($info['js_id']), $info['param_asso']);
     $blBuiltCell = $this->blBuiltCell && $this->blBuiltCell !== 'false' ? 1 : 0;
     if ($info['cell_type'] == 3 && $blBuiltCell) {
         $html = $info['static_html'];
     } else {
         $content = $mode_info['mode_info']['content'];
         $content = str_replace(' ', ' ', $content);
         $ret_data = array();
         if (!$info['data_source']) {
             $map = common::get_mode_map($mode_info);
             if ($blBuiltCell) {
                 $ret_data = !empty($arData) ? $arData : $mode_info['mode_info']['default_param'];
             }
             $ret_data = $info['using_block'] ? common::getBlockData($info['block_id']) : $ret_data;
         } else {
             $data_source = common::get_datasource_info($info['data_source'], $info['param_asso']);
             if ($info['using_block'] && $blBuiltCell) {
                 $ret_data = !empty($arData) ? $arData : common::getBlockData($info['block_id']);
             } else {
                 $map = common::get_cell_map($mode_info, $data_source, $info['param_asso']);
                 if ($blBuiltCell) {
                     $ret_data = common::get_content_by_datasource($info['data_source'], $map['data_input_variable']);
                     if (isset($ret_data['total'])) {
                         $intTotal = $ret_data['total'];
                         $ret_data = $ret_data['data'];
                     }
                     if (!$info['layout_id']) {
                         //替换已经编辑过的单元数据
                         if (!class_exists('cell')) {
                             include CUR_CONF_PATH . 'lib/cell.class.php';
                         }
                         $objCell = new cell();
                         $arCellData = $objCell->getCellData($info['id']);
                         if (is_array($ret_data) && count($ret_data) > 0) {
                             foreach ($ret_data as $k => $v) {
                                 !empty($arCellData[$v['id']]) && ($arCellData[$v['id']]['id'] = $arCellData[$v['id']]['content_id']);
                                 $ret_data[$k] = !empty($arCellData[$v['id']]) ? $arCellData[$v['id']] : $v;
                                 if (!empty($arData)) {
                                     if ($v['id'] == $arData['content_id']) {
                                         //arData 预览提交的数据
                                         $arData['id'] = $arData['content_id'];
                                         $ret_data[$k] = $arData;
                                     }
                                 }
                             }
                         }
                     }
                     if (isset($intTotal)) {
                         $ret_data = array('total' => $intTotal, 'data' => $ret_data);
                     }
                 }
             }
         }
         $cache_file = $info['layout_id'] ? $info['id'] . '_' . $info['layout_id'] . '.php' : $info['id'] . '.php';
         $cache_filepath = MODE_CACHE_DIR . substr(md5($cache_file), 0, 2) . '/';
         include_once CUR_CONF_PATH . 'lib/parse.class.php';
         $parse = new Parse();
         $parse->parse_template(stripcslashes($content), $info['id'], $mode_info['mode_info'], $map['relation_map'], $map['mode_variable_map'], $map['variable_function_relation']);
         if ($blBuiltCell) {
             if (MAGIC_DEBUG) {
                 $path = CUR_CONF_PATH . 'cache/log/data/';
                 hg_mkdir($path);
                 hg_file_write($path . $info['id'] . '.txt', var_export($map['data_input_variable'], 1) . var_export($ret_data, 1));
             }
             $html = $parse->built_cell_html($ret_data, $cache_file, $mode_info['mode_info'], $this->arNeedPageInfo, $this->arPageSiteInfo, $this->arPageColumnInfo, $this->arPageClientInfo, $this->arPageSpecialInfo, $this->arPageSpecialColumnInfo, $map['data_input_variable'], $force, $cache_filepath);
             if ($info['is_header']) {
                 $find = array('{$header_text}', '{$more_href}', '{$more_text}');
                 $replace = array($info['header_text'], $info['is_more'] ? $info['more_href'] : '#', $info['is_more'] ? '更多>>' : '');
                 $header = str_replace($find, $replace, $this->settings['header_dom']['cell']);
                 $html = $header . $html;
             }
             // if (empty($ret_data)) {
             // $html = '<span>暂无数据</span>' . $html;
             // }
         } else {
             $parse->built_mode_cache($cache_file, $cache_filepath);
         }
     }
     $ret = array();
     $ret = array_merge($info, $mode_info);
     $ret['mode_detail'] = $ret['mode_info'];
     //生成时用
     unset($ret['mode_info']);
     !$ret['using_block'] && $ret['data_source'] && ($ret['can_edit'] = 1);
     //有数据源且不是区块单元时单元数据可编辑
     $ret['rended_html'] = $html;
     $ret['input_param'] = $data_source['input_param'];
     $ret['site_id'] = $this->intSiteId;
     $ret['page_id'] = $this->intPageId;
     $ret['page_data_id'] = $this->intPageDataId;
     $ret['content_type'] = $this->intContentType;
     if ($blBuiltCell) {
         $strNsPre = $ret['layout_id'] ? 'layout_cell' : 'cell';
         $ret['css'] = str_replace('<MATEURL>', ICON_URL, preg_replace('/<NS([0-9a-zA-Z]*)>/', '.' . $strNsPre . '_' . $ret['id'] . '_\\1', $ret['css']));
         $ret['js'] = str_replace('<MATEURL>', ICON_URL, preg_replace('/<NS([0-9a-zA-Z]*)>/', '.' . $strNsPre . '_' . $ret['id'] . '_\\1', $ret['js']));
         $ret['rended_html'] = str_replace('<MATEURL>', ICON_URL, preg_replace('/<NS([0-9a-zA-Z]*)>/', $strNsPre . '_' . $ret['id'] . '_\\1', $ret['rended_html']));
         $ret['css'] = preg_replace('/<NNS([0-9a-zA-Z]*)>/', $strNsPre . '_' . $ret['id'] . '_\\1', $ret['css']);
         $ret['js'] = preg_replace('/<NNS([0-9a-zA-Z]*)>/', $strNsPre . '_' . $ret['id'] . '_\\1', $ret['js']);
         $ret['rended_html'] = preg_replace('/<NNS([0-9a-zA-Z]*)>/', $strNsPre . '_' . $ret['id'] . '_\\1', $ret['rended_html']);
         if ($this->input['data'] == 1 || $this->input['return_data'] == 1) {
             if (is_array($ret_data) && count($ret_data) > 0) {
                 foreach ($ret_data as $k => $v) {
                     $ret['data'][] = array('id' => $v['id'], 'title' => $v['title'], 'brief' => $v['brief'], 'indexpic' => $v['indexpic'], 'content_url' => $v['content_url']);
                 }
             }
         }
     }
     return $ret;
 }
コード例 #2
0
ファイル: cell_update.php プロジェクト: h3len/Project
 function update()
 {
     $cell_id = intval($this->input['id']);
     $using_block = intval($this->input['using_block']);
     $data = array('site_id' => intval($this->input['site_id']), 'page_id' => intval($this->input['page_id']), 'page_data_id' => intval($this->input['page_data_id']), 'content_type' => $this->input['content_type'], 'cell_type' => intval($this->input['cell_type']), 'cell_code' => htmlspecialchars_decode($this->input['cell_code']), 'cell_mode' => $this->input['cell_mode'], 'using_block' => $using_block);
     if ($using_block) {
         $data['block_id'] = intval($this->input['block_id']);
     } else {
         $data['data_source'] = $this->input['data_source'];
     }
     if ($this->input['input_param']) {
         $param['input_param'] = $this->input['input_param'];
     }
     if ($this->input['mode_param']) {
         $param['mode_param'] = $this->input['mode_param'];
     }
     if ($this->input['assoc_param']) {
         $param['assoc_param'] = $this->input['assoc_param'];
     }
     $data['param_asso'] = '';
     if ($param) {
         $data['param_asso'] = serialize($param);
     }
     $condition = " AND site_id = " . $data['site_id'] . " AND page_id = " . $data['page_id'] . " AND page_data_id = " . $data['page_data_id'] . " AND content_type = " . $data['content_type'] . " AND cell_name='" . $this->input['title'] . "' AND original_id != 0 AND del=0";
     $info = $this->obj->detail($condition);
     if ($info) {
         $data['update_time'] = TIMENOW;
         $this->obj->update($data, $info['id']);
     } else {
         $data['original_id'] = $cell_id;
         //原单元id
         $data['cell_name'] = $this->input['title'];
         $data['template_style'] = $this->input['template_style'];
         $data['sort_id'] = intval($this->input['sort_id']);
         $data['template_id'] = intval($this->input['template_id']);
         $data['template_sign'] = $this->input['template_sign'];
         $data['user_id'] = $this->user['user_id'];
         $data['user_name'] = $this->user['user_name'];
         $data['appid'] = $this->user['appid'];
         $data['appname'] = $this->user['display_name'];
         $data['create_time'] = TIMENOW;
         $data['update_time'] = TIMENOW;
         $cell_id = $this->obj->create($data);
     }
     $cell_mode = common::get_mode_info($data['cell_mode']);
     $data_source = common::get_datasource_info($data['data_source']);
     $map = $this->obj->get_cell_map($cell_mode, $data_source, $param);
     $datafile = $this->settings['data_source_dir'] . $data['data_source'] . '.php';
     include_once $datafile;
     $classname = "ds_" . $data['data_source'];
     $obj = new $classname();
     $ret = $obj->show('');
     $cache_file = $cell_id . '_' . $data['data_source'] . '_' . $data['cell_mode'] . '.php';
     include_once CUR_CONF_PATH . 'lib/parse.class.php';
     $parse = new Parse();
     $content = html_entity_decode($cell_mode['mode_info']['content']);
     $parse->parse_template($content, $map['relation_map'], $map['mode_variable_map']);
     $html = $parse->built_cell_html($ret, $cache_file);
     $this->addItem($html);
     $this->output();
 }