· 8 years ago · Feb 02, 2018, 08:50 AM
1<?php
2/*
3Plugin Name: Movie times by sinentradas
4Version: 1.00
5Plugin URI: http://wordpress.org/support/plugin/se-movie-times
6Description: Add movie array to set movie times by days.
7Author: sinentradas.
8Author URI: http://www.sinentradas.com/
9*/
10
11// Call function when plugin is activated
12register_activation_hook( __FILE__, 'se_movie_times_install' );
13
14function se_movie_times_install() {
15
16 // Do stuff here
17}
18
19
20// Action hook to initialize the plugin
21add_action( 'init', 'se_movie_times_init' );
22
23//Initialize the plugin
24function se_movie_times_init() {
25
26 // Register movie times cutom post type
27 $labels = array(
28 'name' => __('La cartelera de los 80', 'se-movie-times'),
29 'singular_name' => 'Event',
30 'add_new' => 'Add new event',
31 'add_new_item' => 'Add New Event',
32 'edit_new_item' => 'Edit Event',
33 'new_item' => 'New Event',
34 'all_items' => 'All Events',
35 'view_item' => 'View Event',
36 'search_items' => 'Search Events',
37 'not_found' => 'No events found',
38 'not_found_in_trash' => 'No events found in Trash',
39 'parent_item_colon' => '',
40 'menu_name' => __('Movie times', 'se-movie-times')
41 );
42
43 $args = array(
44 'labels' => $labels,
45 'public' => true,
46 'has_archive' => true,
47 'exclude_from_search' => true,
48 'rewrite' => array('slug' => 'cartelera-cine-80', 'with_front' => false),
49 'supports' => array('title', 'comments'),
50 );
51
52 register_post_type('movie-times', $args);
53
54}
55
56// Create new taxonomie for films genders
57add_action( 'init', 'prowp_define_movie_times_channel_taxonomy' );
58
59function prowp_define_movie_times_channel_taxonomy() {
60 register_taxonomy( 'channel', 'movie-times', array(
61 'label' => 'Cadena TV',
62 'hierarchical' => false,
63 'query_var' => true,
64 'rewrite' => array('slug' => 'cartelera-cine-80-cadena', 'with_front' => false),
65 ));
66}
67
68add_action('admin_enqueue_scripts','se_movie_times_js');
69
70function se_movie_times_js() {
71 wp_register_script( 'se-movie-times-js', plugins_url( '/js/se-movie-times.js', __FILE__ ));
72 wp_enqueue_script( 'se-movie-times-js', plugins_url( '/js/se-movie-times.js', __FILE__ ));
73}
74
75//Action hook to register the Movie times meta box
76add_action( 'add_meta_boxes', 'se_movie_times_register_meta_box' );
77
78function se_movie_times_register_meta_box() {
79
80 //Create our custom meta box
81 add_meta_box( 'se-movie-times-meta',
82 __( 'Movie times', 'se-movie-times'),
83 'se_movie_times_meta_box', 'movie-times', 'normal', 'default');
84}
85add_action( 'admin_footer', 'my_action_javascript' ); // Write our JS below here
86
87function my_action_javascript() { ?>
88 <script type="text/javascript" >
89 jQuery(document).ready(function($) {
90
91 jQuery(document).on('focus', '.my-suggest', function() {
92 jQuery( this ).suggest(ajaxurl + '?action=my_action', {
93 onSelect: function() {
94 hiddenInput = jQuery(this).data('child');
95 thevalue = this.value;
96 thevalue = thevalue.split(' , id:');
97 jQuery( this ).val(thevalue[0]);
98 jQuery('#my-suggest-id-' + hiddenInput).val(thevalue[1]);
99 }
100 });
101 });
102 });
103 </script> <?php
104}
105
106add_action( 'wp_ajax_my_action', 'my_action' );
107
108function my_action() {
109
110 $search = like_escape($_REQUEST['q']);
111
112 $args1 = array(
113 'post_type' => 'movies',
114 'posts_per_page' => '10',
115 's' => $search,
116 'meta_query' => array(
117 array(
118 'key' => '_se-aka-belongs-to',
119 'compare' => 'NOT EXISTS'
120 )
121 ),
122 'orderby' => 'title',
123 'order' => 'ASC'
124 );
125
126 //Get all movies
127 $movies = new WP_Query( $args1 );
128 $rows = $movies->get_posts();
129
130 foreach ($rows as $row) {
131 $post_title = $row->post_title;
132 $id = $row->ID;
133
134 echo $post_title . " , id:". $id . "\n";
135 }
136
137 wp_die(); // this is required to terminate immediately and return a proper response
138}
139
140
141function se_movie_times_meta_box($post) {
142
143
144 //For edit mode
145 $films = get_post_meta($post->ID, '_se-movie-times-film', true);
146 $hours = get_post_meta($post->ID, '_se-movie-times-hour', true);
147 $minutes = get_post_meta($post->ID, '_se-movie-times-minutes', true);
148 $channels = get_post_meta($post->ID, '_se-movie-times-channel', true);
149
150 //Get all channels
151 $args = array(
152 'hide_empty' => 0
153 );
154
155 $allChannels = get_terms('channel', $args);
156
157 // If edit, run each film
158 if (count($films) >= 1 && gettype($films) == 'array') {
159
160 //Adds each film to a select element
161 $colSelectMovies = array();
162 foreach ($films as $key => $film) {
163
164 $ajaxInput = '<div class="jaxtag suggest-me">';
165 $ajaxInput .= '<div class="ajaxtag hide-if-no-js">';
166 $ajaxInput .= '<input type="text" id="my-suggest-' . $key .'" data-child="'. $key .'" name="movie-time-film-names[]" class="form-input-tip my-suggest ui-autocomplete-input" size="16" autocomplete="off" aria-describedby="new-tag-genre-desc" value="' . get_the_title($film) . '" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-owns="ui-id-1">';
167 $ajaxInput .= '<input type="hidden" id="my-suggest-id-'. $key .'" value="' . $film .'" name="movie-time-film[]" >';
168 $ajaxInput .= '</div>';
169 $ajaxInput .= '</div>';
170
171 $colSelectMovies[] = $ajaxInput;
172 }
173
174 //Adds each channel to a select element
175 $colSelectChannels = array();
176 foreach($channels as $key => $channel) {
177 if ($key == 0) {
178 $selectChannels = '<select name="movie-time-channel[]" class="channels-list">';
179 }else{
180 $selectChannels = '<select name="movie-time-channel[]">';
181 }
182 $selectChannels .= '<option value="#NONE#"> Select â€â€</option>';
183 if ($allChannels) {
184 foreach ($allChannels as $oneChannel ) {
185 if ($oneChannel->name == $channel) {
186 $selectChannels .= '<option selected value="'. $oneChannel->name .'">'. $oneChannel->name .'</option>';
187 }else {
188 $selectChannels .= '<option value="'. $oneChannel->name .'">'. $oneChannel->name .'</option>';
189 }
190 }
191 }else{
192 $selectChannels .= '<option value="#NONE#">No hay pelis</option>';
193 }
194 $selectChannels .= '</select>';
195 $colSelectChannels[] = $selectChannels;
196 }
197 }else {
198 //Set a film select
199 $ajaxInput = '<div class="jaxtag">';
200 $ajaxInput .= '<div class="ajaxtag hide-if-no-js">';
201 $ajaxInput .= '<input type="text" id="my-suggest-1" data-child="1" name="movie-time-film-name[]" class="form-input-tip my-suggest ui-autocomplete-input" size="16" autocomplete="off" aria-describedby="new-tag-genre-desc" value="" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-owns="ui-id-1">';
202 $ajaxInput .= '<input type="hidden" id="my-suggest-id-1" name="movie-time-film[]" >';
203 $ajaxInput .= '</div>';
204 $ajaxInput .= '</div>';
205
206 //Set a channel select
207 $selectChannels = '<select name="movie-time-channel[]" class="channels-list">';
208 $selectChannels .= '<option value="#NONE#"> Select â€â€</option>';
209 if ($allChannels) {
210 foreach ($allChannels as $oneChannel ) {
211 $selectChannels .= '<option value="'. $oneChannel->name .'">'. $oneChannel->name .'</option>';
212 }
213 }else{
214 $selectChannels .= '<option value="#NONE#">No hay pelis</option>';
215 }
216 $selectChannels .= '</select>';
217 }
218
219
220
221 //nonce field for security
222 wp_nonce_field( 'meta-box-save', 'se-movie-times');
223
224 //Display metabox
225 echo '<div id="postcustom" data-screen="movie-times">';
226 echo '<div id="postcustomstuff">';
227 echo '<table id="new-movie-time">';
228 echo '<thead>';
229 echo '<tr>';
230 echo '<th class="left"><label for="metakeyselect">Film</label></th>';
231 echo '<th><label for="metavalue">Hour</label></th>';
232 echo '<th><label for="metavalue">Channel</label></th>';
233 echo '</tr>';
234 echo '</thead>';
235 echo '<tbody class="input_fields_wrap">';
236
237 if ( count($films) >= 1 && gettype($films) == 'array' ) {
238 for($i=0; $i < count($films); $i++) {
239
240 $rowWrapper = $i +1;
241 echo '<tr class="movie-time-row row-wrapper-'. $rowWrapper .'">';
242 echo '<td id="newmetaleft" class="left">';
243 echo $colSelectMovies[$i];
244 echo '</td>';
245 echo '<td>';
246 echo '<input type="text" maxlength="2" value="'. $hours[$i] .'" name="movie-time-hour[]" style="width: 40%;">:';
247 echo '<input type="text" maxlength="2" value="'. $minutes[$i] .'" name="movie-time-minutes[]" style="width: 40%">';
248 echo '</td>';
249 echo '<td>';
250 echo $colSelectChannels[$i];
251 echo '</td>';
252 }
253 }else {
254 echo '<tr class="movie-time-row">';
255 echo '<td id="newmetaleft" class="left">';
256 echo $ajaxInput;
257 echo '</td>';
258 echo '<td>';
259 echo '<input type="text" maxlength="2" placeholder="00" value="00" name="movie-time-hour[]" style="width: 40%;">:';
260 echo '<input type="text" maxlength="2" placeholder="00" value="00" name="movie-time-minutes[]" style="width: 40%">';
261 echo '</td>';
262 echo '<td>';
263 echo $selectChannels;
264 echo '</td>';
265 }
266
267 if ( count($films) >= 1 && gettype($films) == 'array' ) {
268 for($i = 0; $i <= count($films); $i++) {
269 echo '</tr>';
270 }
271 }else {
272 echo '</tr>';
273 }
274
275 echo '</tbody>';
276 echo '<tfoot>';
277 echo '<tr>';
278 echo '<td colspan="3">';
279 echo '<div class="submit">';
280 echo '<input type="button" name="addmeta" id="newmeta-submit" class="button add_field_button" value="Add Movie Time"></div>';
281 echo '</tfoot>';
282 echo '</table>';
283 echo '</div>';
284 echo '</div>';
285
286}
287
288add_action( 'save_post', 'se_movie_times_save_meta_box') ;
289
290//Save meta box data
291function se_movie_times_save_meta_box( $post_id ) {
292
293 //verify the post type is for movie times and metadata has been posted
294 if ( get_post_type( $post_id ) == 'movie-times' &&
295 isset( $_POST['movie-time-film'] ) ) {
296
297 // if autosave skip saving data
298 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
299 return;
300
301 //check nonce for security
302 check_admin_referer( 'meta-box-save', 'se-movie-times' );
303
304 //save the meta box data as post metadata
305 update_post_meta( $post_id, '_se-movie-times-film', $_POST['movie-time-film'] );
306 update_post_meta( $post_id, '_se-movie-times-channel', $_POST['movie-time-channel']);
307 update_post_meta( $post_id, '_se-movie-times-hour', $_POST['movie-time-hour']);
308 update_post_meta( $post_id, '_se-movie-times-minutes', $_POST['movie-time-minutes']);
309
310 }
311
312}
313
314// Action hook to create the movie time shortcode
315add_action( 'hs', 'se_movie_time_shortcode');
316
317function se_movie_time_shortcode( $atts, $content = null) {
318
319 global $post;
320
321 extract (shortcode_atts( array(
322 "show" => ''
323 ), $atts) );
324
325 //load options array
326 $movieTimesOptionsArray = get_option( 'se-movie-times' );
327
328}
329
330/** New implementation metaboxes for relate films */
331
332//Action hook to register the Movies meta box
333add_action( 'add_meta_boxes', 'se_movies_register_meta_box' );
334
335function se_movies_register_meta_box() {
336
337 //Create our custom meta box
338 add_meta_box( 'se-movies-meta',
339 __( 'Movies', 'se-movie-times'),
340 'se_movies_meta_box', array('post', 'films', 'oscars'), 'side', 'default');
341}
342
343function se_movies_meta_box($post) {
344
345 //For edit mode
346 $moviesToBelongs = get_post_meta($post->ID, '_se-belongs-to-movie');
347
348 // If edit, run each film
349 if (count($moviesToBelongs) >= 1 && gettype($moviesToBelongs) == 'array') {
350
351 //Adds each film to a select element
352 $colSelectMovies = array();
353 foreach ($moviesToBelongs as $key => $film) {
354
355
356 $ajaxInput = '<div class="jaxtag suggest-me">';
357 $ajaxInput .= '<div class="ajaxtag hide-if-no-js">';
358 $ajaxInput .= '<input type="text" id="my-suggest-' . $key .'" data-child="'. $key .'" name="movie-time-film-names[]" class="form-input-tip my-suggest ui-autocomplete-input" size="16" autocomplete="off" aria-describedby="new-tag-genre-desc" value="' . get_the_title($film) . '" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-owns="ui-id-1">';
359 $ajaxInput .= '<input type="hidden" id="my-suggest-id-'. $key .'" value="' . $film .'" name="movie-time-film[]" >';
360 $ajaxInput .= '</div>';
361 $ajaxInput .= '</div>';
362
363 $colSelectMovies[] = $ajaxInput;
364
365 }
366 }else {
367
368 $ajaxInput = '<div class="jaxtag">';
369 $ajaxInput .= '<div class="ajaxtag hide-if-no-js">';
370 $ajaxInput .= '<input type="text" id="my-suggest-1" data-child="1" name="movie-time-film-name[]" class="form-input-tip my-suggest ui-autocomplete-input" size="16" autocomplete="off" aria-describedby="new-tag-genre-desc" value="" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-owns="ui-id-1">';
371 $ajaxInput .= '<input type="hidden" id="my-suggest-id-1" name="movie-time-film[]" >';
372 $ajaxInput .= '</div>';
373 $ajaxInput .= '</div>';
374 }
375
376 //nonce field for security
377 wp_nonce_field( 'meta-box-save', 'se-movies');
378
379 //Display metabox
380 echo '<div id="postcustom" data-screen="movies">';
381 echo '<div id="postcustomstuff">';
382 echo '<table id="new-movie-time">';
383 echo '<thead>';
384 echo '<tr>';
385 echo '<th class="left"><label for="metakeyselect">PelÃÂculas en este contenido</label></th>';
386 echo '</tr>';
387 echo '</thead>';
388 echo '<tbody class="input_fields_wrap">';
389
390 if ( count($moviesToBelongs) >= 1 && gettype($moviesToBelongs) == 'array' ) {
391 for($i=0; $i < count($moviesToBelongs); $i++) {
392
393 $rowWrapper = $i +1;
394 echo '<tr class="movie-time-row row-wrapper-'. $rowWrapper .'">';
395 echo '<td id="newmetaleft" class="left">';
396 echo $colSelectMovies[$i];
397 echo '</td>';
398 }
399 }else {
400 echo '<tr class="movie-time-row">';
401 echo '<td id="newmetaleft" class="left">';
402 echo $ajaxInput;
403 echo '</td>';
404 }
405
406 if ( count($moviesToBelongs) >= 1 && gettype($moviesToBelongs) == 'array' ) {
407 for($i = 0; $i <= count($moviesToBelongs); $i++) {
408 echo '</tr>';
409 }
410 }else {
411 echo '</tr>';
412 }
413
414 echo '</tbody>';
415 echo '<tfoot>';
416 echo '<tr>';
417 echo '<td>';
418 echo '<div class="submit">';
419 echo '<input type="button" name="addmeta" id="newmeta-submit" class="button add_field_button" value="Add Film"></div>';
420 echo '</tfoot>';
421 echo '</table>';
422 echo '</div>';
423 echo '</div>';
424
425}
426
427add_action( 'save_post', 'se_movies_save_meta_box') ;
428
429//Save meta box data
430function se_movies_save_meta_box( $post_id ) {
431
432
433 //verify the post type is for movie times and metadata has been posted
434 //FIXME puede pertener a films (bluray) o posts de momento
435 if ( (get_post_type( $post_id ) == 'films' || get_post_type( $post_id ) == 'post' || get_post_type( $post_id ) == 'oscars') &&
436 isset( $_POST['movie-time-film'] ) ) {
437
438 // if autosave skip saving data
439 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
440 return;
441
442 //check nonce for security
443 check_admin_referer( 'meta-box-save', 'se-movies' );
444
445 //FIXME Eliminamos todas las peliculas previamente seleccionadas y almacenamos las nuevas
446 delete_post_meta($post_id, '_se-belongs-to-movie');
447
448 //save the meta box data as post metadata
449 foreach ($_POST['movie-time-film'] as $movieId) {
450 //Add new meta data with value
451 add_post_meta( $post_id, '_se-belongs-to-movie', $movieId );
452 }
453 }
454}
455
456/** Adds redirect metabox for bluray/dvds */
457
458//Action hook to register the Movies meta box
459add_action( 'add_meta_boxes', 'se_redirect_register_meta_box' );
460
461function se_redirect_register_meta_box() {
462
463 //Create our custom meta box
464 add_meta_box( 'se-redirect-meta',
465 __( 'Redirect', 'se-movie-times'),
466 'se_redirect_meta_box', 'films', 'normal', 'default');
467}
468
469function se_redirect_meta_box($post) {
470
471 //For edit mode
472 $redirect = get_post_meta($post->ID, 'redirect', true);
473
474 // If edit
475 if ($redirect) {
476 $inputRedirect = '<input type="text" name="redirect" size="200" value="'. $redirect. '" id="redirect" autocomplete="off"><a style="margin-left: 5px; display: inline-block" href="'. $redirect .'" target="_blank">Link</a>';
477 }else {
478 $inputRedirect = '<input type="text" name="redirect" size="200" id="redirect" autocomplete="off">';
479 }
480
481 //nonce field for security
482 wp_nonce_field( 'meta-box-save', 'se-movies');
483
484 //Display metabox
485 echo '<div id="postcustom">';
486 echo '<div id="postcustomstuff">';
487
488 echo $inputRedirect;
489
490 echo '</div>';
491 echo '</div>';
492}
493
494add_action( 'save_post', 'se_redirect_save_meta_box') ;
495
496//Save meta box data
497function se_redirect_save_meta_box( $post_id ) {
498
499 //verify the post type is for movie times and metadata has been posted
500 //FIXME puede pertener a films (bluray) o posts de momento
501 if ( get_post_type( $post_id ) == 'films' &&
502 isset( $_POST['movie-time-film'] ) ) {
503
504 // if autosave skip saving data
505 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
506 return;
507
508 //check nonce for security
509 check_admin_referer( 'meta-box-save', 'se-movies' );
510
511 //save the meta box data as post metadata
512 update_post_meta( $post_id, 'redirect', $_POST['redirect'] );
513 }
514}
515
516/** Adds original title metabox for films */
517
518//Action hook to register the Movies meta box
519add_action( 'add_meta_boxes', 'se_original_name_register_meta_box' );
520
521function se_original_name_register_meta_box() {
522
523 //Create our custom meta box
524 add_meta_box( 'se-original-name-meta',
525 __( 'Original name', 'se-movie-times'),
526 'se_original_name_meta_box', 'movies', 'normal', 'default');
527}
528
529function se_original_name_meta_box($post) {
530
531 //For edit mode
532 $originalName = get_post_meta($post->ID, '_se-movies-original-name', true);
533
534 // If edit
535 $inputOriginalName = '<input type="text" name="originalName" size="200" value="'. $originalName. '" id="originalName" autocomplete="off">';
536
537 //nonce field for security
538 wp_nonce_field( 'meta-box-save', 'se-movies');
539
540 //Display metabox
541 echo '<div id="postcustom">';
542 echo '<div id="postcustomstuff">';
543
544 echo $inputOriginalName;
545
546 echo '</div>';
547 echo '</div>';
548}
549
550add_action( 'save_post', 'se_original_name_save_meta_box') ;
551
552//Save meta box data
553function se_original_name_save_meta_box( $post_id ) {
554
555 //verify the post type is for movie times and metadata has been posted
556 //FIXME puede pertener a films (bluray) o posts de momento
557 if ( get_post_type( $post_id ) == 'movies' &&
558 isset( $_POST['originalName'] ) ) {
559
560 // if autosave skip saving data
561 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
562 return;
563
564 //check nonce for security
565 check_admin_referer( 'meta-box-save', 'se-movies' );
566
567 //save the meta box data as post metadata
568 update_post_meta( $post_id, '_se-movies-original-name', $_POST['originalName'] );
569 }
570}
571
572/** Adds year metabox for films */
573
574//Action hook to register the Movies meta box
575add_action( 'add_meta_boxes', 'se_duration_register_meta_box' );
576
577function se_duration_register_meta_box() {
578
579 //Create our custom meta box
580 add_meta_box( 'se-duration-meta',
581 __( 'Duration', 'se-movie-times'),
582 'se_duration_meta_box', 'movies', 'side', 'default');
583}
584
585function se_duration_meta_box($post) {
586
587 //For edit mode
588 $value = get_post_meta($post->ID, '_se-movies-duration', true);
589
590 // If edit
591 $input = '<input type="text" name="duration" size="200" value="'. $value. '" id="duration" autocomplete="off">';
592
593 //nonce field for security
594 wp_nonce_field( 'meta-box-save', 'se-movies');
595
596 //Display metabox
597 echo '<div id="postcustom">';
598 echo '<div id="postcustomstuff">';
599
600 echo '<table id="new-movie-time">';
601 echo '<tbody class="input_fields_wrap">';
602
603 echo '<tr><td>'. $input . '</td></tr>';
604
605 echo '</tbody>';
606 echo '</table>';
607
608 echo '</div>';
609 echo '</div>';
610}
611
612add_action( 'save_post', 'se_duration_save_meta_box') ;
613
614//Save meta box data
615function se_duration_save_meta_box( $post_id ) {
616
617 //verify the post type is for movie times and metadata has been posted
618 //FIXME puede pertener a films (bluray) o posts de momento
619 if ( get_post_type( $post_id ) == 'movies' &&
620 isset( $_POST['duration'] ) ) {
621
622 // if autosave skip saving data
623 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
624 return;
625
626 //check nonce for security
627 check_admin_referer( 'meta-box-save', 'se-movies' );
628
629 //save the meta box data as post metadata
630 update_post_meta( $post_id, '_se-movies-duration', $_POST['duration'] );
631 }
632}
633
634//Action hook to register the ordered cast meta box
635add_action( 'add_meta_boxes', 'se_ordered_cast_register_meta_box' );
636
637function se_ordered_cast_register_meta_box() {
638
639 //Create our custom meta box
640 add_meta_box( 'se-ordered-cast-meta',
641 __( 'Ordered Cast (Only read)', 'se-movie-times'),
642 'se_ordered_cast_meta_box', array('movies'), 'side', 'default');
643}
644
645function se_ordered_cast_meta_box($post) {
646
647 //For edit mode
648 $moviesToBelongs = get_post_meta($post->ID, '_se-movie-ordered-cast');
649 $orderedCast = $moviesToBelongs[0];
650
651 //nonce field for security
652 wp_nonce_field( 'meta-box-save', 'se-movies');
653
654 //Display metabox
655 echo '<div id="postcustom1">';
656 echo '<div id="postcustomstuff1">';
657 echo '<table id="orderedCast">';
658 echo '<tbody class="input_fields_wrap">';
659
660 if ( count($orderedCast) >= 1 && gettype($orderedCast) == 'array' ) {
661 for($i=0; $i < count($orderedCast); $i++) {
662
663 $rowWrapper = $i +1;
664 echo '<tr class="row-wrapper-'. $rowWrapper .'">';
665 echo '<td id="newmetaleft" class="left">';
666 echo $orderedCast[$i];
667 echo '</td>';
668 echo '</tr>';
669 }
670 }
671
672 echo '</tbody>';
673 echo '</table>';
674 echo '</div>';
675 echo '</div>';
676
677}
678
679add_action( 'save_post', 'se_ordered_cast_save_meta_box') ;
680
681//Save meta box data
682function se_ordered_cast_save_meta_box( $post_id ) {
683
684
685 //verify the post type is for movie times and metadata has been posted
686 //FIXME puede pertener a films (bluray) o posts de momento
687 if ( (get_post_type( $post_id ) == 'movies') &&
688 isset( $_POST['movie-time-film'] ) ) {
689
690 // if autosave skip saving data
691 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
692 return;
693
694 //check nonce for security
695 check_admin_referer( 'meta-box-save', 'se-movies' );
696
697 //FIXME Eliminamos todas las peliculas previamente seleccionadas y almacenamos las nuevas
698 //delete_post_meta($post_id, '_se-movie-ordered-cast');
699
700 //save the meta box data as post metadata
701 //Add new meta data with value
702 //add_post_meta( $post_id, '_se-movie-ordered-cast', $_POST['movie-time-film'] );
703 }
704}
705
706/** Adds aka_belongs_to metabox */
707
708//Action hook to register the Movies meta box
709add_action( 'add_meta_boxes', 'se_aka_belongs_to_register_meta_box' );
710
711function se_aka_belongs_to_register_meta_box() {
712
713 //Create our custom meta box
714 add_meta_box( 'se-aka-belongs-to-meta',
715 __( 'AKA Belongs to', 'se-movie-times'),
716 'se_aka_belongs_to_meta_box', 'movies', 'side', 'default');
717}
718
719function se_aka_belongs_to_meta_box($post) {
720
721 //For edit mode
722 $moviesToBelongs = get_post_meta($post->ID, '_se-aka-belongs-to', true);
723 $movieName = '';
724
725 if ($moviesToBelongs !== '') {
726 $movieName = get_the_title($moviesToBelongs);
727 }
728
729 // If edit, run each film
730 $ajaxInput = '<div class="jaxtag suggest-me">';
731 $ajaxInput .= '<div class="ajaxtag hide-if-no-js">';
732 $ajaxInput .= '<input type="text" id="my-suggest-1" data-child="1" name="belongs-to-name" class="form-input-tip my-suggest ui-autocomplete-input" size="16" autocomplete="off" aria-describedby="new-tag-genre-desc" value="' . $movieName . '" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-owns="ui-id-1">';
733 $ajaxInput .= '<input type="hidden" id="my-suggest-id-1" value="' . $moviesToBelongs .'" name="belongs-to" >';
734 $ajaxInput .= '</div>';
735 $ajaxInput .= '</div>';
736
737 //nonce field for security
738 wp_nonce_field( 'meta-box-save', 'se-movies');
739
740 //Display metabox
741 echo '<div id="postcustom" data-screen="movies">';
742 echo '<div id="postcustomstuff">';
743 echo '<table id="new-movie-time">';
744 echo '<thead>';
745 echo '<tr>';
746 echo '<th class="left"><label for="metakeyselect">Esta pelÃÂcula es un AKA de</label></th>';
747 echo '</tr>';
748 echo '</thead>';
749 echo '<tbody class="input_fields_wrap">';
750
751 echo '<tr class="movie-time-row row-wrapper-1">';
752 echo '<td id="newmetaleft" class="left">';
753 echo $ajaxInput;
754 echo '</td>';
755
756 echo '</tr>';
757
758 echo '<tr class="btn-row row-wrapper-1" ><td colspan="3" style="text-align: right; padding: 0 15px;"><a href="#" class="clear_field" data-row="1">Remove</a></td></tr></div>';
759
760
761 echo '</tbody>';
762 echo '</table>';
763 echo '</div>';
764 echo '</div>';
765 // hasta aqui
766}
767
768add_action( 'save_post', 'se_aka_belongs_to_save_meta_box') ;
769
770//Save meta box data
771function se_aka_belongs_to_save_meta_box( $post_id ) {
772
773 //FIXME Eliminamos todas las peliculas previamente seleccionadas y almacenamos las nuevas
774 delete_post_meta($post_id, '_se-aka-belongs-to');
775
776 //verify the post type is for movie times and metadata has been posted
777 //FIXME puede pertener a films (bluray) o posts de momento
778 if ( get_post_type( $post_id ) == 'movies' &&
779 isset( $_POST['belongs-to']) && $_POST['belongs-to'] !== '' ) {
780
781 // if autosave skip saving data
782 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
783 return;
784
785 //check nonce for security
786 check_admin_referer( 'meta-box-save', 'se-movies' );
787
788 //save the meta box data as post metadata
789 update_post_meta( $post_id, '_se-aka-belongs-to', $_POST['belongs-to'] );
790 }
791}