Advertisement
herzcthu

wp-front-end-add-post

May 23rd, 2011
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.77 KB | None | 0 0
  1. <?php
  2. function authors_dropdown_post() {
  3.     $get_tags = get_terms('authors', 'order_by=name');
  4.     $dropdown = '';
  5.     $dropdown_start = '<select size="5" onclick="" onfocus="" onblur="" class="select_input" id="select_authors" name="select_authors">';
  6.     $dropdown_start .= sprintf('<option value="">%s</option>', __('Select Authors or Type in Textbox', 'adw'));
  7.     foreach($get_tags as $tag):
  8.         $dropdown .= sprintf('<option onclick="sendText(document.wpuf_new_post_form.authors, \'%2$s, \');" href="javascript:void(0)" value="%1$s">%2$s</option>', get_term_link($tag->slug, 'authors'), $tag->name);
  9.     endforeach;
  10.     $dropdown_end = '</select>';
  11.     echo $dropdown_start.$dropdown.$dropdown_end;
  12. }
  13. function editions_dropdown_post() {
  14.     $get_tags = get_terms('editions', 'order_by=name');
  15.     $dropdown = '';
  16.     $dropdown_start = '<select size="5" onclick="" onfocus="" onblur="" class="select_input" id="select_editions" name="select_editions">';
  17.     $dropdown_start .= sprintf('<option value="">%s</option>', __('Select Editions or Type in Textbox', 'adw'));
  18.     foreach($get_tags as $tag):
  19.         $dropdown .= sprintf('<option onclick="sendText(document.wpuf_new_post_form.editions, \'%2$s, \');" href="javascript:void(0)" value="%1$s">%2$s</option>', get_term_link($tag->slug, 'editions'), $tag->name);
  20.     endforeach;
  21.     $dropdown_end = '</select>';
  22.     echo $dropdown_start.$dropdown.$dropdown_end;
  23. }
  24. function publishers_dropdown_post() {
  25.     $get_tags = get_terms('publishers', 'order_by=name');
  26.     $dropdown = '';
  27.     $dropdown_start = '<select size="5" onclick="" onfocus="" onblur="" class="select_input" id="select_publishers" name="select_publishers">';
  28.     $dropdown_start .= sprintf('<option value="">%s</option>', __('Select Publishers or Type in Textbox', 'adw'));
  29.     foreach($get_tags as $tag):
  30.         $dropdown .= sprintf('<option onfocus="" onblur="" onclick="sendText(document.wpuf_new_post_form.publishers, \'%2$s, \');" href="javascript:void(0)" value="%1$s">%2$s</option>', get_term_link($tag->slug, 'publishers'), $tag->name);
  31.     endforeach;
  32.     $dropdown_end = '</select>';
  33.     echo $dropdown_start.$dropdown.$dropdown_end;
  34. }
  35. function classcat_dropdown_post() {
  36.     $get_tags = get_terms('classcat', 'order_by=name');
  37.     $names = wp_get_object_terms($post->ID, 'classcat');
  38.     $dropdown = '';
  39.     $dropdown_start = '<select size="5" onclick="" onfocus="" onblur="" class="select_input" id="select_classcat" name="select_classcat">';
  40.     $dropdown_start .= sprintf('<option value="">%s</option>', __('Select Class/Category or Type in Textbox', 'adw'));
  41.     foreach($get_tags as $tag):
  42.         $dropdown .= sprintf('<option onclick="sendText(document.wpuf_new_post_form.classcat, \'%2$s, \');" href="javascript:void(0)" value="%1$s">%2$s</option>', $tag->slug, $tag->name);
  43.     endforeach;
  44.     $dropdown_end = '</select>';
  45.     echo $dropdown_start.$dropdown.$dropdown_end;
  46. }
  47. function wpuf_add_post_shorcode() {
  48.     wpuf_auth_redirect_login(); // if not logged in, redirect to login page
  49.     nocache_headers();
  50.     wpuf_add_post();
  51.     add_action('wp_footer', 'wpuf_post_form_style');
  52. }
  53. add_shortcode('wpuf_addpost', 'wpuf_add_post_shorcode');
  54.  
  55.  
  56. function wpuf_add_post() {
  57.  
  58.     //validate new post submission
  59.     if(isset($_POST['wpuf_new_post_submit'])) {
  60.         check_admin_referer('wpuf-add-post');
  61.         wpuf_validate_post_submit();
  62.     }
  63.  
  64.     ?> 
  65. <script language="JavaScript" type="text/JavaScript">
  66. function sendText(e, text)
  67. {
  68.   e.value = e.value + text
  69. }
  70. </script>
  71. <form name="wpuf_new_post_form" action="" method="POST">
  72.         <?php wp_nonce_field('wpuf-add-post') ?>
  73.     <ul class="wpuf-post-form">
  74.         <li>
  75.             <label for="new-post-title">
  76.                 Title <span class="required">*</span>
  77.             </label>
  78.             <input type="text" name="wpuf_post_title" value="<?php echo htmlspecialchars($_POST['wpuf_post_title']);?>" id="new-post-title" minlength="2">
  79.             <div class="clear"></div>
  80.         </li>
  81.         <li>
  82.             <label for="bookid">
  83.                 Book ID <span class="required">*</span>
  84.             </label>
  85.             <input type="text" name="bookid" value="<?php echo htmlspecialchars($_POST['bookid']);?>" id="bookid" minlength="2">
  86.             <div class="clear"></div>
  87.         </li>
  88.         <li>
  89.             <label for="authors">
  90.                 Authors:
  91.             </label>
  92.             <div class="input_boxes">
  93.             <input type="text" name="authors" value="<?php echo htmlspecialchars($_POST['authors']);?>" id="authors"><br /><?php authors_dropdown_post(); ?></div>
  94.             <div class="clear"></div>
  95.         </li>
  96.         <li>
  97.         <label for="publishers">
  98.                 Publishers:
  99.             </label>
  100.             <div class="input_boxes">
  101.             <input type="text" name="publishers" value="<?php echo htmlspecialchars($_POST['publishers']);?>" id="publishers"><br /><?php publishers_dropdown_post(); ?></div>
  102.             <div class="clear"></div>
  103.         </li>
  104.         <li>
  105.         <label for="classcat">
  106.                 Category/Class:
  107.             </label><div class="input_boxes">
  108.             <input type="text" name="classcat" value="<?php echo htmlspecialchars($_POST['classcat']);?>" id="classcat"><br /><?php classcat_dropdown_post(); ?></div>
  109.             <div class="clear"></div>
  110.         </li>
  111.         <li>
  112.         <label for="editions">
  113.                 Editions:
  114.             </label><div class="input_boxes">
  115.             <input type="text" name="editions" value="<?php echo htmlspecialchars($_POST['editions']);?>" id="editions"><br /><?php editions_dropdown_post(); ?></div>
  116.             <div class="clear"></div>
  117.         </li>
  118.         <li>
  119.             <label for="dates">
  120.                 Listed Date:
  121.             </label>
  122.             <input type="text" name="dates" id="dates" value="<?php the_time('j, M, Y'); ?>" onfocus="if (this.value == '<?php the_time('j, M, Y'); ?>') {this.value = '<?php the_time('j, M, Y'); ?>';}" onblur="if (this.value == '') {this.value = '<?php the_time('j, M, Y'); ?>';}" />
  123.             <div class="clear"></div>
  124.         </li>
  125.         <li>
  126.             <label for="new-post-desc">
  127.                 Description <span class="required">*</span>
  128.             </label>
  129.             <textarea name="wpuf_post_content" id="new-post-desc" cols="40" rows="8"></textarea>
  130.             <div class="clear"></div>
  131.         </li>
  132.         <li>
  133.             <label>&nbsp;</label>
  134.             <input class="wpuf_submit" type="submit" name="wpuf_new_post_submit" value="Post!">
  135.         </li>
  136.     </ul>
  137. </form>
  138.     <?php
  139. }
  140.  
  141. function wpuf_validate_post_submit() {
  142.     global $userdata;
  143.  
  144.     $errors = array();
  145.  
  146.     $title      = trim($_POST['wpuf_post_title']);
  147.     $content    = trim($_POST['wpuf_post_content']);
  148.     //$tags       = wpuf_clean_tags($_POST['wpuf_post_tags']);
  149.     $cat        = trim($_POST['cat']);
  150.     $authors        = wpuf_clean_tags($_POST['authors']);
  151.     $publishers        = wpuf_clean_tags($_POST['publishers']);
  152.     $editions        = wpuf_clean_tags($_POST['editions']);
  153.     $classcat        = wpuf_clean_tags($_POST['classcat']);
  154.     $dates        = wpuf_clean_tags($_POST['dates']);
  155.  
  156.     if (empty($title)) {
  157.         $errors[] = "Empty post title";
  158.     } else {
  159.         $title = trim(strip_tags($title));
  160.     }
  161.  
  162.     if (empty($content)) {
  163.         $errors[] = "Empty post content";
  164.     } else {
  165.         $content = trim($content);
  166.     }
  167.  
  168.     if (!empty($tags)) {
  169.         $tags = explode(',', $tags);
  170.     }
  171.    
  172.     if (!empty($authors)) {
  173.         $authors = explode(',', $authors);
  174.     }
  175.    
  176.     if (!empty($publishers)) {
  177.         $publishers = explode(',', $publishers);
  178.     }
  179.  
  180.     if (!empty($editions)) {
  181.         $editions = explode(',', $editions);
  182.     }
  183.    
  184.     if (!empty($classcat)) {
  185.         $classcat = explode(',', $classcat);
  186.     }
  187.     $post_status = (get_option('wpuf_post_status')) ? get_option('wpuf_post_status') : 'publish';
  188.  
  189.     if (!$errors) {
  190.         $my_post = array(
  191.                 'post_title'    => $title,
  192.                 'post_content'  => $content,
  193.                 'post_status'   => $post_status,
  194.                 'post_author'   => $userdata->ID,
  195.                 'post_category' => array($cat),
  196.                 'post_type' => 'library',
  197.                 'authors' => $authors,
  198.                 'editions' => $editions,
  199.                 'classcat' => $classcat,
  200.                 'dates' => $dates,
  201.                 'publishers' => $publishers,
  202.                 'tags_input'    => $tags
  203.         );
  204.         $post_id = wp_insert_post($my_post);
  205.  
  206.         if ($post_id) {
  207.         add_post_meta($post_id, 'bookid', $_POST['bookid']);
  208.             echo '<div class="success">Post Published succesfully.</div>';
  209.  
  210.             //send mail notification
  211.             if(get_option('wpuf_notify') == 'yes') {
  212.                 wpuf_notify_post_mail();
  213.             }
  214.         }
  215.  
  216.     } else {
  217.         echo wpuf_error_msg($errors);
  218.     }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement