[ Index ]

PHP Cross Reference of MyBB 1.6.5

title

Body

[close]

/ -> sendthread.php (source)

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


Generated: Sun Dec 11 14:16:27 2011 Cross-referenced by PHPXref 0.7.1