Guest User

Untitled

a guest
Nov 1st, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.66 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id: $
  6. * @copyright (c) 2007 DualFusion - 2008 ..::Frans::..
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. if (!defined('IN_PHPBB'))
  11. {
  12. exit;
  13. }
  14.  
  15. /**
  16. * Class welcome_pm
  17. * Send Welcome PM's and get Profile Field Information
  18. * @author ..::Frans::..
  19. */
  20. class welcome_pm
  21. {
  22. var $vars = array();
  23. var $data = array();
  24.  
  25. /**
  26. * Initializes welcome_pm class and method get_data and get_vars
  27. */
  28. function welcome_pm()
  29. {
  30. $this->get_data();
  31.  
  32. }
  33.  
  34. /**
  35. * Method get_send_userdata()
  36. * Sets all info on the user that SENDS the PM
  37. */
  38.  
  39. function get_send_userdata()
  40. {
  41. global $db;
  42. $sql = 'SELECT u.*
  43. FROM ' . WPM_TABLE . ' w,
  44. ' . USERS_TABLE . ' u
  45. WHERE w.wpm_config_id = 1
  46. AND w.wpm_send_id = u.user_id';
  47. $result = $db->sql_query($sql);
  48. $this->send_user_data = $db->sql_fetchrow($result);
  49. $db->sql_freeresult($result);
  50. }
  51.  
  52. /**
  53. * Method get_vars
  54. * Sets preset dynamic vars and initializes method get_cpf_data
  55. */
  56. function get_vars()
  57. {
  58. global $config, $user, $db, $auth;
  59.  
  60. // Get user data from user that will be sender
  61. $this->get_send_userdata();
  62.  
  63. $this->vars = array(
  64. 0 => array(
  65. 'var' => '{USER_ID}',
  66. 'value' => $user->data['user_id'],
  67. ),
  68. 1 => array(
  69. 'var' => '{USERNAME}',
  70. 'value' => $user->data['username'],
  71. ),
  72. 2 => array(
  73. 'var' => '{USER_IP}',
  74. 'value' => $user->data['user_ip'],
  75. ),
  76. 3 => array(
  77. 'var' => '{USER_REGDATE}',
  78. 'value' => $user->format_date($user->data['user_regdate']),
  79. ),
  80. 4 => array(
  81. 'var' => '{USER_EMAIL}',
  82. 'value' => $user->data['user_email'],
  83. ),
  84. 5 => array(
  85. 'var' => '{USER_LANG_EN}',
  86. 'value' => $this->get_lang('english_name'),
  87. ),
  88. 6 => array(
  89. 'var' => '{USER_LANG_LOCAL}',
  90. 'value' => $this->get_lang('local_name'),
  91. ),
  92. 7 => array(
  93. 'var' => '{USER_TZ}',
  94. 'value' => $this->get_tz(),
  95. ),
  96. 8 => array(
  97. 'var' => '{SITE_NAME}',
  98. 'value' => $config['sitename'],
  99. ),
  100. 9 => array(
  101. 'var' => '{SITE_DESC}',
  102. 'value' => $config['site_desc'],
  103. ),
  104. 10 => array(
  105. 'var' => '{BOARD_CONTACT}',
  106. 'value' => $config['board_contact'],
  107. ),
  108. 11 => array(
  109. 'var' => '{BOARD_EMAIL}',
  110. 'value' => $config['board_email'],
  111. ),
  112. 12 => array(
  113. 'var' => '{SENDER}',
  114. 'value' => $this->send_user_data['username'],
  115. ),
  116. 13 => array(
  117. 'var' => '{BOARD_SIG}',
  118. 'value' => $config['board_email_sig'],
  119. ),
  120. );
  121.  
  122. // If we're in the acp as admin...
  123. if ($auth->acl_get('a_'))
  124. {
  125. //Add language entries for displaying the vars
  126. for ($i = 0, $size = sizeof($this->vars); $i < $size; $i++)
  127. {
  128. $this->vars[$i]['name'] = $user->lang['WPM_' . substr(substr($this->vars[$i]['var'], 0, -1), 1)];
  129. }
  130. }
  131. }
  132.  
  133. /**
  134. * Method get_lang
  135. * Gets lang_id or lang_english_name based on lang_iso ($user->data['user_lang'])
  136. *
  137. * @param string $mode Tell which methods to convert to ( 'id', 'dir', 'english_name' , 'local_name', or 'author')
  138. * @return string $row The data converted
  139. */
  140. function get_lang($mode)
  141. {
  142. global $db, $user;
  143.  
  144. if ($mode)
  145. {
  146. $sql = 'SELECT lang_' . $mode . '
  147. FROM ' . LANG_TABLE . "
  148. WHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'";
  149. $result = $db->sql_query($sql);
  150. $row = $db->sql_fetchrow($result);
  151. $db->sql_freeresult($result);
  152.  
  153. if($row)
  154. {
  155. return (string) $row['lang_' . $mode];
  156. }
  157. return false;
  158. }
  159. return false;
  160. }
  161.  
  162. /**
  163. * Method get_tz
  164. * Gets timezone text from number
  165. *
  166. * @return string $user->lang The timezone data
  167. */
  168. function get_tz()
  169. {
  170. global $user;
  171.  
  172. $tz = strval(doubleval($user->data['user_timezone']));
  173. $dst = ($user->data['user_dst']) ? ' ' . $user->lang['tz']['dst'] : '';
  174.  
  175. return $user->lang['tz'][$tz] . $dst;
  176. }
  177.  
  178. /**
  179. * Method send_pm
  180. * Sends the welcome pm message to the current user
  181. */
  182. function send_wpm()
  183. {
  184. global $user, $db, $phpbb_root_path, $phpEx;
  185.  
  186. if (!function_exists('pm_notification'))
  187. {
  188. include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
  189. }
  190.  
  191. $user->add_lang('ucp');
  192.  
  193. $subject = $this->data['subject'];
  194. $text = utf8_normalize_nfc($this->data['message']);
  195.  
  196. for ($i = 0, $size = sizeof($this->vars); $i < $size; $i++)
  197. {
  198. $vars[$this->vars[$i]['var']] = $this->vars[$i]['value'];
  199. }
  200.  
  201. $subject = str_replace(array_keys($vars), array_values($vars), $subject);
  202. $message = str_replace(array_keys($vars), array_values($vars), $text);
  203.  
  204. $uid = $bitfield = $options = '';
  205. $allow_bbcode = $allow_smilies = $allow_urls = $img_status = $flash_status = true;
  206.  
  207. generate_text_for_storage($message, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
  208.  
  209. $pm_data = array(
  210. 'address_list' => array('u' => array($user->data['user_id'] => 'to')),
  211. 'from_user_id' => $this->send_user_data['user_id'],
  212. 'from_user_ip' => $this->send_user_data['user_ip'],
  213. 'from_username' => $this->send_user_data['username'],
  214. 'enable_sig' => false,
  215. 'enable_bbcode' => true,
  216. 'enable_smilies' => true,
  217. 'enable_urls' => true,
  218. 'reply_from_root_level' => 0,
  219. 'reply_from_msg_id' => 0,
  220. 'icon_id' => 0,
  221. 'bbcode_bitfield' => $bitfield,
  222. 'bbcode_uid' => $uid,
  223. 'message' => $message,
  224. );
  225. $msg_id = submit_pm('post', $subject, $pm_data);
  226. $sender_id = $this->send_user_data['username'];
  227. $receiver_id = $user->data['user_id'];
  228.  
  229. $recipients[$receiver_id] = 'to';
  230. pm_notification('post', $this->send_user_data['username'], $recipients, $subject, $pm_data['message']);
  231. }
  232.  
  233. /**
  234. * Method get_data
  235. * Gets data from wpm table
  236. */
  237. function get_data()
  238. {
  239. global $db, $config;
  240.  
  241. $sql = 'SELECT *
  242. FROM ' . WPM_TABLE . ' WHERE wpm_config_id = '. WPM_CONFIG_ID;
  243. $result = $db->sql_query($sql);
  244. $row = $db->sql_fetchrow($result);
  245. $db->sql_freeresult($result);
  246.  
  247. $this->data['subject'] = $row['wpm_subject'];
  248. $this->data['message'] = $row['wpm_message'];
  249. $this->data['enable'] = (int) $row['wpm_enable'];
  250. $this->data['user_id'] = (int) $row['wpm_send_id'];
  251. }
  252.  
  253. /**
  254. * Method set_data
  255. * Updates the wpm table (acp)
  256. */
  257. function set_data($key, $value)
  258. {
  259. global $db;
  260.  
  261. if(in_array($key, array('message', 'subject', 'enable', 'user_id')))
  262. {
  263. if($key == 'user_id')
  264. {
  265. $key = 'wpm_send_id';
  266. }
  267. else
  268. {
  269. $key = 'wpm_' . $key;
  270. }
  271.  
  272. $sql = 'UPDATE ' . WPM_TABLE . "
  273. SET " . $key . " = '" . $db->sql_escape($value) . "'
  274. WHERE wpm_config_id = " . WPM_CONFIG_ID;
  275. $db->sql_query($sql);
  276. }
  277. }
  278. }
  279. ?>
Advertisement
Add Comment
Please, Sign In to add comment