Advertisement
Guest User

page-update-listing.php

a guest
Nov 20th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.90 KB | None | 0 0
  1. <?php get_header() ?>
  2. <div id="content"><!-- start #content -->
  3. <div class="padder">
  4. <div class="page" id="blog-page"><!-- start #blog-page -->
  5.  
  6. <?php
  7.  
  8. global $wp_query, $wp_taxonomies, $post, $post_ID, $CustomPress_Core;
  9.  
  10. $listing_data = '';
  11. $selected_cats = '';
  12. $error = get_query_var('dr_error');
  13. $post_statuses = get_post_statuses(); // get the wp post status list
  14. $core = new Directory_Core();
  15. $options = $core->get_options('general');
  16.  
  17. $allowed_statuses = $core->get_options('general'); // Get the ones we allow
  18. $allowed_statuses['moderation'] = (empty($allowed_statuses['moderation']) ) ? array('publish' => 1, 'draft'=> 1 ) : $allowed_statuses['moderation']; // Get the ones we allow
  19. $allowed_statuses = array_reverse(array_intersect_key($post_statuses, $allowed_statuses['moderation']) ); //return the reduced list
  20.  
  21. //Are we adding a Listing?
  22. if (is_page($core->add_listing_page_id)) {
  23. //Make an auto-draft so we have a post id to connect attachemnts to. Set global $post_ID so media editor can hook up. Watch the case
  24. $post_ID = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $core->post_type, 'post_status' => 'auto-draft' ) );
  25. $listing_data = get_post($post_ID, ARRAY_A );
  26. $listing_data['post_title'] = ''; //Have to have a title to insert the auto-save but we don't want it as final.
  27. $editing = false;
  28. }
  29.  
  30. //Or are we editing a listing?
  31. if(is_page($core->edit_listing_page_id)){
  32. $listing_data = get_post( $_REQUEST['post_id'], ARRAY_A );
  33. $post_ID = $listing_data['ID'];
  34. $editing = true;
  35. }
  36. $post = get_post($post_ID);
  37.  
  38. if ( isset( $_POST['listing_data'] ) ) $listing_data = $_POST['listing_data'];
  39.  
  40. require_once(ABSPATH . 'wp-admin/includes/template.php');
  41. require_once(ABSPATH . 'wp-admin/includes/media.php');
  42. require_once(ABSPATH . 'wp-admin/includes/post.php');
  43.  
  44. $editor_settings = array(
  45. 'wpautop' => true, // use wpautop?
  46. 'media_buttons' => true, // show insert/upload button(s)
  47. 'textarea_name' => 'listing_data[post_content]', // set the textarea name to something different, square brackets [] can be used here
  48. 'textarea_rows' => 10, //get_option('default_post_edit_rows', 10), // rows="..."
  49. 'tabindex' => '',
  50. 'editor_css' => '', // intended for extra styles for both visual and HTML editors buttons, needs to include the <style> tags, can use "scoped".
  51. 'editor_class' => 'required', // add extra class(es) to the editor textarea
  52. 'teeny' => false, // output the minimal editor config used in Press This
  53. 'dfw' => false, // replace the default fullscreen with DFW (needs specific css)
  54. 'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
  55. 'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
  56. );
  57.  
  58. $listing_content = (empty( $listing_data['post_content'] ) ) ? '' : $listing_data['post_content'];
  59.  
  60. wp_enqueue_script('set-post-thumbnail');
  61. ?>
  62. <script type="text/javascript" src="<?php echo $core->plugin_url . 'ui-front/js/jquery.tagsinput.min.js'; ?>" ></script>
  63. <script type="text/javascript" src="<?php echo $core->plugin_url . 'ui-front/js/media-post.js'; ?>" ></script>
  64. <script type="text/javascript" src="<?php echo $core->plugin_url . 'ui-front/js/ui-front.js'; ?>" >
  65. </script>
  66.  
  67. <?php if ( !empty( $error ) ): ?>
  68. <br /><div class="error"><?php echo $error . '<br />'; ?></div>
  69. <?php endif; ?>
  70.  
  71. <div class="dr_update_form">
  72.  
  73. <form class="standard-form base" method="post" action="#" enctype="multipart/form-data" id="dr_update_form" >
  74. <input type="hidden" id="post_ID" name="listing_data[ID]" value="<?php echo ( isset( $listing_data['ID'] ) ) ? $listing_data['ID'] : ''; ?>" />
  75. <input type="hidden" name="post_id" value="<?php echo ( isset( $listing_data['ID'] ) ) ? $listing_data['ID'] : ''; ?>" />
  76.  
  77. <?php if(post_type_supports('directory_listing','title') ): ?>
  78. <div class="editfield">
  79. <label for="title"><?php _e( 'Title', $core->text_domain ); ?></label>
  80. <input class="required" type="text" id="title" name="listing_data[post_title]" value="<?php echo ( isset( $listing_data['post_title'] ) ) ? esc_attr($listing_data['post_title']) : ''; ?>" />
  81. <p class="description"><?php _e( 'Enter title here.', $core->text_domain ); ?></p>
  82. </div>
  83. <?php endif; ?>
  84.  
  85. <?php if(post_type_supports('directory_listing','thumbnail') && current_theme_supports('post-thumbnails') ): ?>
  86. <div class="editfield">
  87.  
  88. <?php if(empty($options['media_manager']) ): ?>
  89.  
  90. <?php if(has_post_thumbnail()) the_post_thumbnail('thumbnail'); ?><br />
  91. <script type="text/javascript">js_translate.image_chosen = '<?php _e("Feature Image Chosen", $core->text_domain); ?>';</script>
  92. <span class="upload-button">
  93.  
  94. <?php $class = ( empty($options['field_image_req']) && !has_post_thumbnail() ) ? 'required' : ''; ?>
  95.  
  96. <input type="file" name="feature_image" size="1" id="image" class="<?php echo $class; ?>" />
  97. <button type="button" class="button"><?php _e('Set Feature Image', $core->text_domain); ?></button>
  98. </span>
  99. <br />
  100.  
  101. <?php else: ?>
  102.  
  103. <div id="postimagediv">
  104. <div class="inside">
  105. <?php
  106. $thumbnail_id = get_post_meta( $post_ID, '_thumbnail_id', true );
  107. echo _wp_post_thumbnail_html($thumbnail_id, $post_ID);
  108. ?>
  109. </div>
  110. </div>
  111. <?php endif; ?>
  112. </div>
  113. <?php endif; ?>
  114.  
  115. <?php if(post_type_supports('directory_listing','editor') ): ?>
  116. <div>
  117. <label for="listingcontent"><?php _e( 'Content', $core->text_domain ); ?></label><br />
  118.  
  119. <?php wp_editor( $listing_content, 'listingcontent', $editor_settings); ?>
  120.  
  121. <p class="description"><?php _e( 'The content of your listing.', $core->text_domain ); ?></p>
  122. </div>
  123. <?php endif; ?>
  124.  
  125. <?php if(post_type_supports('directory_listing','excerpt') ): ?>
  126. <div class="editfield alt">
  127. <label for="excerpt"><?php _e( 'Excerpt', $core->text_domain ); ?></label>
  128. <textarea id="excerpt" name="listing_data[post_excerpt]" rows="2" ><?php echo (isset( $listing_data['post_excerpt'] ) ) ? esc_textarea($listing_data['post_excerpt']) : ''; ?></textarea>
  129. <p class="description"><?php _e( 'A short excerpt of your listing.', $core->text_domain ); ?></p>
  130. </div>
  131. <?php endif; ?>
  132.  
  133. <?php
  134. //get related hierarchical taxonomies
  135. $taxonomies = get_object_taxonomies('directory_listing', 'objects');
  136. $taxonomies = empty($taxonomies) ? array() : $taxonomies;
  137.  
  138. //Loop through the taxonomies that apply
  139. foreach($taxonomies as $taxonomy):
  140. if( ! $taxonomy->hierarchical) continue;
  141. $tax_name = $taxonomy->name;
  142. $labels = $taxonomy->labels;
  143. //Get this Taxonomies terms
  144. $selected_cats = array_values( wp_get_post_terms($listing_data['ID'], $tax_name, array('fields' => 'ids') ) );
  145.  
  146.  
  147. ?>
  148.  
  149. <div id="taxonomy-<?php echo $tax_name; ?>" class="dr_taxonomydiv">
  150. <label><?php echo $labels->all_items; ?></label>
  151.  
  152. <div id="<?php echo $tax_name; ?>_all" class="dr_tax_panel">
  153. <?php
  154. $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
  155. echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
  156. ?>
  157. <ul id="<?php echo $tax_name; ?>_checklist" class="list:<?php echo $labels->name; ?> categorychecklist form-no-clear">
  158. <?php wp_terms_checklist( 0, array( 'taxonomy' => $tax_name, 'selected_cats' => $selected_cats, 'checked_ontop' => false ) ) ?>
  159. </ul>
  160. </div>
  161. <span class="description"><?php echo $labels->add_or_remove_items; ?></span>
  162. </div>
  163. <?php endforeach; ?>
  164.  
  165.  
  166. <?php
  167. //get related non-hierarchical taxonomies
  168.  
  169. //Loop through the taxonomies that apply
  170. foreach($taxonomies as $tag):
  171. if( $tag->hierarchical) continue;
  172.  
  173. $tag_name = $tag->name;
  174. $labels = $tag->labels;
  175.  
  176. //Get this Taxonomies terms
  177. $tag_list = strip_tags(get_the_term_list( $listing_data['ID'], $tag_name, '', ',', '' ));
  178.  
  179. ?>
  180.  
  181. <div class="dr_taxonomydiv">
  182. <div id="<?php echo $tag_name; ?>-checklist" class="tagchecklist">
  183. <label><?php echo $labels->name; ?>
  184. <input id="tag_<?php echo $tag_name; ?>" name="tag_input[<?php echo $tag_name; ?>]" type="text" value="<?php echo $tag_list?>" />
  185. </label>
  186. </div>
  187. <span class="description"><?php echo $labels->add_or_remove_items; ?></span>
  188. </div>
  189.  
  190. <script type="text/javascript" > jQuery('#tag_<?php echo $tag_name; ?>').tagsInput({width:'auto', height:'150px', defaultText: '<?php _e("add a tag", $core->text_domain); ?>'}); </script>
  191. <?php endforeach; ?>
  192.  
  193. <div class="clear"><br /></div>
  194.  
  195. <div class="editfield" >
  196. <label for="title"><?php _e( 'Status', $core->text_domain ); ?></label>
  197. <div id="status-box">
  198. <select name="listing_data[post_status]" id="listing_data[post_status]">
  199. <?php
  200. foreach($allowed_statuses as $key => $value): ?>
  201.  
  202. <option value="<?php echo $key; ?>" <?php selected( ! empty($listing_data['post_status'] ) && $key == $listing_data['post_status'] ); ?> ><?php echo $value; ?></option>
  203.  
  204. <?php endforeach; ?>
  205. </select>
  206. </div>
  207. <p class="description"><?php _e( 'Select a status for your Listing.', $core->text_domain ); ?></p>
  208. </div>
  209.  
  210. <?php if ( isset( $CustomPress_Core ) ) : ?>
  211. <?php echo do_shortcode('[custom_fields_input style="editfield"]'); ?>
  212. <?php endif; ?>
  213.  
  214. <?php if ( !empty( $error ) ): ?>
  215. <br /><div class="error"><?php echo $error . '<br />'; ?></div>
  216. <?php endif; ?>
  217.  
  218. <div class="submit">
  219. <?php wp_nonce_field( 'verify' ); ?>
  220. <input type="submit" value="<?php _e( 'Save Changes', $core->text_domain ); ?>" name="update_listing">
  221.  
  222. <input type="button" value="<?php _e( 'Cancel', $core->text_domain ); ?>" onclick="location.href='<?php echo get_permalink($core->my_listings_page_id); ?>'">
  223. </div>
  224. <?php //echo do_shortcode('[ct_validate]') ; ?>
  225. </form>
  226. </div>
  227. </div><!-- end #blog-page -->
  228. </div><!-- end .padder -->
  229. </div><!-- end #content -->
  230. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement