public function create_show($id, $module)
 {
     C('DEFAULT_THEME_NAME', $this->sysConfig['DEFAULT_THEME']);
     C('HTML_FILE_SUFFIX', $this->sysConfig['HTML_FILE_SUFFIX']);
     C('TMPL_FILE_NAME', str_replace('Admin/Default', 'Home/' . $this->sysConfig['DEFAULT_THEME'], C('TMPL_FILE_NAME')));
     if (APP_LANG) {
         $lang = C('URL_LANG') != LANG_NAME ? $lang = LANG_NAME . '/' : '';
         L(include LANG_PATH . LANG_NAME . '/common.php');
         $T = F('config_' . LANG_NAME, '', './Template/' . $this->sysConfig['DEFAULT_THEME'] . '/');
     } else {
         L(include LANG_PATH . $this->sysConfig['DEFAULT_LANG'] . '/common.php');
         $T = F('config_' . $this->sysConfig['DEFAULT_LANG'], '', './Template/' . $this->sysConfig['DEFAULT_THEME'] . '/');
     }
     $this->assign('T', $T);
     $search_module[0] = L('ALL');
     foreach ((array) $this->module as $r) {
         if ($r['issystem']) {
             $search_module[$r['id']] = L($r['name']);
         }
     }
     $this->assign('search_module', $search_module);
     $this->assign('form', new Form());
     $p = 1;
     $id = intval($id);
     if (empty($id)) {
         $this->success(L('do_empty'));
     }
     $this->assign($this->Config);
     $this->assign('Categorys', $this->categorys);
     $this->assign('Module', $this->module);
     $this->assign('Type', $this->Type);
     $this->assign('module_name', $module);
     $dao = M($module);
     $data = $dao->find($id);
     $catid = $data['catid'];
     $this->assign('catid', $catid);
     $cat = $this->categorys[$data['catid']];
     $this->assign($cat);
     $bcid = explode(",", $cat['arrparentid']);
     $bcid = $bcid[1];
     if ($bcid == '') {
         $bcid = intval($catid);
     }
     $this->assign('bcid', $bcid);
     $seo_title = $data['title'] . '-' . $cat['catname'];
     $this->assign('seo_title', $seo_title);
     $this->assign('seo_keywords', $data['keywords']);
     $this->assign('seo_description', $data['description']);
     $fields = F($this->mod[$module] . '_Field');
     foreach ($data as $key => $c) {
         $setup = '';
         $fields[$key]['setup'] = $setup = string2array($fields[$key]['setup']);
         if ($setup['fieldtype'] == 'varchar' && $fields[$key]['type'] != 'text') {
             $data[$key . '_old_val'] = $data[$key];
             $data[$key] = fieldoption($fields[$key], $data[$key]);
         } elseif ($fields[$key]['type'] == 'images' || $fields[$key]['type'] == 'files') {
             $p_data = explode(':::', $data[$key]);
             $data[$key] = array();
             foreach ($p_data as $k => $res) {
                 $p_data_arr = explode('|', $res);
                 $data[$key][$k]['filepath'] = $p_data_arr[0];
                 $data[$key][$k]['filename'] = $p_data_arr[1];
             }
             unset($p_data);
             unset($p_data_arr);
         }
         unset($setup);
     }
     $this->assign('fields', $fields);
     $this->assign('form', new Form());
     $urlrule = geturl($cat, $data, $this->Urlrule);
     if (!empty($data['template'])) {
         $template = $cat['module'] . '_' . $data['template'];
     } elseif (!empty($cat['template_show'])) {
         $template = $cat['module'] . '_' . $cat['template_show'];
     } else {
         $template = $cat['module'] . '_show';
     }
     //手动分页
     $CONTENT_POS = strpos($data['content'], '[page]');
     if ($CONTENT_POS !== false) {
         $pageurls = array();
         $contents = array_filter(explode('[page]', $data['content']));
         $pagenumber = count($contents);
         for ($i = 1; $i <= $pagenumber; $i++) {
             $pageurls[$i] = str_replace('{$p}', $i, $urlrule);
         }
         //生成分页
         foreach ($pageurls as $p => $urls) {
             $pages = content_pages($pagenumber, $p, $pageurls);
             $this->assign('pages', $pages);
             $data['content'] = $contents[$p - 1];
             $this->assign($data);
             $url = $p > 1 ? $urls[1] : $urls[0];
             if (strstr($url, C('HTML_FILE_SUFFIX'))) {
                 $filename = basename($url, C('HTML_FILE_SUFFIX'));
                 $dir = dirname($url) . '/';
             } else {
                 $filename = 'index';
                 $dir = $url;
             }
             $dir = substr($dir, strlen(YP_PATH . '/'));
             $this->buildHtml($filename, $dir, './Template/' . $this->sysConfig['DEFAULT_THEME'] . '/' . $template . C('TMPL_TEMPLATE_SUFFIX'));
         }
     } else {
         $url = str_replace('$page', $p, $urlrule[0]);
         if (strstr($url, C('HTML_FILE_SUFFIX'))) {
             $filename = basename($url, C('HTML_FILE_SUFFIX'));
             $dir = dirname($url) . '/';
         } else {
             $filename = 'index';
             $dir = $url;
         }
         $this->assign('pages', '');
         $this->assign($data);
         $dir = substr($dir, strlen(YP_PATH . '/'));
         $this->buildHtml($filename, $dir, './Template/' . $this->sysConfig['DEFAULT_THEME'] . '/' . $template . C('TMPL_TEMPLATE_SUFFIX'));
     }
     return true;
 }
