Advertisement
Guest User

Post from Front End

a guest
Sep 9th, 2011
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.37 KB | None | 0 0
  1. <?php
  2. if ($_POST){
  3. $error = false;
  4.  
  5. if(cP("title") == "") {
  6. $error = true;
  7. $error_text .= __('* Please enter an event title.', "wpct")."<br />";
  8. }        
  9.  
  10. if(!isEmail(cP("FlyerEmail"))) {
  11. $error = true;
  12. $error_text .= __('* Please enter a valid email address', "wpct")."<br />";
  13. }
  14.  
  15. if(cPR("description") == "") {
  16. $error = true;
  17. $error_text .= __('* Please enter a description.', "wpct")."<br />";
  18. }
  19.  
  20. if(cPR("Location") == "") {
  21. $error = true;
  22. $error_text .= __('* Please enter a location.', "wpct")."<br />";
  23. }
  24.  
  25. if(cPR("FlyerFirstName") == "") {
  26. $error = true;
  27. $error_text .= __('* Please enter your first name.', "wpct")."<br />";
  28. }        
  29.  
  30. if(cPR("FlyerLastName") == "") {
  31. $error = true;
  32. $error_text .= __('* Please enter your last name.', "wpct")."<br />";
  33. }        
  34.  
  35. //image check
  36. if (get_option('EventFlyer_max_img_num','4')>0){
  37. $image_check=true;
  38. $image_upload=false;//nothing to upload
  39. $types=split(",",get_option('EventFlyer_img_types','jpeg'));//creating array with the allowed types
  40. for ($i=1;$i<=get_option('EventFlyer_max_img_num','4')&&$image_check;$i++){
  41. $file_size = $_FILES["pic$i"]['size'];
  42. $file_type = $_FILES["pic$i"]['type'];
  43. if ($file_size > get_option('EventFlyer_max_img_size','1000000')) {//control the size
  44.  
  45. $image_check=false;//is to big then false
  46. $error = true;
  47. $error_text .=__('* Sorry, your flyer is too large (One mb max)<br />');
  48. }
  49.  
  50. elseif ($file_type!=""){//the size is right checking type
  51. $image_check=false;//not allowed
  52. foreach ($types as $ac_type){//to find allowed types
  53. if (strpos($file_type, $ac_type)) $image_check=true;//allowed one
  54. }
  55. }
  56.  
  57. if (!$image_check) {
  58. $error = true;
  59. $error_text .=__('* Sorry, you can only upload flyers in the jpeg format')." ".get_option('')."<br />";
  60. }
  61.  
  62. if (file_exists($_FILES["pic$i"]['tmp_name'])) $image_upload=true;//there's someting to upload
  63. }
  64. }
  65.  
  66. if (!$error){
  67. if (is_numeric(cP("price"))) $price=cP("price");
  68.  
  69. else unset($price);
  70. // post information
  71. $data = array
  72.  
  73. (
  74. 'post_title' => cP("title"),
  75. 'post_content' => cPR("description"),
  76. 'post_status' => "draft",
  77. 'post_category' => array(cP("category")),
  78. 'tags_input'    => cP("tags")
  79. );
  80.  
  81. // insert post
  82. $published_id = wp_insert_post($data);
  83.  
  84. // add custom fields
  85. if (cP(Location)!="") add_post_meta($published_id, 'Location', cP("Location"), true);
  86. if (cP(FlyerFirstName)!="") add_post_meta($published_id, 'FlyerFirstName', cP("FlyerFirstName"), true);
  87. if (cP(FlyerLastName)!="") add_post_meta($published_id, 'FlyerLastName', cP("FlyerLastName"), true);
  88. if (cP(FlyerEmail)!="") add_post_meta($published_id, 'FlyerEmail', cP("FlyerEmail"), true);
  89. if (cP(phone)!="") add_post_meta($published_id, 'phone', cP("phone"), true);
  90.  
  91. // images upload
  92. if (get_option('EventFlyer_max_img_num','4')>0&&$image_upload){
  93. $upload_array = wp_upload_dir();
  94. $img_upload_dir = trailingslashit($upload_array['basedir']).get_option('EventFlyer_img_upload_dir','Event Flyer')."/".date("Y")."/".date("m")."/".date("d");
  95. if (!file_exists($img_upload_dir)) mkdir($img_upload_dir, 0777, true);
  96. for ($i=1;$i<=get_option('EventFlyer_max_img_num','4');$i++){
  97. $img_upload_file = trailingslashit($img_upload_dir).$published_id."-".$i.strrchr($_FILES["pic$i"]['name'],'.');
  98. if (move_uploaded_file($_FILES["pic$i"]['tmp_name'],$img_upload_file)){
  99. $post_images .= get_option('EventFlyer_img_upload_dir','EventFlyer')."/".date("Y")."/".date("m")."/".date("d")."/".$published_id."-".$i.strrchr($_FILES["pic$i"]['name'],'.').",";
  100. }
  101. }
  102. add_post_meta($published_id, 'EventFlyer', $post_images, true);
  103. }
  104.  
  105.               //EMAIL notify
  106.               if (get_option('permalink_structure') != '' ) {
  107.                   $linkConfirm=get_permalink(get_option('wpClassifieds_edit_page_id'))."?post=$published_id&pwd=$post_password&action=confirm";
  108.                   $linkEliminate=get_permalink(get_option('wpClassifieds_edit_page_id'))."?post=$published_id&pwd=$post_password&action=delete";
  109.                   $linkEdit=get_permalink(get_option('wpClassifieds_edit_page_id'))."?post=$published_id&pwd=$post_password&action=edit";
  110.               }
  111.               else {
  112.                   $linkConfirm=get_permalink(get_option('wpClassifieds_edit_page_id'))."&post=$published_id&pwd=$post_password&action=confirm";
  113.                   $linkEliminate=get_permalink(get_option('wpClassifieds_edit_page_id'))."&post=$published_id&pwd=$post_password&action=delete";
  114.                   $linkEdit=get_permalink(get_option('wpClassifieds_edit_page_id'))."&post=$published_id&pwd=$post_password&action=edit";
  115.               }
  116.  
  117.               $body= get_option('wpClassifieds_mail_confirm');
  118.               $body= str_replace(array("{SITE_NAME}", "{TITLE_OF_AD}", "{CONFIRM_LINK}", "{EDIT_LINK}", "{ELIMINATE_LINK}"), array(get_bloginfo('name'), cP("title"), $linkConfirm, $linkEdit, $linkEliminate), $body);
  119.  
  120.               $subject="[".get_bloginfo('name')."] ".__('Ad Confirmation', "wpct");
  121.               $headers = 'From: no-reply '.get_bloginfo('name').' <'.get_the_author_meta('email',1).'>' . "\r\n\\";
  122.               wp_mail(cP(email),$subject,$body,$headers);
  123.  
  124.               $error_text = __('Thank you! Check your email inbox to confirm your ad', "wpct");
  125.               $submitted_ad = true;
  126.  
  127. }
  128.  
  129. }
  130.  
  131. ?>
  132.  
  133.       <?php if (!$submitted_ad) : ?>
  134.  
  135.       <?php if (get_option("wpClassifieds_post_message") != "") : ?>
  136.       <div class="intro">
  137.         <?php echo get_option('wpClassifieds_post_message'); ?>
  138.       </div>
  139.       <?php endif; ?>
  140.       <?php if ($error_text) { echo "<div class=\"error-msg\">$error_text</div>"; }?>
  141.       <form action="" method="post" enctype="multipart/form-data">
  142.  
  143. <div class="field">
  144. <div class="fieldLabel">
  145. Show Title:
  146. </div>
  147. <input id="title" name="title" type="text" value="<?php echo cP("title");?>" class="PublishField" />
  148. </div>
  149.  
  150. <div class="field">
  151. <div class="fieldLabel">
  152. Show Location:
  153. </div>
  154. <input id="Location" name="Location" type="text" value="<?php echo cP("Location");?>" class="PublishField"/>
  155. </div>
  156.  
  157. <div class="field">
  158. <div class="fieldLabel">
  159. Your First Name:<span class="fieldLabelSmall">(will not be published)</span>
  160. </div>
  161. <input id="FlyerFirstName" name="FlyerFirstName" type="text" value="<?php echo cP("FlyerFirstName");?>" class="PublishField" />
  162. </div>
  163.  
  164. <div class="field">
  165. <div class="fieldLabel">
  166. Your Last Name:<span class="fieldLabelSmall">(will not be published)</span>
  167. </div>
  168. <input id="FlyerLastName" name="FlyerLastName" type="text" value="<?php echo cP("FlyerLastName");?>" class="PublishField" />
  169. </div>
  170.  
  171. <div class="field">
  172. <div class="fieldLabel">
  173. Your Email: <span class="fieldLabelSmall">(will not be published)</span>
  174. </div>
  175.  
  176. <input id="FlyerEmail" name="FlyerEmail" type="text" value="<?php echo cP("FlyerEmail");?>" class="PublishField" />
  177. </div>
  178.  
  179. <div class="field">
  180. <div class="fieldLabel">
  181. Show Description:
  182. </div>
  183. <textarea id="description" name="description" class="PublishFieldDescription">
  184. <?php echo cPR("description");?>
  185. </textarea>
  186. </div>
  187.  
  188. <?php if (get_option('EventFlyer_max_img_num','1')>0) : ?>
  189.  
  190. <?php for ($i=1;$i<=get_option('EventFlyer_max_img_num','1');$i++) : ?>
  191.  
  192. <div class="pictures">
  193. Upload Flyer
  194. <input type="file" name="pic<?php echo $i?>" id="pic<?php echo $i?>" value="<?php echo $_POST["pic".$i];?>" />
  195. </div>
  196.  
  197. <?php endfor; ?>
  198. <?php endif; ?>
  199.  
  200. <div class="submitContainer">
  201. <input name="Submit" value="SUBMIT FOR APPROVAL" type="submit" class="submit" />
  202. </div>
  203.  
  204. </form>
  205.  
  206. <?php endif; ?>
  207. <?php if ($error_text and $submitted_ad) :  ?>
  208.  
  209. <div class="error-msg"><?php echo $error_text; ?></div>
  210.  
  211. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement