[ Index ]

PHP Cross Reference of MyBB 1.4.13

title

Body

[close]

/ -> sendthread.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.4
   4   * Copyright © 2008 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybboard.net
   7   * License: http://www.mybboard.net/about/license
   8   *
   9   * $Id: sendthread.php 4359 2009-04-23 18:50:06Z dennis $
  10   */
  11  
  12  define("IN_MYBB", 1);
  13  define('THIS_SCRIPT', 'sendthread.php');
  14  
  15  $templatelist = "sendthread";
  16  
  17  require_once  "./global.php";
  18  require_once  MYBB_ROOT."inc/functions_post.php";
  19  require_once  MYBB_ROOT."inc/class_parser.php";
  20  $parser = new postParser;
  21  
  22  // Load global language phrases
  23  $lang->load("sendthread");
  24  
  25  // Get thread info
  26  $tid = intval($mybb->input['tid']);
  27  $thread = get_thread($tid);
  28  $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
  29  
  30  // Invalid thread
  31  if(!$thread['tid'])
  32  {
  33      error($lang->error_invalidthread);
  34  }
  35  
  36  // Guests cannot use this feature
  37  if(!$mybb->user['uid'])
  38  {
  39      error_no_permission();
  40  }
  41  $fid = $thread['fid'];
  42  
  43  
  44  // Make navigation
  45  build_forum_breadcrumb($thread['fid']);
  46  add_breadcrumb($thread['subject'], get_thread_link($thread['tid']));
  47  add_breadcrumb($lang->nav_sendthread);
  48  
  49  // Get forum info
  50  $forum = get_forum($thread['fid']);
  51  $forumpermissions = forum_permissions($forum['fid']);
  52  
  53  // Invalid forum?
  54  if(!$forum['fid'] || $forum['type'] != "f")
  55  {
  56      error($lang->error_invalidforum);
  57  }
  58  
  59  // This user can't view this forum or this thread
  60  if($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
  61  {
  62      error_no_permission();
  63  }
  64  
  65  // Check if this forum is password protected and we have a valid password
  66  check_forum_password($forum['fid']);
  67  
  68  if($mybb->usergroup['cansendemail'] == 0)
  69  {
  70      error_no_permission();
  71  }
  72  
  73  // Check group limits
  74  if($mybb->usergroup['maxemails'] > 0)
  75  {
  76      $query = $db->simple_select("maillogs", "COUNT(*) AS sent_count", "fromuid='{$mybb->user['uid']}' AND dateline >= '".(TIME_NOW - (60*60*24))."'");
  77      $sent_count = $db->fetch_field($query, "sent_count");
  78      if($sent_count >= $mybb->usergroup['maxemails'])
  79      {
  80          $lang->error_max_emails_day = $lang->sprintf($lang->error_max_emails_day, $mybb->usergroup['maxemails']);
  81          error($lang->error_max_emails_day);
  82      }
  83  }
  84  
  85  if($mybb->input['action'] == "do_sendtofriend" && $mybb->request_method == "post")
  86  {
  87      // Verify incoming POST request
  88      verify_post_check($mybb->input['my_post_key']);
  89  
  90      $plugins->run_hooks("sendthread_do_sendtofriend_start");
  91      
  92      if(!validate_email_format($mybb->input['email']))
  93      {
  94          $errors[] = $lang->error_invalidemail;
  95      }
  96      
  97      if(empty($mybb->input['subject']))
  98      {
  99          $errors[] = $lang->error_nosubject;
 100      }    
 101      
 102      if(empty($mybb->input['message']))
 103      {
 104          $errors[] = $lang->error_nomessage;
 105      }
 106  
 107      // No errors detected
 108      if(count($errors) == 0)
 109      {
 110          if($mybb->settings['mail_handler'] == 'smtp')
 111          {
 112              $from = $mybb->user['email'];
 113          }
 114          else
 115          {
 116              $from = "{$mybb->user['username']} <{$mybb->user['email']}>";
 117          }
 118          
 119          $threadlink = get_thread_link($thread['tid']);
 120          
 121          $message = $lang->sprintf($lang->email_sendtofriend, $mybb->user['username'], $mybb->settings['bbname'], $mybb->settings['bburl']."/".$threadlink, $mybb->input['message']);
 122          
 123          // Send the actual message
 124          my_mail($mybb->input['email'], $mybb->input['subject'], $message, $from, "", "", false, "text", "", $mybb->user['email']);
 125          
 126          if($mybb->settings['mail_logging'] > 0)
 127          {
 128              // Log the message
 129              $log_entry = array(
 130                  "subject" => $db->escape_string($mybb->input['subject']),
 131                  "message" => $db->escape_string($message),
 132                  "dateline" => TIME_NOW,
 133                  "fromuid" => $mybb->user['uid'],
 134                  "fromemail" => $db->escape_string($mybb->user['email']),
 135                  "touid" => 0,
 136                  "toemail" => $db->escape_string($mybb->input['email']),
 137                  "tid" => $thread['tid'],
 138                  "ipaddress" => $db->escape_string($session->ipaddress)
 139              );
 140              $db->insert_query("maillogs", $log_entry);
 141          }
 142  
 143          $plugins->run_hooks("sendthread_do_sendtofriend_end");
 144          redirect(get_thread_link($thread['tid']), $lang->redirect_emailsent);
 145      }
 146      else
 147      {
 148          $mybb->input['action'] = '';
 149      }
 150  }
 151  
 152  if(!$mybb->input['action'])
 153  {
 154      $plugins->run_hooks("sendthread_start");
 155  
 156      // Do we have some errors?
 157      if(count($errors) >= 1)
 158      {
 159          $errors = inline_error($errors);
 160          $email = htmlspecialchars_uni($mybb->input['email']);
 161          $subject = htmlspecialchars_uni($mybb->input['subject']);
 162          $message = htmlspecialchars_uni($mybb->input['message']);
 163      }
 164      else
 165      {
 166          $errors = '';
 167          $email = '';
 168          $subject = $lang->sprintf($lang->emailsubject_sendtofriend, $mybb->settings['bbname']);
 169          $message = '';
 170      }
 171  
 172      eval("\$sendtofriend = \"".$templates->get("sendthread")."\";");
 173      $plugins->run_hooks("sendthread_end");
 174      output_page($sendtofriend);
 175  }
 176  ?>


Generated: Mon Apr 19 19:52:21 2010 Cross-referenced by PHPXref 0.7