Esempio n. 2
0
 public function show($id = '', $module = '')
 {
     $this->Urlrule = F('Urlrule');
     $p = max(intval($_REQUEST[C('VAR_PAGE')]), 1);
     $id = $id ? $id : intval($_REQUEST['id']);
     $module = $module ? $module : MODULE_NAME;
     $this->assign('module_name', $module);
     $this->dao = M($module);
     $data = $this->dao->find($id);
     $catid = $data['catid'];
     $cat = $this->categorys[$data['catid']];
     if (empty($cat['ishtml'])) {
         $this->dao->where("id=" . $id)->setInc('hits');
     }
     //添加点击次数
     $bcid = explode(",", $cat['arrparentid']);
     $bcid = $bcid[1];
     if ($bcid == '') {
         $bcid = intval($catid);
     }
     if ($data['readgroup']) {
         if ($this->_groupid != 1 && !in_array($this->_groupid, explode(',', $data['readgroup']))) {
             $noread = 1;
         }
     } elseif ($cat['readgroup']) {
         if ($this->_groupid != 1 && !in_array($this->_groupid, explode(',', $cat['readgroup']))) {
             $noread = 1;
         }
     }
     if ($noread == 1) {
         $this->assign('jumpUrl', URL('User-Login/index'));
         $this->error(L('NO_READ'));
     }
     $chargepoint = $data['readpoint'] ? $data['readpoint'] : $cat['chargepoint'];
     if ($chargepoint && $data['userid'] != $this->_userid) {
         $user = M('User');
         $userdata = $user->find($this->_userid);
         if ($cat['paytype'] == 1 && $userdata['point'] >= $chargepoint) {
             $chargepointok = $user->where("id=" . $this->_userid)->setDec('point', $chargepoint);
         } elseif ($cat['paytype'] == 2 && $userdata['amount'] >= $chargepoint) {
             $chargepointok = $user->where("id=" . $this->_userid)->setDec('amount', $chargepoint);
         } else {
             $this->error(L('NO_READ'));
         }
     }
     $seo_title = $data['title'] . '|' . $cat['catname'];
     $this->assign('seo_title', $seo_title);
     $this->assign('seo_keywords', $data['keywords']);
     $this->assign('seo_description', $data['description']);
     $this->assign('fields', F($cat['moduleid'] . '_Field'));
     $fields = F($this->mod[$module] . '_Field');
     foreach ($data as $key => $c_d) {
         $setup = '';
         $fields[$key]['setup'] = $setup = string2array($fields[$key]['setup']);
         if ($setup['fieldtype'] == 'varchar' && $fields[$key]['type'] != 'text') {
             $data[$key . '_old_val'] = $data[$key];
             $data[$key] = fieldoption($fields[$key], $data[$key]);
         } elseif ($fields[$key]['type'] == 'images' || $fields[$key]['type'] == 'files') {
             if (!empty($data[$key])) {
                 $p_data = explode(':::', $data[$key]);
                 $data[$key] = array();
                 foreach ($p_data as $k => $res) {
                     $p_data_arr = explode('|', $res);
                     $data[$key][$k]['filepath'] = $p_data_arr[0];
                     $data[$key][$k]['filename'] = $p_data_arr[1];
                 }
                 unset($p_data);
                 unset($p_data_arr);
             }
         }
         unset($setup);
     }
     $this->assign('fields', $fields);
     //手动分页
     $CONTENT_POS = strpos($data['content'], '[page]');
     if ($CONTENT_POS !== false) {
         $urlrule = geturl($cat, $data, $this->Urlrule);
         $urlrule = str_replace('%7B%24page%7D', '{$page}', $urlrule);
         $contents = array_filter(explode('[page]', $data['content']));
         $pagenumber = count($contents);
         for ($i = 1; $i <= $pagenumber; $i++) {
             $pageurls[$i] = str_replace('{$page}', $i, $urlrule);
         }
         $pages = content_pages($pagenumber, $p, $pageurls);
         //判断[page]出现的位置是否在文章开始
         if ($CONTENT_POS < 7) {
             $data['content'] = $contents[$p];
         } else {
             $data['content'] = $contents[$p - 1];
         }
         $this->assign('pages', $pages);
     }
     if (!empty($data['template'])) {
         $template = $data['template'];
     } elseif (!empty($cat['template_show'])) {
         $template = $cat['template_show'];
     } else {
         $template = 'show';
     }
     $this->assign('catid', $catid);
     $this->assign($cat);
     $this->assign('bcid', $bcid);
     $this->assign($data);
     $this->display($module . ':' . $template);
 }