Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.47 KB | None | 0 0
  1. <?php
  2.  
  3. // Using SSI?
  4. if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
  5.     require_once(dirname(__FILE__) . '/SSI.php');
  6. elseif (!defined('SMF'))
  7.     die('<strong>Error:</strong> Cannot install - please make sure that this file in the same directory as SMF\'s SSI.php file.');
  8.  
  9. // Call our template
  10. templateFunc();
  11.  
  12. function templateFunc()
  13. {
  14.  
  15.     // Globalize everything we'll need...
  16.     global $sourcedir, $scripturl, $fileName, $possibleBoards, $errors, $smcFunc;
  17.  
  18.     // Our Logic
  19.     loadLogic();
  20.  
  21.     // Now the HTML
  22.     echo '<form action="', $fileName, '" method="post">
  23.         <!-- NAME -->
  24.         <br /><br />
  25.         <label for="name">
  26.             <span style="font-weight: bold;', isset($errors['name']) ? ' color: #ff0000;' : '', '">*Name:</span>
  27.         </label>
  28.         <input type="text" maxlength="255" id="name" name="name" size="40"', isset($_POST['name']) && !empty($_POST['name']) ? ' value="' . $_POST['name'] . '"' : '', ' />
  29.         <!-- EMAIL -->
  30.         <br /><br />
  31.         <label for="email">
  32.             <strong>Email:</strong>
  33.         </label>
  34.         <input type="text" maxlength="255" id="email" name="email" size="40"', isset($_POST['email']) && !empty($_POST['email']) ? ' value="' . $_POST['email'] . '"' : '', ' />
  35.         <!-- SUBJECT -->
  36.         <br /><br />
  37.         <label for="subject">
  38.             <span style="font-weight: bold;', isset($errors['subject']) ? ' color: #ff0000;' : '', '">*Subject:</span>
  39.         </label>
  40.         <input type="text" maxlength="255" id="subject" name="subject" size="40"', isset($_POST['subject']) && !empty($_POST['subject']) ? ' value="' . $_POST['subject'] . '"' : '', ' />
  41.         <!-- BOARD ID -->
  42.         <br /><br />
  43.         <label for="id_board">
  44.             <strong>Board to Post in:</strong>
  45.         </label>
  46.         <select id="id_board" name="id_board" style="padding: 4px;">';
  47.         if (!empty($possibleBoards))
  48.         {
  49.             foreach ($possibleBoards as $key => $value)
  50.             {
  51.                 echo '<option value="' . $key . '"', isset($_POST['id_board']) && $_POST['id_board'] == $key ? ' selected="selected"' : '', '>' . $value . '&nbsp;&nbsp;</option>';
  52.             }
  53.         }
  54.         else
  55.         {
  56.             echo '<option value="">No Boards Available</option>';
  57.         }
  58.         echo '
  59.         </select>
  60.         <!-- BODY -->
  61.         <br /><br />
  62.         <label for="body">
  63.             <span style="font-weight: bold;', isset($errors['body']) ? ' color: #ff0000;' : '', '">*Body:</span>
  64.         </label>
  65.         <textarea id="body" name="body" cols="50" rows="5">', isset($_POST['body']) && !empty($_POST['body']) ? $_POST['body'] : '', '</textarea>
  66.         <span class="smalltext" style="margin-left: 70px; display: block;">BBC is Enabled</span>
  67.         <br />
  68.         <!-- SUBMIT -->
  69.         <input type="submit" value="Submit" />
  70.     </form>
  71.     <span class="smalltext">* = Required Fields</span>';
  72.  
  73. }
  74.  
  75. function loadLogic()
  76. {
  77.  
  78.     // Globalize everything we'll need...
  79.     global $sourcedir, $scripturl, $fileName, $smcFunc, $possibleBoards, $errors;
  80.  
  81.     // Subs-Post for createPost();
  82.     require_once($sourcedir . '/Subs-Post.php');
  83.  
  84.     // File Name with ".php"
  85.     $fileName = '.php';
  86.  
  87.     // Allow smileys? true : false;
  88.     $smileysEnabled = true;
  89.  
  90.     // Default Board
  91.     $defaultBoard = 1;
  92.  
  93.     // Possible boards?
  94.     $possibleBoards = array();
  95.     $query = $smcFunc['db_query']('', '
  96.         SELECT id_board, name
  97.         FROM {db_prefix}boards'
  98.     );
  99.     while ($row = $smcFunc['db_fetch_assoc']($query))
  100.     {
  101.         $possibleBoards[$row['id_board']] = $row['name'];
  102.     }
  103.     $smcFunc['db_free_result']($query);
  104.  
  105.     // Submitting...
  106.     if (isset($_POST['name']))
  107.     {
  108.         // Validation
  109.         $errors = array();
  110.         if (isset($_POST['name']) && empty($_POST['name']))
  111.             $errors['name'] = 1;
  112.         if (isset($_POST['subject']) && empty($_POST['subject']))
  113.             $errors['subject'] = 1;
  114.         if (isset($_POST['body']) && empty($_POST['body']))
  115.             $errors['body'] = 1;
  116.  
  117.         if (!in_array(1, $errors))
  118.         {
  119.  
  120.             // Message Options
  121.             $msgOptions = array(
  122.                 'body' => !empty($_POST['body']) ? $smcFunc['htmlspecialchars']($_POST['body']) : '',
  123.                 'subject' => !empty($_POST['subject']) ? $smcFunc['htmlspecialchars']($_POST['subject']) : '',
  124.                 'attachments' => array(),
  125.                 'icon' => 'xx',
  126.                 'smileys_enabled' => isset($smileysEnabled) ? $smileysEnabled : true,
  127.             );
  128.  
  129.             // Topic Options
  130.             $topicOptions = array(
  131.                 'board' => !empty($_POST['id_board']) ? (int) $_POST['id_board'] : $defaultBoard,
  132.                 'mark_as_read' => false,
  133.                 'lock_mode' => 0,
  134.                 'poll' => 0,
  135.                 'sticky_mode' => 0,
  136.             );
  137.  
  138.             // Poster Options
  139.             $posterOptions = array(
  140.                 'email' => !empty($_POST['email']) ? $_POST['email'] : '',
  141.                 'ip' => $_SERVER['remote_addr'],
  142.                 'name' => $_POST['name'],
  143.                 'update_post_count' => true,
  144.                 'id' => 1,
  145.             );
  146.  
  147.             // Create...
  148.             createPost($msgOptions, $topicOptions, $posterOptions);
  149.  
  150.             // Then redirect
  151.             redirectexit($scripturl);
  152.  
  153.         }
  154.  
  155.     }
  156.  
  157. }
  158.  
  159. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement