PageRenderTime 44ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/acp/acp_quick_reply.php

https://github.com/Vexilurz/phpbb_forum
PHP | 241 lines | 167 code | 46 blank | 28 comment | 28 complexity | 90486bfb8f6185b73417a01af8d39e8d MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package acp
  5. * @version $Id: acp_quick_reply.php,v 1.00 2007/07/17 13:57:02 rxu Exp $
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. * @todo add cron intervals to server settings? (database_gc, queue_interval, session_gc, search_gc, cache_gc, warnings_gc)
  10. */
  11. /**
  12. * @package acp
  13. */
  14. class acp_quick_reply
  15. {
  16. var $u_action;
  17. function main($id, $mode)
  18. {
  19. global $db, $user, $auth, $template;
  20. global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
  21. $quick_reply_options = array('allow_reply_icons'=>1, 'allow_reply_checkboxes'=>2, 'allow_reply_attachbox'=>3, 'allow_reply_smilies'=>4);
  22. $quick_post_options = array('allow_post_icons'=>1, 'allow_post_checkboxes'=>2, 'allow_post_attachbox'=>3, 'allow_post_smilies'=>4);
  23. $action = request_var('action', '');
  24. $submit = (isset($_POST['submit'])) ? true : false;
  25. $form_key = 'acp_board';
  26. add_form_key($form_key);
  27. if ($mode != 'quick_reply')
  28. {
  29. return;
  30. }
  31. /**
  32. * Validation types are:
  33. * string, int, bool,
  34. * script_path (absolute path in url - beginning with / and no trailing slash),
  35. * rpath (relative), rwpath (realtive, writable), path (relative path, but able to escape the root), wpath (writable)
  36. */
  37. $display_vars = array(
  38. 'title' => 'ACP_QUICK_REPLY',
  39. 'lang' => 'mods/quick_reply',
  40. 'vars' => array(
  41. 'allow_quick_reply' => array('lang' => 'ALLOW_QUICK_REPLY', 'validate' => 'int', 'type' => 'select', 'method' => 'allow_quick_reply', 'explain' => true),
  42. 'allow_reply_icons' => array('lang' => 'ALLOW_REPLY_ICONS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
  43. 'allow_reply_checkboxes'=> array('lang' => 'ALLOW_REPLY_CHECKBOXES','validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
  44. 'allow_reply_attachbox' => array('lang' => 'ALLOW_REPLY_ATTACHBOX', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
  45. 'allow_reply_smilies' => array('lang' => 'ALLOW_REPLY_SMILIES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
  46. 'allow_quick_post' => array('lang' => 'ALLOW_QUICK_POST', 'validate' => 'int', 'type' => 'select', 'method' => 'allow_quick_post', 'explain' => true),
  47. 'allow_post_icons' => array('lang' => 'ALLOW_REPLY_ICONS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
  48. 'allow_post_checkboxes' => array('lang' => 'ALLOW_REPLY_CHECKBOXES','validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
  49. 'allow_post_attachbox' => array('lang' => 'ALLOW_REPLY_ATTACHBOX', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
  50. 'allow_post_smilies' => array('lang' => 'ALLOW_REPLY_SMILIES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false)
  51. ),
  52. );
  53. if (isset($display_vars['lang']))
  54. {
  55. $user->add_lang($display_vars['lang']);
  56. }
  57. foreach($quick_reply_options as $key => $value)
  58. {
  59. $config[$key] = ($config['allow_quick_reply_options'] & 1 << $value) ? 1 : 0;
  60. }
  61. foreach($quick_post_options as $key => $value)
  62. {
  63. $config[$key] = ($config['allow_quick_post_options'] & 1 << $value) ? 1 : 0;
  64. }
  65. $this->new_config = $config;
  66. $cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config;
  67. $error = array();
  68. // We validate the complete config if whished
  69. validate_config_vars($display_vars['vars'], $cfg_array, $error);
  70. if ($submit && !check_form_key($form_key))
  71. {
  72. $error[] = $user->lang['FORM_INVALID'];
  73. }
  74. // Do not write values if there is an error
  75. if (sizeof($error))
  76. {
  77. $submit = false;
  78. }
  79. // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
  80. foreach ($display_vars['vars'] as $config_name => $null)
  81. {
  82. if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
  83. {
  84. continue;
  85. }
  86. $this->new_config[$config_name] = $cfg_array[$config_name];
  87. }
  88. if ($submit)
  89. {
  90. foreach($quick_reply_options as $key=>$value)
  91. {
  92. if ($this->new_config[$key] && !($this->new_config['allow_quick_reply_options'] & 1 << $value))
  93. {
  94. $this->new_config['allow_quick_reply_options'] += 1 << $value;
  95. }
  96. else if(!$this->new_config[$key] && ($this->new_config['allow_quick_reply_options'] & 1 << $value))
  97. {
  98. $this->new_config['allow_quick_reply_options'] -= 1 << $value;
  99. }
  100. }
  101. foreach($quick_post_options as $key=>$value)
  102. {
  103. if ($this->new_config[$key] && !($this->new_config['allow_quick_post_options'] & 1 << $value))
  104. {
  105. $this->new_config['allow_quick_post_options'] += 1 << $value;
  106. }
  107. else if(!$this->new_config[$key] && ($this->new_config['allow_quick_post_options'] & 1 << $value))
  108. {
  109. $this->new_config['allow_quick_post_options'] -= 1 << $value;
  110. }
  111. }
  112. add_log('admin', 'LOG_CONFIG_' . strtoupper($mode));
  113. set_config('allow_quick_reply', $this->new_config['allow_quick_reply']);
  114. set_config('allow_quick_reply_options', $this->new_config['allow_quick_reply_options']);
  115. set_config('allow_quick_post', $this->new_config['allow_quick_post']);
  116. set_config('allow_quick_post_options', $this->new_config['allow_quick_post_options']);
  117. trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
  118. }
  119. $this->tpl_name = 'acp_quick_reply';
  120. $this->page_title = $display_vars['title'];
  121. $template->assign_vars(array(
  122. 'L_TITLE' => $user->lang[$display_vars['title']],
  123. 'L_TITLE_EXPLAIN' => $user->lang[$display_vars['title'] . '_EXPLAIN'],
  124. 'S_ERROR' => (sizeof($error)) ? true : false,
  125. 'ERROR_MSG' => implode('<br />', $error),
  126. 'U_ACTION' => $this->u_action)
  127. );
  128. // Output relevant page
  129. foreach ($display_vars['vars'] as $config_key => $vars)
  130. {
  131. if (!is_array($vars) && strpos($config_key, 'legend') === false)
  132. {
  133. continue;
  134. }
  135. if (strpos($config_key, 'legend') !== false)
  136. {
  137. $template->assign_block_vars('options', array(
  138. 'S_LEGEND' => true,
  139. 'LEGEND' => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars)
  140. );
  141. continue;
  142. }
  143. $type = explode(':', $vars['type']);
  144. $l_explain = '';
  145. if ($vars['explain'] && isset($vars['lang_explain']))
  146. {
  147. $l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
  148. }
  149. else if ($vars['explain'])
  150. {
  151. $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
  152. }
  153. $template->assign_block_vars('options', array(
  154. 'KEY' => $config_key,
  155. 'TITLE' => (isset($user->lang[$vars['lang']])) ? $user->lang[$vars['lang']] : $vars['lang'],
  156. 'S_EXPLAIN' => $vars['explain'],
  157. 'TITLE_EXPLAIN' => $l_explain,
  158. 'CONTENT' => build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars),
  159. )
  160. );
  161. unset($display_vars['vars'][$config_key]);
  162. }
  163. }
  164. /**
  165. * Quick reply
  166. */
  167. function allow_quick_reply($value, $key = '')
  168. {
  169. global $user;
  170. $options_ary = array(0 => 'ALLOW_QUICK_REPLY_NONE', 1 => 'ALLOW_QUICK_REPLY_REG', 2 => 'ALLOW_QUICK_REPLY_ALL');
  171. $allow_quick_reply_options = '';
  172. foreach ($options_ary as $key_value=>$option)
  173. {
  174. $selected = ($value == $key_value) ? ' selected="selected"' : '';
  175. $allow_quick_reply_options .= '<option value="' . $key_value . '"' . $selected . '>' . $user->lang[$option] . '</option>';
  176. }
  177. return $allow_quick_reply_options;
  178. }
  179. /**
  180. * Quick post
  181. */
  182. function allow_quick_post($value, $key = '')
  183. {
  184. global $user;
  185. $options_ary = array(0 => 'ALLOW_QUICK_REPLY_NONE', 1 => 'ALLOW_QUICK_REPLY_REG', 2 => 'ALLOW_QUICK_REPLY_ALL');
  186. $allow_quick_post_options = '';
  187. foreach ($options_ary as $key_value=>$option)
  188. {
  189. $selected = ($value == $key_value) ? ' selected="selected"' : '';
  190. $allow_quick_post_options .= '<option value="' . $key_value . '"' . $selected . '>' . $user->lang[$option] . '</option>';
  191. }
  192. return $allow_quick_post_options;
  193. }
  194. }
  195. ?>