<?php
include WPJAM_CONTENT_TEMPLATE_PLUGIN_DIR .'admin/hooks/template-type.php';
add_filter('wpjam_table_tabs', function(){
$post_id = wpjam_get_data_parameter('post_id');
$tabs = [
'table' => ['title'=>'表格设置', 'function'=>'wpjam_table_setting_page'],
'content' => ['title'=>'表格内容', 'function'=>'wpjam_table_no_fields_page'],
'bulk' => ['title'=>'批量编辑', 'function'=>'wpjam_table_bulk_edit_page']
];
if($post_id && get_post_meta($post_id, '_table_fields', true)){
// $table_post = get_post($post_id);
// if(empty($table_post->post_content)){
// $post_excerpt = maybe_unserialize($table_post->post_excerpt);
// if(is_array($post_excerpt)){
// $post_content = $table_post->post_excerpt;
// $post_excerpt = '';
// $post_arr = ['ID'=>$post_id, 'post_content'=>$post_content, 'post_excerpt'=>$post_excerpt];
// wp_update_post($post_arr);
// }
// }
$tabs['content'] = ['title'=>'表格内容', 'function'=>'list', 'list_table_name'=>'table_content'];
}
return $tabs;
});
function wpjam_table_setting_page(){
$post_id = wpjam_get_data_parameter('post_id') ?: 0;
if($post_id){
$post = get_post($post_id);
$post_title = $post->post_title;
$post_excerpt = $post->post_excerpt;
$post_password = $post->post_password;
$table_fields = get_post_meta($post_id, '_table_fields', true);
}else{
$post_title = $post_excerpt = $post_password = '';
$table_fields = [];
}
$type_options = [
'text' => '输入框',
'textarea' => '文本框',
'number' => '数字输入框',
'url' => '链接输入框',
'email' => '邮件输入框',
'date' => '日期选择框',
'time' => '时间选择框',
'select' => '下拉选择框',
// 'id' => '中国大陆身份证号',
// 'tel' => '中国大陆手机号码',
'img' => '上传图片',
];
$fields = [
'post_title' => ['title'=>'标题', 'type'=>'text'],
'shortcode' => ['title'=>'短代码', 'type'=>'view', 'value'=>'[template id="'.$post_id.'"]'],
'post_excerpt' => ['title'=>'简介', 'type'=>'textarea', 'value'=>$post_excerpt, 'class'=>''],
'post_password' => ['title'=>'密码', 'type'=>'text', 'value'=>$post_password,'class'=>'', 'description'=>'设置了密码保护,则前端必须输入密码才可查看'],
'table_fields' => ['title'=>'字段', 'type'=>'mu-fields', 'value'=>$table_fields, 'fields'=>[
'title' => ['title'=>'', 'type'=>'text', 'class'=>'', 'placeholder'=>'请输入字段名称'],
'type' => ['title'=>'', 'type'=>'select', 'options'=>$type_options],
'options' => ['title'=>'', 'type'=>'mu-text', 'class'=>'', 'placeholder'=>'请输入选项...'],
'url_for' => ['title'=>'', 'type'=>'text', 'class'=>'', 'placeholder'=>'链接字段应用于...'],
// 'required' => ['title'=>'', 'type'=>'checkbox', 'description'=>'必填'],
'index' => ['title'=>'', 'type'=>'hidden'],
]],
'post_id' => ['title'=>'', 'type'=>'hidden', 'value'=>$post_id],
];
if(empty($post_id)){
unset($fields['shortcode']);
}
$data = compact('post_title', 'post_excerpt', 'post_password', 'table_fields', 'post_id');
$submit_text = $post_id ? '编辑' : '新建';
echo $post_id ? '<h2>表格设置</h2>' : '<h1 class="wp-heading-inline">新建表格</h1>';
wpjam_ajax_form([
'fields' => $fields,
'data' => $data,
'submit_text' => $submit_text,
'action' => 'save',
]);
}
function wpjam_table_ajax_response(){
global $plugin_page;
$action = $_POST['page_action'];
check_ajax_referer($plugin_page.'-'.$action);
$post_id = wpjam_get_data_parameter('post_id');
$data = wp_parse_args($_POST['data']);
if($action == 'save'){
$post_title = $data['post_title'] ?? '';
$post_excerpt = $data['post_excerpt'] ?? '';
$post_password = $data['post_password'] ?? '';
$table_fields = $data['table_fields'] ?? [];
$post_status = 'publish';
if($table_fields){
$indexs = wp_list_pluck($table_fields, 'index');
$index = max($indexs);
foreach ($table_fields as $key=> &$table_field) {
if(empty($table_field['title'])){
unset($table_fields[$key]);
continue;
}
if($table_field['type'] == 'select'){
$table_field['options'] = array_filter($table_field['options']);
}else{
unset($table_field['options']);
if($table_field['type'] != 'url'){
unset($table_field['url_for']);
}
}
if(empty($table_field['index'])){
$index++;
$table_field['index'] = $index;
}
}
if($table_fields){
$table_fields = array_values($table_fields);
}
}
$table_fields = $table_fields ?: [];
$meta_input = [
'_template_type' =>'table',
'_table_fields' =>$table_fields
];
if($post_id){
$post_id = WPJAM_Post::update($post_id, compact('post_title', 'post_excerpt', 'post_status', 'post_password', 'meta_input'));
$is_add = false;
}else{
$post_type = 'template';
$post_id = WPJAM_Post::insert(compact('post_type','post_title', 'post_excerpt', 'post_status', 'post_password', 'meta_input'));
$is_add = true;
}
if(is_wp_error($post_id)){
wpjam_send_json($post_id);
}else{
wpjam_send_json(compact('post_id', 'is_add'));
}
}elseif($action == 'bulk_edit'){
$table_fields = get_post_meta($post_id, '_table_fields', true);
foreach ($table_fields as $table_field) {
$field_indexs[] = 'i'.$table_field['index'];
}
$table_content = trim($data['table_content']);
if($table_content){
$table_content = str_replace("\r\n", "\n", $table_content);
$table_content = str_replace("\r\n", "\n", $table_content);
$items = [];
$trs = explode("\n\n", $table_content);
$index = 0;
foreach($trs as $tr){
$index++;
$tds = explode("\n", $tr);
$item = [];
foreach ($field_indexs as $i => $field_index) {
$td = $tds[$i] ?? '';
$item[$field_index] = trim($td);
}
$items[$index] = $item;
}
$post_content = maybe_serialize($items);
$result = WPJAM_Post::update($post_id, compact('post_content'));
if(is_wp_error($result)){
wpjam_send_json($result);
}else{
wpjam_send_json();
}
}
}
}
function wpjam_table_bulk_edit_page(){
echo '<h2>批量编辑</h2>';
$post_id = wpjam_get_data_parameter('post_id');
if($post_id){
$table_fields = get_post_meta($post_id, '_table_fields', true);
}else{
$table_fields = [];
}
if(empty($table_fields)){
echo '<p>请先在「表格设置」中添加字段。</p>';
return;
}
foreach ($table_fields as $table_field) {
if($table_field['type'] == 'textarea'){
echo '<p>含有「富文本」类型的字段,不能批量编辑。</p>';
return;
}elseif($table_field['type'] == 'img'){
echo '<p>含有「图片」类型的字段,不能批量编辑。</p>';
return;
}
}
echo '
<p>批量编辑极其容易造成数据丢失和紊乱,批量编辑前请先做好备份。批量编辑规则:</p>
<p>* 连续两个回车当做:<strong>一行</strong>。
<br />* 单独一个回车当做:<strong>单元格</strong>。</p>
';
$post_content = get_post($post_id)->post_content;
$table_content = $post_content ? maybe_unserialize($post_content) : [];
$value = '';
if($table_content){
$field_indexs = [];
foreach ($table_fields as $table_field) {
$field_indexs[] = 'i'.$table_field['index'];
}
foreach ($table_content as $table_row) {
foreach ($field_indexs as $field_index) {
$v = $table_row[$field_index] ?: ' ';
$value .= $v."\n";
}
$value .="\n";
}
}
$fields = [
'table_content' => ['title'=>'', 'type'=>'textarea', 'value'=>$value, 'rows'=>20, 'class'=>'large-text'],
'post_id' => ['title'=>'', 'type'=>'hidden', 'value'=>$post_id],
];
wpjam_ajax_form([
'fields' => $fields,
'action' => 'bulk_edit',
'submit_text' => '批量编辑'
]);
}
function wpjam_table_no_fields_page(){
echo '<h2>表格内容</h2>';
echo '<p>请先在「表格设置」中添加字段。</p>';
}
add_filter('wpjam_table_content_list_table', function(){
r
没有合适的资源?快使用搜索试试~ 我知道了~
WordPress 响应式Sweet简洁个人博客主题源码下载
共102个文件
php:84个
js:7个
css:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 40 浏览量
2022-07-04
11:26:02
上传
评论
收藏 459KB ZIP 举报
温馨提示
WordPress 响应式Sweet简洁个人博客主题源码下载 基于WPJAM插件制作,因此,必须安装WPJAM插件,要求Linux服务器以及使用PHP7.2版本。(php7.2版本以下的用户可以不用往下看了) 该模板网站很容易吸引访客点击,提升ip流量和pv是非常有利的。 本套模板采用现在非常流行的全屏自适应布局设计,且栏目列表以简洁,非常时尚大气。 页面根据分辨率大小而自动排版,很大程度上改善了页面宽度兼容问题,
资源推荐
资源详情
资源评论
收起资源包目录
WordPress 响应式Sweet简洁个人博客主题源码下载 (102个子文件)
style.css 56KB
blocks.style.build.css 14KB
blocks.editor.build.css 3KB
morris.css 433B
style.css 294B
hr.gif 430B
icon-gotop-fixed.gif 70B
raphael.min.js 91KB
prismjs.min.js 72KB
blocks.build.js 63KB
morris.min.js 35KB
blocks.front.build.js 8KB
sweet 2.js 1KB
sweet.js 1KB
table.php 12KB
class-signup.php 7KB
index-grid.php 7KB
trait-qrcode.php 7KB
sweet-functions.php 7KB
class-weixin-signup.php 7KB
comment.php 7KB
hooks.php 6KB
post-query.php 6KB
theme-setting.php 6KB
utils.php 6KB
user-meta.php 6KB
card.php 5KB
post.php 5KB
load-scripts.php 4KB
settings.php 4KB
post-meta.php 4KB
login.php 4KB
script-loader.php 4KB
load-styles.php 4KB
post-password.php 3KB
single.php 3KB
admin.php 3KB
template-type.php 3KB
template-type.php 3KB
weixin.php 3KB
template-list.php 3KB
post.update.php 3KB
class-weapp-signup.php 3KB
index-list.php 3KB
template-list.php 3KB
wpjam-bind.php 2KB
hooks.php 2KB
wpjam-check.php 2KB
class-invite.php 2KB
post.create.php 2KB
button.php 2KB
user-query.php 2KB
post-list.php 2KB
button.php 2KB
admin.php 2KB
utils.php 2KB
xintheme-block.php 2KB
compat.php 2KB
wpjam-invite.php 2KB
session-tokens.php 2KB
header.php 1KB
content-index.php 1KB
admin.php 1KB
term-query.php 1KB
wpjam-signup.php 1KB
utils.php 1KB
template.php 1KB
apis.php 1KB
page.php 1KB
weapp.php 1KB
wpjam-cache.php 1KB
template.php 1KB
hooks.php 1KB
wpjam-signup.php 1KB
upgrade.php 1KB
footer.php 927B
functions.php 842B
media-months.php 840B
user.signup.php 831B
wpjam-content-template.php 830B
comments.php 824B
singular.php 772B
auto-draft.php 752B
hooks.php 720B
user-list.php 703B
weixin.qrcode.verify.php 659B
wpjam-format.php 639B
plugable.php 482B
timeline.php 468B
weapp.qrcode.bind.php 460B
weapp.qrcode.code.php 449B
weixin.qrcode.create.php 433B
extends.php 403B
post.create.list.php 355B
admin.php 302B
index.php 202B
author.php 91B
user.logout.php 39B
screenshot.png 254KB
mail.svg 2KB
共 102 条
- 1
- 2
资源评论
智慧浩海
- 粉丝: 1w+
- 资源: 5188
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功