easyiit_proudct_publish.php
21.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
<?php
/**
* Plugin Name: Easy Product publish
* Plugin URI: http://www.goodao.cn/
* Description: Easy Product publish
* Version: 1.1.00
* Author: GD-Shop
* Author URI: http://www.goodao.cn/
*/
error_reporting(0);
ignore_user_abort(true);
define ( 'Easyiit_p_p_FILE', __FILE__);
define ( 'Easyiit_p_p_DIR', rtrim ( plugin_dir_path ( Easyiit_p_p_FILE ), '/' ) );
define ( 'Easyiit_p_p_URL', rtrim ( plugin_dir_url ( Easyiit_p_p_FILE ), '/' ) );
add_action('admin_menu', 'p_p_init');
function p_p_init() {
add_menu_page('产品发布', '产品发布', 7, 'easyiit_product_publish');
add_submenu_page('easyiit_product_publish', '产品发布', '产品发布', 7, 'easyiit_product_publish', 'product_publish');
add_submenu_page('easyiit_news_publish', '新闻发布', '新闻发布', 7, 'easyiit_news_publish', 'news_publish');
}
function product_publish(){
global $wpdb;
$products = $wpdb->get_results("select p.ID,p.post_title from wp_posts as p inner join wp_term_relationships as c on p.ID=c.object_id where p.post_type='post' and c.term_taxonomy_id=496",ARRAY_A);
?>
<style>
body {background:#eeeeee}
* {-moz-box-sizing:border-box;-webkit-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box;outline: 0;}
.add_page820 {display:inline-block;vertical-align:middle;font-family:Arial, Helvetica, sans-serif;font-size:12px; padding: 30px 0;}
.add_page820 .form_item {position:relative;display:block;width:100%;margin:0 0 30px;}
.add_page820 label {display:inline-block;vertical-align:middle;width:113px;height:37px;line-height:37px;text-align:center;background:#188ae2;color:#FFF;}
.add_page820 select,.add_page820 select#select_area, .add_page820 input,.add_page820 textarea {width:290px;height:37px;border:1px solid #ccc;padding:0 8px;margin:0 10px 0 17px;}
.add_page820 .pay_att {position:relative;display:inline-block;vertical-align:middle;color:#a02424;}
.add_page820 .form_item input {width:265px}
.add_page820 .form_item input.button, .add_page820 input.submit {display:inline-block;vertical-align:middle;width:115px;height:37px;line-height:37px;text-align:center;background:#5cb85c;color:#FFF;border:none;cursor:pointer; padding:0;}
.add_page820 .form_item.form_item_el label {background:#5cb85c;}
.add_page820 .form_item.form_item_el input {width:655px;}
.add_page820 .text_box {display:inline-block;vertical-align:middle;}
.add_page820 input.submit {float:right;}
.add_page820 textarea{ width:655px;height:200px;}
.add_page820 .select2-container{ margin: 0 10px 0 17px;}
.add_page820 .select2-container--default .select2-selection--single,.add_page820 .select2-container .select2-selection--single{border-color: #ccc;border-radius: 0;height: 37px;line-height: 37px}
.add_page820 .select2-container--default .select2-selection--single .select2-selection__rendered{line-height: 37px;}
.add_page820 .select2-container--default .select2-selection--single .select2-selection__arrow { height: 37px;top: 0;}
.add_page820 #cover_img{margin: -15px 0 10px 135px;}
.add_page820 .form_item .load_img{ position:relative; display:inline-block; vertical-align:middle;width:32px; height:32px;padding:0 15px;}
.add_page820 .form_item .load_img i{ position:relative; display:inline-block; vertical-align:middle;width:32px; height:32px; background: transparent url(../wp-content/plugins/easyiit_product_publish/include/loading.gif) no-repeat center center;}
.msg{display:inline-block;vertical-align:middle;width:800px;height:37px;line-height:37px;text-align:center;background:#d54e21;color:#FFF;}
.add_page820 .form_item.form_item_el input#youtube_vs{ width:20px; height:auto;}
.add_page820 .form_item label.label_el{ display:inline; width:auto; height:auto; line-height:inherit; text-align:inherit; background:none; color:inherit;}
</style>
<script src="<?php echo Easyiit_p_p_URL;?>/include/jquery.min.1.9.2.js"></script>
<link href="<?php echo Easyiit_p_p_URL;?>/include/select2.min.css" rel="stylesheet" />
<script src="<?php echo Easyiit_p_p_URL;?>/include/select2.min.js"></script>
<script type="text/javascript">
$(function () {
$("#select_area").select2();
$("#get_ky").click(function(){
$("#new_title").val('');
$("#new_keyword").val('');
$("#contents").html('');
var keyword = $("#keyword").val();
var postid = $('#select_area').select2('val');
var loding='<i></i>'
if(keyword != ''){
$('.add_page820 .form_item .load_img').append(loding);
$("#get_ky").attr("disabled",'true');
$(".submit").attr("disabled",'true');
$.get("/wp-admin/admin-ajax.php?action=pp_get_title_tags&keyword="+keyword+'&postid='+postid,function(data){
if(data == 1){
alert('获取失败,请稍后重试');
}else{
$("#new_title").val(data.new_title);
$("#new_keyword").val(data.new_keyword);
$("#contents").append(data.new_content);
$("#prefix1").val(data.prefix1);
$("#prefix2").val(data.prefix2);
$("#suffix_l").val(data.suffix_l);
$("#suffix_s").val(data.suffix_s);
}
$('.add_page820 .form_item .load_img i').remove();
$(".submit").removeAttr("disabled");
$("#get_ky").removeAttr("disabled");
$("#get_ky").val("重新生成");
},'json');
}else{
alert('请输入关键词');
}
});
$("#select_area").on("select2:select",function(){
$("#new_title").val('');
$("#new_keyword").val('');
$("#contents").html('');
var postid = $(this).val();
$.get("/wp-admin/admin-ajax.php?action=pp_get_a_pic&postid="+postid,function(data){
if(data != 1){
$("#cover_img").attr("src", data);
}
});
});
});
</script>
<div class="add_page820">
<form action="" method="post">
<img id="cover_img" height="100px;" src="<?php $gallery = get_post_meta($products[0]['ID'],'product_gallery');if($gallery){$img = wp_get_attachment_image_src($gallery[0][0],'thumbnail'); echo $img[0];}?>"/>
<div class="form_item">
<label>初始产品信息</label>
<select id="select_area" name="product">
<?php if($products){ foreach($products as $product){?>
<option value ="<?php echo $product['ID'];?>"><?php echo $product['post_title'];?></option>
<?php }}?>
</select>
<span class="pay_att">选择后除标题,关键词,新增描述内容,其余的保持和初始产品信息一致</span> <br/>
</div>
<div class="form_item">
<label>扩展产品分类</label>
<select name="category">
<option value ="Featured Products">Featured Products</option>
<!-- <?php foreach($all_cats as $cat){?>
<option value ="<?php echo $cat->name;?>"><?php echo $cat->name;?></option>
<?php }?> -->
</select>
</div>
<div class="form_item">
<label>核心关键词</label>
<input type="text" name='keyword' id="keyword"/>
<input type="button" value="AI智能生成" class="button" id="get_ky"/>
<span class="load_img"></span>
</div>
<div class="form_item form_item_el">
<label>新标题</label>
<input type="text" name='new_title' value='' id="new_title"/>
</div>
<div class="form_item form_item_el">
<label>新匹配关键词</label>
<input type="text" name='new_keyword' value='' id="new_keyword"/>
</div>
<div class="form_item form_item_el">
<label>扩展描述内容</label>
<div class="text_box">
<textarea id="contents" name="contents" ></textarea>
</div>
</div>
<div class="form_item form_item_el">
<label>随机相关视频</label>
<input type="checkbox" name='youtube_vs' value=1 id="youtube_vs" /><label class="label_el" for="youtube_vs">随机插入2个YouTube视频</label>
</div>
<input type="hidden" name="prefix1" id="prefix1">
<input type="hidden" name="prefix2" id="prefix2">
<input type="hidden" name="suffix_l" id="suffix_l">
<input type="hidden" name="suffix_s" id="suffix_s">
<input type="submit" value="发布" class="submit"/>
</form>
</div>
<br/>
<?php
if(isset($_POST) && $_POST){
$postid = $_POST['product'];
if(!$postid){
echo '<span class="msg">请选择文章</span>';exit;
}
/*$cats = get_the_category($postid);
foreach($cats as $cat){
$res['cat'][] = $cat->name;
}
if(!in_array($_POST['category'],$res['cat'])){
$res['cat'][] = $_POST['category'];
}*/
$res['cat'][] = $_POST['category'];
$res['post_content'] = trim($_POST['contents']);
$res['post_title'] = trim($_POST['new_title']);
$res['post_tags'] = trim($_POST['new_keyword']);
$postinfo = get_post($postid,ARRAY_A);
if(!$res['post_title']){
echo '<span class="msg">请输入标题</span>';exit;
}
$catids = array();
foreach ($res['cat'] as $catname) {
$rid = get_cat_ID($catname);
if ($rid != 0) {
$catid = $rid;
} else {
$catid = wp_create_category($catname);
}
$catids[] = $catid;
}
$res_sel = $wpdb->get_row("select count(*) as cnt from wp_posts where post_type='post'");
$count_post = $res_sel->cnt;
$post_date = date("Y-m-d H:i:s",time()-3600*8-60);
$my_post = array(
'post_title' => $res['post_title'],
'post_content' => '',
'post_type' => 'post',
'post_status' => 'publish',
'post_author' => 34,
'post_category' => $catids,
'post_date'=> $post_date
);
$post_id = wp_insert_post($my_post);
$tags = explode(",", $res['post_tags']);
wp_set_post_tags($post_id, $tags, true);
$ar_pre_suf = json_decode($pre_suf,JSON_OBJECT_AS_ARRAY);
$tags_new = wp_get_post_tags($post_id);
$contents = $_POST['prefix2'].' '.$res['post_title'].', '.$_POST['suffix_s']."\r\n";
foreach($tags_new as $k=>$v){
$new_tag_info[] = '<a href="'.home_url().'/tag/'.$v->slug.'" target="_blank">'.$v->name.'</a>';
}
$contents .= $_POST['prefix2'].' '.implode(', ',$new_tag_info).', '.$_POST['suffix_l'] . "\r\n";
$contents .= $postinfo['post_content'];
if($_POST['youtube_vs']==1){ //勾选后随机插入两个youtube视频
$vs_ar = $wpdb->get_results($wpdb->prepare("SELECT post_content FROM wp_posts WHERE post_type='vs' ORDER BY RAND() LIMIT 2"));
if($vs_ar){
foreach($vs_ar as $vs){
$contents .= $vs->post_content."\r\n";
}
}
}
$arg_post_update = array('ID'=>$post_id,'post_content'=>$contents);
wp_update_post($arg_post_update);
$sql = $wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = %d", absint($postid));
$post_meta = $wpdb->get_results($sql,ARRAY_A);
foreach($post_meta as $key=>$val){
if($val['meta_key'] == '_listorder' || $val['meta_key'] == '_fl_builder_data' || $val['meta_key'] == '_fl_builder_data_settings' || $val['meta_key'] == '_fl_builder_draft' || $val['meta_key'] == '_fl_builder_enabled' || $val['meta_key'] == 'product_gallery' || $val['meta_key'] == 'special'){}else{
add_post_meta($post_id, $val['meta_key'], $val['meta_value']);
}
}
$meta_g = get_post_meta($postid,'product_gallery');
add_post_meta($post_id, 'product_gallery', $meta_g[0]);
add_post_meta($post_id, 'special', '');
echo '<span class="msg">发布成功</span><script>setTimeout(function(){$(".msg").hide();},3000);</script>';exit;
}
}
function news_publish(){
global $wpdb;
?>
<style>
body {background:#eeeeee}
* {-moz-box-sizing:border-box;-webkit-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box;outline: 0;}
.add_page820 {display:inline-block;vertical-align:middle;font-family:Arial, Helvetica, sans-serif;font-size:12px; padding: 30px 0;}
.add_page820 .form_item {position:relative;display:block;width:100%;margin:0 0 30px;}
.add_page820 label {display:inline-block;vertical-align:middle;width:113px;height:37px;line-height:37px;text-align:center;background:#188ae2;color:#FFF;}
.add_page820 select,.add_page820 select#select_area, .add_page820 input,.add_page820 textarea {width:290px;height:37px;border:1px solid #ccc;padding:0 8px;margin:0 10px 0 17px;}
.add_page820 .pay_att {position:relative;display:inline-block;vertical-align:middle;color:#a02424;}
.add_page820 .form_item input {width:265px}
.add_page820 .form_item input.button, .add_page820 input.submit {display:inline-block;vertical-align:middle;width:115px;height:37px;line-height:37px;text-align:center;background:#5cb85c;color:#FFF;border:none;cursor:pointer; padding:0;}
.add_page820 .form_item.form_item_el label {background:#5cb85c;}
.add_page820 .form_item.form_item_el input {width:655px;}
.add_page820 .text_box {display:inline-block;vertical-align:middle;width:655px;height:350px; margin-left: 17px;}
.add_page820 input.submit {float:right;}
.add_page820 textarea{ width:655px;height:200px;}
.add_page820 .select2-container{ margin: 0 10px 0 17px;}
.add_page820 .select2-container--default .select2-selection--single,.add_page820 .select2-container .select2-selection--single{border-color: #ccc;border-radius: 0;height: 37px;line-height: 37px}
.add_page820 .select2-container--default .select2-selection--single .select2-selection__rendered{line-height: 37px;}
.add_page820 .select2-container--default .select2-selection--single .select2-selection__arrow { height: 37px;top: 0;}
.add_page820 #cover_img{margin: -15px 0 10px 135px;}
.add_page820 .form_item .load_img{ position:relative; display:inline-block; vertical-align:middle;width:32px; height:32px;padding:0 15px;}
.add_page820 .form_item .load_img i{ position:relative; display:inline-block; vertical-align:middle;width:32px; height:32px; background: transparent url(../wp-content/plugins/easyiit_product_publish/include/loading.gif) no-repeat center center;}
.msg{display:inline-block;vertical-align:middle;width:800px;height:37px;line-height:37px;text-align:center;background:#d54e21;color:#FFF;}
.add_page820 .form_item.form_item_el input#youtube_vs{ width:20px; height:auto;}
.add_page820 .form_item label.label_el{ display:inline; width:auto; height:auto; line-height:inherit; text-align:inherit; background:none; color:inherit;}
</style>
<script src="<?php echo Easyiit_p_p_URL;?>/include/jquery.min.1.9.2.js"></script>
<script type="text/javascript">
$(function () {
$("#contents-html").hide();
$("#get_ky").click(function(){
$("#new_title").val('');
$("#new_keyword").val('');
document.getElementById('contents_ifr').contentWindow.document.getElementById('tinymce').innerHTML = '';
var keyword = $("#keyword").val();
var loding='<i></i>'
if(keyword != ''){
$('.add_page820 .form_item .load_img').append(loding);
$("#get_ky").attr("disabled",'true');
$(".submit").attr("disabled",'true');
$.get("/wp-admin/admin-ajax.php?action=pp_get_news_title_tags&keyword="+keyword,function(data){
if(data == 1 || data == 3){
alert('获取失败,请稍后重试');
}else if(data == 2){
alert('请于两分钟之后重新获取');
}else{
if(data.title != ''){
$("#new_title").val(data.title);
document.getElementById('contents_ifr').contentWindow.document.getElementById('tinymce').innerHTML=data.contents;
}else{
alert('获取标题失败,请稍后重试');
}
}
$('.add_page820 .form_item .load_img i').remove();
$(".submit").removeAttr("disabled");
$("#get_ky").removeAttr("disabled");
$("#get_ky").val("重新生成");
},'json');
}else{
alert('请输入关键词');
}
});
});
</script>
<div class="add_page820">
<form action="" method="post">
<div class="form_item">
<label>核心关键词</label>
<input type="text" name='keyword' id="keyword"/>
<input type="button" value="AI智能生成" class="button" id="get_ky"/>
<span class="load_img"></span>
</div>
<div class="form_item form_item_el">
<label>新标题</label>
<input type="text" name='new_title' value='' id="new_title"/>
</div>
<div class="form_item form_item_el">
<label>扩展描述内容</label>
<div id="a_cn" class="text_box">
<?php wp_editor('','contents',array('editor_height' => 300));?>
<!--<textarea id="contents" name="contents" ></textarea>-->
</div>
</div>
<div class="form_item form_item_el">
<label>随机相关视频</label>
<input type="checkbox" name='youtube_vs' value=1 id="youtube_vs" /><label class="label_el" for="youtube_vs">随机插入2个YouTube视频</label>
</div>
<input type="submit" value="发布" class="submit"/>
</form>
</div>
<br/>
<?php
if(isset($_POST) && $_POST){
if(!$_POST['new_title']){
echo '<span class="msg">请输入标题</span>';exit;
}
$contents = $_POST['contents']."\r\n";
if($_POST['youtube_vs']==1){ //勾选后随机插入两个youtube视频
$vs_ar = $wpdb->get_results($wpdb->prepare("SELECT post_content FROM wp_posts WHERE post_type='vs' ORDER BY RAND() LIMIT 2"));
if($vs_ar){
foreach($vs_ar as $vs){
$contents .= $vs->post_content."\r\n";
}
}
}
$my_post = array(
'post_title' => $_POST['new_title'],
'post_content' => $contents,
'post_type' => 'news',
'post_status' => 'publish',
'post_author' => 34,
'post_date'=> date("Y-m-d H:i:s",time()-3600*8-60)
);
//print_r($my_post);exit;
$post_id = wp_insert_post($my_post);
echo '<span class="msg">发布成功</span><script>setTimeout(function(){$(".msg").hide();},3000);</script>';exit;
}
}
//新闻自动发布
add_action( 'wp_ajax_nopriv_ai_news_contents', 'ai_news_contents');
add_action( 'wp_ajax_ai_news_contents', 'ai_news_contents');
function ai_news_contents(){
if(isset($_POST['title']) && $_POST['title']){
$title = trim($_POST['title']);
$content = trim($_POST['content']);
$has_news = $wpdb->query('select * from wp_posts where post_title="'.$title.'" and post_type="news"',ARRAY_A);
if(empty($has_news)){
$my_post = array(
'post_title' => $title,
'post_content' => $content,
'post_type' => 'news',
'post_status' => 'publish',
'post_author' => 34,
'post_date'=> date("Y-m-d H:i:s",time()-3600*8-60)
);
$post_id = wp_insert_post($my_post);
echo json_encode(['code'=>200,'msg'=>'success']);
}else{
echo json_encode(['code'=>2,'msg'=>'新闻已存在,请重新提交']);
}
}else{
echo json_encode(['code'=>1,'msg'=>'请传入参数']);
}
exit;
}
//从阿里巴巴获取标题和标签
add_action( 'wp_ajax_nopriv_pp_get_title_tags', 'pp_get_title_tags');
add_action( 'wp_ajax_pp_get_title_tags', 'pp_get_title_tags');
function pp_get_title_tags(){
$keyword = trim($_GET['keyword']);
if(!$keyword){
echo 1;exit;
}
$keyword = str_replace(" ","_",trim($_GET['keyword']));
$pre_suf = file_get_contents("http://www.quanqiusou.cn/get_prefix_suffix_api.php");
$ar_pre_suf = json_decode($pre_suf,JSON_OBJECT_AS_ARRAY);
$search_info = file_get_contents("http://title.globalso.com/ajax_data_for_web.php?keyword=".$keyword);
if($search_info){
$new_info = explode(" - ",trim($search_info));
$data['prefix1'] = $ar_pre_suf['prefix_title'][0];
$data['prefix2'] = $ar_pre_suf['prefix'][0];
$data['suffix_l'] = $ar_pre_suf['suffix_l'][0];
$data['suffix_s'] = $ar_pre_suf['suffix_s'][0];
$data['new_title'] = str_replace(' ',' ',$ar_pre_suf['prefix_title'][0].' '.$new_info[0]);
$data['new_keyword'] = $new_info[1];
$tm_ky = explode(',',$new_info[1]);
$contents = $ar_pre_suf['prefix'][0].' '.$data['new_title'].', '.$ar_pre_suf['suffix_s'][0]."\r\n";
$contents .= $ar_pre_suf['prefix_title'][0].' '.implode(', ',$tm_ky).', '.$ar_pre_suf['suffix_l'][0]."\r\n";
$data['new_content'] = htmlentities($contents);
echo json_encode($data);exit;
}else{
echo 1;exit;
}
}
//从谷歌获取标题和内容
add_action( 'wp_ajax_nopriv_pp_get_news_title_tags', 'pp_get_news_title_tags');
add_action( 'wp_ajax_pp_get_news_title_tags', 'pp_get_news_title_tags');
function pp_get_news_title_tags(){
$keyword = trim($_GET['keyword']);
if(!$keyword){
echo 1;exit;
}
$keyword = str_replace(" ","+",trim($_GET['keyword']));
$search_info = file_get_contents("http://gnews.globalso.com/gnews_news.php?keyword=".$keyword);
if($search_info){
$ar_info = json_decode($search_info,true);
//print_r($ar_info);exit;
if($ar_info['err'] == 0){
$data['contents'] = '';
$data['title'] = $ar_info['data']['title'][0];
foreach( $ar_info['data']['p'] as $p){
$data['contents'] .= $p."<br/><br/>\r\n";
}
echo json_encode($data);exit;
}elseif($ar_info['err'] == 1){
echo 2;exit;
}else{
echo 3;exit;
}
echo $search_info;exit;
}else{
echo 1;exit;
}
}
//获取一张封面图片
add_action( 'wp_ajax_nopriv_pp_get_a_pic', 'pp_get_a_pic');
add_action( 'wp_ajax_pp_get_a_pic', 'pp_get_a_pic');
function pp_get_a_pic(){
$postid = trim($_GET['postid']);
if(!$postid){
echo 1;exit;
}
$gallery = get_post_meta($postid,'product_gallery');
if($gallery){
$pic = wp_get_attachment_image_src($gallery[0][0],'thumbnail');
echo $pic[0];exit;
}else{
echo 1;exit;
}
}
?>