PageRenderTime 27ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/contact.php

https://gitlab.com/billyprice1/cfimagehost-on-openshift
PHP | 179 lines | 106 code | 20 blank | 53 comment | 18 complexity | 9daedb207f8d8a044df9bd1147a56841 MD5 | raw file
  1. <?php
  2. /**************************************************************************************************************
  3. *
  4. * CF Image Hosting Script
  5. * ---------------------------------
  6. *
  7. * Author: codefuture.co.uk
  8. * Version: 1.6.5
  9. *
  10. * You can download the latest version from: http://codefuture.co.uk/projects/imagehost/
  11. *
  12. * Copyright (c) 2010-2013 CodeFuture.co.uk
  13. * This file is part of the CF Image Hosting Script.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
  20. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. *
  23. * You may not modify and/or remove any copyright notices or labels on the software on each
  24. * page (unless full license is purchase) and in the header of each script source file.
  25. *
  26. * You should have received a full copy of the LICENSE AGREEMENT along with
  27. * Codefuture Image Hosting Script. If not, see http://codefuture.co.uk/projects/imagehost/license/.
  28. *
  29. *
  30. * ABOUT THIS PAGE -----
  31. * Used For: Contact Us Form
  32. * Last edited: 19/12/2012
  33. *
  34. *************************************************************************************************************/
  35. define('cfih', 'contact');
  36. require './inc/cfih.php';
  37. // check to see if this page has been hidden (set in the admin panel), if so then send user to the index/home page
  38. if(!$settings['SET_HIDE_CONTACT']){
  39. header('Location: index.php');
  40. exit();
  41. }
  42. // Set page variable values
  43. $errors = array();
  44. $emailSent = false;
  45. // check to see if the contact form has been posted
  46. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  47. // Clean input variable
  48. $name = isset($_POST['name'])?cl($_POST['name']):'';
  49. $email = isset($_POST['email'])?cl($_POST['email']):'';
  50. $comment = isset($_POST['comment'])?cl($_POST['comment']):'';
  51. $captcha = isset($_POST['captcha'])?cl($_POST['captcha']):'';
  52. // check for a name
  53. if(empty($name)) $errors['name'] = _T("site_contact_err_name_blank");
  54. // check for a email address
  55. if(empty($email)){
  56. $errors['email'] = _T("site_contact_err_email_blank");
  57. }elseif(!check_email_address($email)){
  58. $errors['email'] = _T("site_contact_err_email_invalid");
  59. }
  60. // check for the email comment
  61. if(empty($comment)) $errors['comment'] = _T("site_contact_err_comment_blank");
  62. // Set the captcha Error Messages (check_captcha())
  63. define('ERROR_MESSAGE_CAPTCHA' , _T("site_contact_err_captcha_blank"));
  64. define('ERROR_MESSAGE_CAPTCHA_INVALID' , _T("site_contact_err_captcha_invalid"));
  65. define('ERROR_MESSAGE_CAPTCHA_COOKIE' , _T("site_contact_err_captcha_cookie"));
  66. // check for captcha errors
  67. require CFLIBPATH.'captcha.class.php';
  68. check_captcha($_POST['captcha'],false);
  69. if(isset($error_captcha)) $errors['captcha'] = $error_captcha;
  70. // if no errors send email
  71. if( !is_errors() ){
  72. if(strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) $ent = "\r\n";
  73. elseif(strtoupper(substr(PHP_OS, 0, 3) == 'MAC')) $ent = "\r";
  74. else $ent = "\n";
  75. $comment = ' Name: '.$name.$ent.' E-mail: '.$email.$ent.' Comment: '.$ent.$comment;
  76. $boundary = '----=_NextPart_' . md5(rand());
  77. $headers = 'From: ' . $name . '<' . $email . '>' . $ent;
  78. $headers .= 'X-Mailer: PHP/' . phpversion() . $ent;
  79. $headers .= 'MIME-Version: 1.0' . $ent;
  80. $headers .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . $ent . $ent;
  81. $message = '--' . $boundary . $ent;
  82. $message .= 'Content-Type: text/plain; charset="utf-8"' . $ent;
  83. $message .= 'Content-Transfer-Encoding: base64' . $ent . $ent;
  84. $message .= chunk_split(base64_encode($comment));
  85. ini_set('sendmail_from', $email);
  86. mail($settings['SET_CONTACT'], 'Email from contact form on '.$settings['SET_TITLE'], strip_tags(html_entity_decode($message)), $headers);
  87. $emailSent = true;
  88. }
  89. }
  90. // header page var
  91. $pageSet['id'] = 'contact_page';
  92. $pageSet['title'] = ' - '._T("site_menu_contact");
  93. $pageSet['description'] = _T("site_menu_contact").' page for '.$settings['SET_TITLE'];
  94. $pageSet['keywords'] = '';
  95. $captcha_light = (theme_setting('captcha_light')?'&amp;bg':'');
  96. // load header
  97. require CFROOTPATH.'header.php';
  98. ?>
  99. <div class="contentBox">
  100. <div id="contact">
  101. <h2><?php echo _T("site_menu_contact");?></h2>
  102. <div class="contact_box">
  103. <?php if($emailSent){ // if email is sent say thanks ?>
  104. <p class="teaser"><?php echo _T("site_contact_thank_you",$name);?></p>
  105. <?php }else{ // show contact form ?>
  106. <p class="teaser"><?php echo _T("site_contact_des",'<a href="faq.php" title="'._T("site_faq_title").'">'._T("site_faq_title").'</a>');?></p>
  107. <div id="form">
  108. <form method="post" action="contact.php">
  109. <?php echo is_errors('name');?>
  110. <div class="code_box">
  111. <label for="name"><?php echo _T("site_contact_form_name");?></label>
  112. <input name="name" type="text" id="name" class="text_input" size="24" value="<?php echo err_ReSet('name');?>" />
  113. </div>
  114. <?php echo is_errors('email');?>
  115. <div class="code_box">
  116. <label for="email"><?php echo _T("site_contact_form_email");?></label>
  117. <input name="email" type="text" id="email" class="text_input" size="24" value="<?php echo err_ReSet('email');?>" /><br/>
  118. </div>
  119. <?php echo is_errors('comment');?>
  120. <div class="code_box contact">
  121. <label for="comment"><?php echo _T("site_contact_form_comment");?></label>
  122. <textarea name="comment" id="comment" rows="8" cols="5" class="text_input long"><?php echo err_ReSet('comment');?></textarea>
  123. </div>
  124. <?php echo is_errors('captcha');?>
  125. <div class="code_box">
  126. <label for="captcha"><?php echo _T("site_contact_form_captcha");?></label>
  127. <input name="captcha" type="text" id="captcha" size="24" class="text_input" />
  128. </div>
  129. <div class="code_box"><label><?php echo _T("site_contact_form_captcha_img");?></label><a href="#Reload Captcha" onclick="document.getElementById('captchaImg').src = 'img/captcha.img.php?img<?php echo $captcha_light;?>&amp' + Math.random(); return false" class="creload"><img src="img/captcha.img.php?img<?php echo $captcha_light;?>&amp<?php echo time();?>" alt="captcha" title="<?php echo _T("site_contact_form_captcha_image_title");?>" class="captcha" id="captchaImg" /></a></div>
  130. <div class="code_box"><label></label><input type="submit" class="button" value="<?php echo _T("site_contact_form_send");?>" /></div>
  131. </form>
  132. </div>
  133. <?php } // end show contact form/thanks ?>
  134. </div>
  135. </div>
  136. </div>
  137. <?php
  138. require CFROOTPATH.'footer.php';
  139. /***
  140. * is_errors($name=null)
  141. * Checks to see if $name has a error and if so returns the error in a html span
  142. */
  143. function is_errors($name=null){
  144. global $errors;
  145. if(is_null($name) && count($errors)>0)return true;
  146. if(isset($errors[$name]))
  147. return '<span class="error_message">'.$errors[$name].'</span>';
  148. return '';
  149. }
  150. /***
  151. * err_ReSet($name)
  152. * Checks to see if there is a error and $name is not empty, if so returns $_POST[$name]
  153. */
  154. function err_ReSet($name){
  155. global $errors;
  156. if(count($errors)>0 && isset($_POST[$name]))
  157. return cl($_POST[$name]);
  158. return '';
  159. }