/** * 替换模板中的PC标签 * @param $filepath 文件地址 * @param $old_tag 老PC标签 * @param $new_tag 新PC标签 * @param $style 风格 * @param $dir 目录名 */ function replace_pc_tag($filepath, $old_tag, $new_tag, $style, $dir) { if (file_exists($filepath)) { creat_template_bak($filepath, $style, $dir); $data = @file_get_contents($filepath); $data = str_replace($old_tag, $new_tag, $data); if (!is_writable($filepath)) return false; @file_put_contents($filepath, $data); return true; } }
public function edit_file() { if (empty($this->tpl_edit)) { showmessage(L('tpl_edit')); } $dir = isset($_GET['dir']) && trim($_GET['dir']) ? str_replace(array('..\\', '../', './', '.\\'), '', urldecode(trim($_GET['dir']))) : ''; $file = isset($_GET['file']) && trim($_GET['file']) ? trim($_GET['file']) : ''; if ($file) { preg_match('/^([a-zA-Z0-9])?([^.|-|_]+)/i', $file, $file_t); $file_t = $file_t[0]; $file_t_v = array('header' => array('{$SEO[\'title\']}' => L('seo_title'), '{$SEO[\'site_title\']}' => L('site_title'), '{$SEO[\'keyword\']}' => L('seo_keyword'), '{$SEO[\'description\']}' => L('seo_des')), 'category' => array('{$catid}' => L('cat_id'), '{$catname}' => L('cat_name'), '{$url}' => L('cat_url'), '{$r[catname]}' => L('cat_name'), '{$r[url]}' => 'URL', '{$CATEGORYS}' => L('cats')), 'list' => array('{$catid}' => L('cat_id'), '{$catname}' => L('cat_name'), '{$url}' => L('cat_url'), '{$CATEGORYS}' => L('cats')), 'show' => array('{$title}' => L('title'), '{$inputtime}' => L('inputtime'), '{$copyfrom}' => L('comeform'), '{$content}' => L('content'), '{$previous_page[url]}' => L('pre_url'), '{$previous_page[title]}' => L('pre_title'), '{$next_page[url]}' => L('next_url'), '{$next_page[title]}' => L('next_title')), 'page' => array('{$CATEGORYS}' => L('cats'), '{$content}' => L('content'))); } if (substr($file, -4, 4) != 'html') { showmessage(L("can_edit_html_files")); } $filepath = $this->filepath . $dir . DIRECTORY_SEPARATOR . $file; $is_write = 0; if (is_writable($filepath)) { $is_write = 1; } if ($_POST['dosubmit']) { $code = isset($_POST['code']) ? stripslashes($_POST['code']) : showmessage(L('illegal_operation'), HTTP_REFERER); $code = str_replace(array('<?', '{php'), array('<?', '{ php'), $code); if ($is_write == 1) { pc_base::load_app_func('global'); creat_template_bak($filepath, $this->style, $dir); file_put_contents($filepath, htmlspecialchars_decode($code)); showmessage(L('operation_success'), HTTP_REFERER); } else { showmessage(L("file_does_not_writable"), HTTP_REFERER); } } else { if (file_exists($filepath)) { $data = new_html_special_chars(file_get_contents($filepath)); } else { showmessage(L('file_does_not_exists')); } } $show_header = true; include $this->admin_tpl('file_edit_file'); }