/
vice-versa.php
748 lines (660 loc) · 32.2 KB
/
vice-versa.php
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
<?php
/**
* Plugin Name: Vice Versa
* Plugin URI: http://jasonlau.biz
* Description: Convert Pages to Posts and Vice Versa
* Version: 2.1.9
* Author: Jason Lau
* Author URI: http://jasonlau.biz
* Disclaimer: Use at your own risk. No warranty expressed or implied.
* Always backup your database before making changes.
* Copyright 2010-2012 http://jasonlau.biz
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
define('VICEVERSA_VERSION', '2.1.9');
define('VICEVERSA_DEBUG', false); // Test this plugin
load_plugin_textdomain('vice-versa', '/wp-content/plugins/vice-versa/vice-versa.pot');
function viceversa_admin_menu(){
add_submenu_page('tools.php', 'Vice Versa', 'Vice Versa', 'publish_pages', 'vice-versa', 'viceversa_display');
}
add_action('admin_menu', 'viceversa_admin_menu');
if(!class_exists('WP_List_Table')):
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
endif;
class ViceVersa_List_Table extends WP_List_Table {
function __construct(){
global $status, $page;
parent::__construct( array(
'singular' => __('post', 'vice-versa'),
'plural' => __('posts', 'vice-versa'),
'ajax' => false
) );
}
function column_default($item, $column_name){
switch($column_name){
case 'ID':
case 'post_title':
case 'post_date':
return $item->$column_name;
case 'assign_to':
return '<div class="viceversa-assign-to" rel="'.$item->ID.'">Loading ...</div><div class="viceversa-assign-to-text" rel="'.$item->ID.'"></div>';
default:
return print_r($item,true);
}
}
function column_ID($item){
$actions = array(
'convert' => sprintf('<a href="?page=%s&action=%s&p=%s">' . __('Convert', 'vice-versa') . '</a>',$_POST['page'],'convert',$item->ID)
);
return sprintf('%1$s %2$s',
$item->ID,
$this->row_actions($actions)
);
}
function column_cb($item){
return sprintf(
'<input type="checkbox" name="%1$s[]" value="%2$s" data-id="%3$s" />',
$this->_args['singular'],
$item->ID . "|vice-versa|" . $item->post_title,
$item->ID
);
}
function get_columns(){
$columns = array(
'cb' => '<input type="checkbox" />',
'ID' => __('ID', 'vice-versa'),
'post_title' => __('Title', 'vice-versa'),
'post_date' => __('Date', 'vice-versa'),
'assign_to' => __('Assign To', 'vice-versa')
);
return $columns;
}
function get_sortable_columns() {
$sortable_columns = array(
'ID' => array('ID',false),
'post_title' => array('post_title',false),
'post_date' => array('post_date',false),
'assign_to' => array('assign_to',true)
);
return $sortable_columns;
}
function get_bulk_actions() {
$actions = array(
'convert' => __('Convert', 'vice-versa')
);
return $actions;
}
function process_bulk_action(){
global $wp_rewrite, $wpdb;
if('convert' === $this->current_action()):
$output = "<div id=\"viceversa-status\" class=\"updated\">
<input type=\"button\" class=\"viceversa-close-icon button-secondary\" title=\"Close\" value=\"x\" />";
if(VICEVERSA_DEBUG):
$output .= "<strong>" . __('Debug Mode', 'vice-versa') . "</strong>\n";
endif;
switch($_POST['p_type']){
case 'page':
$categories = array('ids' => array(), 'titles' => array());
$do_bulk = false;
foreach($_POST['parents'] as $category):
if($category != ""):
$data = explode("|", $category);
$categories[$data[3]]['ids'] = array();
$categories[$data[3]]['titles'] = array();
if($data[3] == 0) $do_bulk = true;
endif;
endforeach;
foreach($_POST['parents'] as $category):
if($category != ""):
$data = explode("|", $category);
array_push($categories[$data[3]]['ids'], $data[0]);
array_push($categories[$data[3]]['titles'], $data[2]);
endif;
endforeach;
$output .= "<p>\n";
foreach($_POST['post'] as $viceversa_page):
$viceversa_data = explode("|", $viceversa_page);
$viceversa_url = site_url() . "/?p=" . $viceversa_data[0];
if($do_bulk):
$ids = $categories[0]['ids'];
$titles = $categories[0]['titles'];
else:
$ids = $categories[$viceversa_data[0]]['ids'];
$titles = $categories[$viceversa_data[0]]['titles'];
endif;
$catlist = "";
if($titles):
foreach($titles as $cat):
$catlist .= $cat.", ";
endforeach;
endif;
$catlist = (trim($catlist,', ') == "") ? get_cat_name(1) : trim($catlist,', ');
$cat_array = (count($ids)<1) ? array(1) : $ids;
if(!VICEVERSA_DEBUG):
$wpdb->update(
$wpdb->posts,
array(
'guid' => $viceversa_url,
'post_parent' => $cat_array[0]
),
array( 'ID' => intval($viceversa_data[0]) ),
array(
'%s',
'%d'
),
array( '%d' )
);
clean_page_cache(intval($viceversa_data[0]));
set_post_type(intval($viceversa_data[0]), 'post');
wp_set_post_categories(intval($viceversa_data[0]), $cat_array);
endif;
$new_permalink = get_permalink(intval($viceversa_data[0]));
$output .= sprintf(__('<strong>' . __('Page', 'vice-versa') . '</strong> #%s <code><a href="%s" target="_blank" title="' . __('New Permalink', 'vice-versa') . '">%s</a></code> ' . __('was successfully converted to a <strong>Post</strong> and assigned to category(s)', 'vice-versa') . ' <code>%s</code>. <a href="%s" target="_blank" title="' . __('New Permalink', 'vice-versa') . '">' . __('New Permalink', 'vice-versa') . '</a>', 'vice-versa'), $viceversa_data[0], $new_permalink, $viceversa_data[2], $catlist, $new_permalink) . "<br />\n";
endforeach;
if(!VICEVERSA_DEBUG):
$wp_rewrite->flush_rules();
endif;
break;
default :
$parents = array();
$do_bulk = false;
foreach($_POST['parents'] as $parent):
if($parent != ""):
$data = explode("|", $parent);
if($data[3] == 0) $do_bulk = true;
$parents[intval($data[3])] = $data[0] . "|" . $data[2];
endif;
endforeach;
$output .= "<p>\n";
if(!$_POST['post']):
$output .= __('No items were selected. Please select items using the checkboxes.', 'vice-versa');
else:
foreach($_POST['post'] as $viceversa_post):
$viceversa_data = explode("|", $viceversa_post);
$viceversa_url = site_url() . "/?page_id=" . $viceversa_data[0];
if($do_bulk):
$p = $parents[0];
else:
$p = $parents[$viceversa_data[0]];
endif;
$parent = ($p == "") ? "0|" . __('No Parent', 'vice-versa') . "" : $p;
$parent = explode("|", $parent);
if(!VICEVERSA_DEBUG):
$wpdb->update(
$wpdb->posts,
array(
'guid' => $viceversa_url,
'post_parent' => intval($parent[0])
),
array( 'ID' => intval($viceversa_data[0]) ),
array(
'%s',
'%d'
),
array( '%d' )
);
clean_post_cache(intval($viceversa_data[0]));
set_post_type(intval($viceversa_data[0]), 'page');
wp_set_post_categories(intval($viceversa_data[0]), array(intval($parent[0])));
endif;
$permalink = get_permalink(intval($viceversa_data[0]));
$output .= sprintf(__('<strong>' . __('Post', 'vice-versa') . '</strong> #%s <code><a href="%s" target="_blank" title="' . __('New Permalink', 'vice-versa') . '">%s</a></code> ' . __('was successfully converted to a <strong>Page</strong> and assigned to parent', 'vice-versa') . ' #%s <code>%s</code>. <a href="%s" target="_blank" title="' . __('New Permalink', 'vice-versa') . '">' . __('New Permalink', 'vice-versa') . '</a>', 'vice-versa'), $viceversa_data[0], $permalink, $viceversa_data[2], $parent[0], $parent[1], $permalink) . "<br />\n";
endforeach;
if(!VICEVERSA_DEBUG):
$wp_rewrite->flush_rules();
endif;
endif;
}
$output .= "</p></div>\n";
define("VICEVERSA_STATUS", $output);
endif; // $this->current_action
}
function close_icon(){
echo '<input type="button" class="viceversa-close-icon button-secondary" title="' . __('Close', 'vice-versa') . '" value="x" />';
}
function prepare_items() {
global $wpdb;
$this->process_bulk_action();
$per_page = (!$_POST['per_page']) ? 10 : $_POST['per_page'];
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
if(!isset( $_POST['p_type'])):
$p_type = 'post';
elseif(in_array( $_POST['p_type'], get_post_types(array( 'show_ui' => true)))):
$p_type = $_POST['p_type'];
else:
wp_die(__('Invalid post type'));
endif;
$_POST['p_type'] = $p_type;
$post_type_object = get_post_type_object($p_type);
$orderby = (!$_REQUEST['orderby']) ? '' : ' ORDER BY ' . $_REQUEST['orderby'];
$order = (!$_REQUEST['order']) ? '' : ' ' . $_REQUEST['order'];
$search = (!$_POST['s']) ? "" : " AND " . $_POST['viceversa_search_mode'] . " REGEXP '" . $_POST['s'] . "'";
if(!current_user_can($post_type_object->cap->edit_others_posts)):
$query = "SELECT * FROM $wpdb->posts WHERE post_type = '$p_type' AND post_status NOT IN ( 'trash', 'auto-draft', 'inherit' ) AND post_author = " . get_current_user_id() . $search . $orderby . $order;
else:
$query = "SELECT * FROM $wpdb->posts WHERE post_type = '$p_type' AND post_status NOT IN ( 'trash', 'auto-draft', 'inherit' ) " . $search . $orderby . $order;
endif;
$data = $wpdb->get_results($query);
$current_page = $this->get_pagenum();
$total_items = count($data);
$data = array_slice($data,(($current_page-1)*$per_page),$per_page);
$this->items = $data;
$this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items/$per_page)));
}
function assign_to($p_type){
global $wpdb;
$output = "";
switch ($p_type){
case 'page':
$categories = get_categories('hide_empty=0&order=asc');
$output .= "<select name=\"parents[]\">\n<option value=\"\">" . __('Select A Category', 'vice-versa') . "</option>\n";
foreach($categories as $cat):
$output .= "<option title=\"" . $cat->cat_name . "\" value=\"" . $cat->term_id . "|vice-versa|";
$post_title = (strlen($cat->cat_name) > 25) ? substr($cat->cat_name, 0, 25) . '...' : $cat->cat_name;
$output .= $cat->cat_name . "\">";
$output .= $cat->cat_name . " (" . $cat->category_count . ")</option>\n";
endforeach;
$output .= "</select> <input type=\"button\" class=\"viceversa-add-category button-secondary\" value=\"+\" title=\"" . __('Add another category', 'vice-versa') . "\" /><input type=\"button\" class=\"viceversa-remove-category button-secondary\" value=\"-\" title=\"" . __('Remove this category', 'vice-versa') . "\" />\n";
break;
default :
$query = "SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status NOT IN ( 'trash', 'auto-draft' ) AND post_author = " . get_current_user_id() . " ORDER BY post_title ASC";
$parents = $wpdb->get_results($query);
$output .= "<select name=\"parents[]\">\n<option value=\"\">" . __('Select A Parent Page', 'vice-versa') . "</option>\n";
foreach ($parents as $parent):
$post = get_post(intval($parent->ID));
$output .= "<option title=\"" . $post->post_title . "\" value=\"" . $post->ID . "|vice-versa|";
$post_title = (strlen($post->post_title) > 25) ? substr($post->post_title, 0, 25) . '...' : $post->post_title;
$output .= $post_title . "\">";
$output .= $post_title . "</option>\n";
endforeach;
$output .= "</select>\n";
}
return $output;
}
} // class ViceVersa_List_Table
/***************************** RENDER PAGE ********************************
*******************************************************************************/
function viceversa_display(){
$wp_list_table = new ViceVersa_List_Table();
$wp_list_table->prepare_items();
$p_type = (!$_POST['p_type']) ? 'post' : $_POST['p_type'];
$per_page = (!$_POST['per_page']) ? 10 : $_POST['per_page'];
?>
<style type="text/css">
<!--
#viceversa-left-panel{
position: relative;
margin: 0px 150px 0px 0px !important;
/*padding: 0px 250px 0px 0px !important;*/
}
#viceversa-right-panel{
text-align: center;
position: absolute;
right: 10px;
margin: 10px 0px 0px 0px !important;
padding: 10px;
width: 120px !important;
max-width: 120px !important;
min-width: 120px !important;
background: #ECECEC;
border: 1px solid #CCC;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
.viceversa-error-field{
border: 1px solid red;
background-color: #FFFF99;
}
#viceversa-assign-error{
color:red;
font-weight: bold;
font-variant: small-caps;
}
.viceversa-close-icon, .viceversa-close-info-icon{
float: right;
margin: 5px 0px;
}
.viceversa-info{
background: #ECECEC;
border: 1px solid #CCC;
padding: 0 10px;
margin: 5px 0px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
.viceversa-hidden{
display: none;
}
#viceversa-left-panel{
z-index: 1;
width:100%;
}
#viceversa-right-panel{
z-index: 1;
}
#viceversa-form{
margin: 0px 150px 0px 0px !important;
}
.wp-list-table{
width:100%;
}
.viceversa-assign-to{
width:300px;
min-width: 300px !important;
}
.column-assign_to{
width:300px;
min-width: 300px !important;
}
.column-ID{
width:100px;
min-width: 100px !important;
}
.column-post_title{
width:350px;
min-width: 350px !important;
}
.column-post_date{
width:150px;
min-width: 150px !important;
}
-->
</style>
<div class="wrap">
<div id="icon-tools" class="icon32"><br/></div>
<h2>Vice Versa</h2>
<?php _e('Convert Pages To Posts And Vice Versa', 'vice-versa') ?><br />
<?php
$post_types=get_post_types('','names');
foreach ($post_types as $post_type ) {
echo '<p>'. $post_type. '</p>';
}
?>
<div class="viceversa-info hidden">
<input type="button" class="viceversa-close-info-icon button-secondary" title="<?php _e('Close', 'vice-versa') ?>" value="x" />
<p><?php _e('Vice Versa is a post-type converter. Follow the steps below to convert items from one post-type to another.', 'vice-versa') ?></p>
<ol start="1">
<li><?php _e('Always backup your data before making changes to your website.', 'vice-versa') ?></li>
<li><?php _e('Select a conversion mode using the <code>Post To Page</code> and <code>Page To Post</code> buttons. The <input type="button" class="button-primary" value="blue" /> button is the selected conversion mode.', 'vice-versa') ?></li>
<li><?php _e('Optional: Select a Parent or Categories to assign your Post or Page to. Use the bulk Parent or Category selector located at the bottom of the list table if needed. The Parents and Categories selectors will become visible depending on which conversion mode is selected.', 'vice-versa') ?></li>
<li><?php _e('Select Posts or Pages to convert by either using the <code>Convert</code> link for each item or by using the checkboxes and <code>Bulk Actions</code> menu.', 'vice-versa') ?></li>
<li><?php _e('<strong>Important</strong>: Vice Versa does not redirect. The links to the converted items will change automatically! You will be provided with new permalinks during the conversion process. Be prepared to change menu links if you have custom menus or have links hard-coded in your theme.', 'vice-versa') ?></li>
<li>Premium Tech Support - $25.00/hr <form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="RZ8KMAZYEDURL"><input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"></form>
</ol>
<br />
</div>
<?php
if(defined("VICEVERSA_STATUS")) echo VICEVERSA_STATUS
?>
<div id="viceversa-left-panel" class="alignleft">
<form id="viceversa-form" method="post">
<input type="hidden" name="page" value="<?php echo $_POST['page'] ?>" />
<input type="hidden" id="p-type" name="p_type" value="<?php echo $p_type ?>" />
<input type="hidden" id="per-page-hidden" name="per_page" value="10" />
<div id="viceversa-search"><?php $wp_list_table->search_box(__('Search'), 'post') ?></div>
<?php $wp_list_table->display() ?>
</form>
<div id="viceversa-assign-to" style="display: none;"><div class="viceversa-assign-to-menu"><?php echo $wp_list_table->assign_to($p_type);?></div></div>
<br />
<code><?php _e('<strong>Another <em><strong>Quality</strong></em> Work From', 'vice-versa') ?> <a href="http://JasonLau.biz" target="_blank">JasonLau.biz</a></strong> - ©Jason Lau</code> <code>[<?php _e('Vice Versa Version', 'vice-versa') ?>: <?php echo VICEVERSA_VERSION; ?>]</code>
</div><div id="viceversa-right-panel" class="alignright">
<?php
// Check for updates
$response = wp_remote_get('http://jasonlau.biz/viceversa/remote.php?version='.VICEVERSA_VERSION);
if(is_wp_error($response)):
?>
<a href="http://jasonlau.biz/home/contact-me" target="_blank"><?php _e('Advertise Here', 'vice-versa') ?></a>
<?php
else:
echo $response['body'];
endif;
?>
</div>
<script type="text/javascript">
/**
* Cookie plugin
*
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
jQuery(function($){
try{
$("#viceversa-form input[type='checkbox']").prop('checked');
}catch(e){
alert('<?php _e('Error: Vice Versa is not compatible with old versions of jQuery. Please update jQuery to the latest version from jquery.com. jquery.js is located in wp-includes/js/jquery/', 'vice-versa') ?>');
}
$("div.actions").first().prepend('<input type="button" class="vv-mode action <?php if($p_type == 'post') echo "button-primary"; else echo "button-secondary"; ?>" rel="post" value="<?php _e('Post To Page', 'vice-versa') ?>" /> <input type="button" class="vv-mode action <?php if($p_type == 'page') echo "button-primary"; else echo "button-secondary"; ?>" rel="page" value="<?php _e('Page To Post', 'vice-versa') ?>" /> <strong><?php _e('Items Per Page', 'vice-versa') ?>:</strong> <input type="text" id="per-page" size="4" value="<?php echo $per_page ?>" /><input class="vv-go button-secondary action" type="submit" value="<?php _e('Go', 'vice-versa') ?>" />');
$("#doaction").after(' <input class="vv-help button-secondary hidden" type="button" value="?" title="Info" />');
$("#post-search-input").after(' <select class="vv-search-mode" name="viceversa_search_mode"><option value="ID"<?php if($_POST['viceversa_search_mode'] == 'ID'): ?> selected="selected"<?php endif; ?>>ID</option><option value="post_title"<?php if(!$_POST['viceversa_search_mode'] || $_POST['viceversa_search_mode'] == 'post_title'): ?> selected="selected"<?php endif; ?>>Title</option><option value="post_date"<?php if($_POST['viceversa_search_mode'] == 'post_date'): ?> selected="selected"<?php endif; ?>>Date</option><option value="post_content"<?php if($_POST['viceversa_search_mode'] == 'post_content'): ?> selected="selected"<?php endif; ?>>Content</option></select>');
$('.vv-help').css('border-color','#FFFF00');
$(".vv-mode").each(function(){
$(this).bind('mouseup',function(){
$("#viceversa-form input[type='checkbox']").prop('checked',false);
$("#viceversa-form select").val('');
$("#p-type").val($(this).attr('rel'));
$("#viceversa-form").submit();
});
});
$(".vv-go").each(function(){
$(this).bind('mouseup',function(){
$("#per-page-hidden").val($("#per-page").val());
$("#viceversa-form").submit();
});
});
$(".vv-help").bind('mouseup',function(){
$(".viceversa-info").show('slow');
$(this).hide('slow');
$.cookie('vvinfo',1);
});
if($.cookie('vvinfo') == 1){
$(".viceversa-info").show();
$(".vv-help").hide();
} else {
$(".viceversa-info").hide();
$(".vv-help").show();
}
<?php
switch ($p_type){
case 'page':
?>
$(".viceversa-assign-to").each(function(){
$(this).html($("#viceversa-assign-to").html());
});
$("#viceversa-form").append('<fieldset class="viceversa-bulk-assign-field viceversa-info"><legend style="padding: 0px 4px"><strong><?php _e('Bulk Category Selector', 'vice-versa') ?></strong></legend><div id="viceversa-assign-error"><?php _e('Error: Duplicate Selected!', 'vice-versa') ?></div><div id="viceversa-bulk-assign">' + $("#viceversa-assign-to").html() + '</div></fieldset>');
<?php
break;
default :
?>
$(".viceversa-assign-to").each(function(){
$(this).html($("#viceversa-assign-to").html());
});
$("#viceversa-form").append('<fieldset class="viceversa-bulk-assign-field viceversa-info"><legend style="padding: 0px 4px"><strong><?php _e('Bulk Parent Selector', 'vice-versa') ?></strong></legend><div id="viceversa-bulk-assign">' + $("#viceversa-assign-to").html() + '</div></fieldset>');
<?php
}
?>
$(".viceversa-remove-category").not(".viceversa-remove-category:last").hide();
$(".viceversa-assign-to-text, #viceversa-assign-error").hide();
var _activate = function(){
$(".viceversa-remove-category").unbind('mouseup');
$(".viceversa-remove-category").bind('mouseup',function(){
$(this).parent().remove();
if($("#viceversa-bulk-assign select:first").val() != "" && $("#viceversa-bulk-assign select").length < 2){
if($(".viceversa-assign-to").is(':visible'))
$(".viceversa-assign-to").fadeOut();
} else if($("#viceversa-bulk-assign select:first").val() == "" && $("#viceversa-bulk-assign select").length < 2){
if(!$(".viceversa-assign-to").is(':visible'))
$(".viceversa-assign-to").fadeIn();
}
update_assignto_text();
});
$(".viceversa-add-category").unbind('mouseup');
$(".viceversa-add-category").bind('mouseup',function(){
$(this).parent().parent().append($("#viceversa-assign-to").html());
_activate();
});
$(".assign_to option").each(function(){
var check = $(this).val().split('|');
if(check.length < 4 && check.length > 2){
$(this).val($(this).val()+'|'+$(this).parent().parent().parent().attr('rel'));
}
});
$("#viceversa-bulk-assign option").each(function(){
var check = $(this).val().split('|');
if(check.length < 4 && check.length > 2)
$(this).val($(this).val()+'|0');
});
if($("#viceversa-bulk-assign select").length > 1){
$(".viceversa-assign-to").hide();
update_assignto_text();
} else {
if($("#viceversa-bulk-assign select").val() != "" && !$(".viceversa-assign-to").is(':visible'))
$(".viceversa-assign-to").fadeIn();
}
$("#viceversa-bulk-assign select").bind('change',function(){
if($(this).val() != "" && $("#viceversa-bulk-assign select").length < 2){
if($(".viceversa-assign-to").is(':visible'))
$(".viceversa-assign-to").hide();
update_assignto_text();
} else if($(this).val() == "" && $("#viceversa-bulk-assign select").length < 2){
if(!$(".viceversa-assign-to").is(':visible'))
$(".viceversa-assign-to").fadeIn();
update_assignto_text();
} else {
update_assignto_text();
}
});
update_assignto_text();
};
var update_assignto_text = function(){
var v = '', assignto = '', data = [], i = 0, error = false;
$("#viceversa-bulk-assign select").each(function(){
if($(this).val() != ""){
v = $(this).val().split('|');
$.each(data, function(key,value){
if(value == v[0]){
error = true;
$('#viceversa-assign-error').fadeIn();
return false;
}
});
if(!error){
$(this).removeClass('viceversa-error-field');
$("#viceversa-assign-error").hide();
if(assignto == ''){
assignto += v[2];
} else {
assignto += ', ' + v[2];
}
data[i] = v[0];
i++;
} else {
$(this).addClass('viceversa-error-field');
$('#viceversa-assign-error').fadeIn();
return false;
}
}
});
if(assignto != ''){
$(".viceversa-assign-to-text").html(assignto).fadeIn();
} else {
if($(".viceversa-assign-to-text").is(':visible'))
$(".viceversa-assign-to-text").html('').fadeOut();
}
};
$("form a:contains('<?php _e('Convert', 'vice-versa') ?>')").each(function(){
var url = $(this).attr('href').split('=');
$(this).attr({'href':'javascript:void(0)'});
$(this).bind('mouseup',function(){
var c = confirm('<?php _e('Are you sure you want to convert that item? Press OK to continue or Cancel to return.', 'vice-versa') ?>');
if(c == true){
$("input[data-id='"+url[3]+"']").prop('checked',true);
$("select[name='action'], select[name='action2']").val('convert');
$("#doaction2").trigger('click');
}
});
});
$(".viceversa-close-info-icon").css('text-decoration','none').click(function(){
$(this).parent().hide('slow');
$(".vv-help").show('slow');
$.cookie('vvinfo',0);
});
$(".viceversa-close-icon").css('text-decoration','none').click(function(){
$(this).parent().hide('slow');
});
_activate();
}); // jQuery
var viceversa_checkWin = function(){
if(jQuery(window).width() < 1200){
jQuery("#viceversa-right-panel").hide();
} else {
jQuery("#viceversa-right-panel").show();
}
};
window.onresize = function(){
viceversa_checkWin();
};
viceversa_checkWin();
</script>
</div>
<?php
}
?>