Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion adm/style/boardrules_manage_add_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ <h3>{{ lang('WARNING') }}</h3>
<label><input type="checkbox" class="radio" name="disable_magic_url"{% if S_MAGIC_URL_DISABLE_CHECKED and (S_PREVIEW or not S_ADD_RULE) %} checked="checked"{% endif %}> {{ lang('DISABLE_MAGIC_URL') }}</label>
{% endif %}
</dd>
<dd style="margin-{{ S_CONTENT_FLOW_BEGIN }}: 90px; margin-top: 10px;"><strong>{{ lang('OPTIONS') ~ lang('COLON') }} </strong>{{ BBCODE_STATUS }} :: {{ IMG_STATUS }} :: {{ FLASH_STATUS }} :: {{ URL_STATUS }} :: {{ SMILIES_STATUS }}</dd>
<dd style="margin-{{ S_CONTENT_FLOW_BEGIN }}: 90px; margin-top: 10px;"><strong>{{ lang('OPTIONS') ~ lang('COLON') }} </strong>{{ BBCODE_STATUS }} :: {{ IMG_STATUS }} :: {{ URL_STATUS }} :: {{ SMILIES_STATUS }}</dd>
</dl>
{% endif %}
</fieldset>
Expand Down
64 changes: 43 additions & 21 deletions controller/admin_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function display_language_dashboard()
* @param int $parent_id Category to display rules from; default: 0
* @return void
* @access public
* @throws \phpbb\boardrules\exception\base If stored rule data is invalid
* @throws \InvalidArgumentException If stored rule data is invalid
*/
public function display_rules($language, $parent_id = 0)
{
Expand Down Expand Up @@ -514,7 +514,7 @@ protected function get_ruleset_return_url($language, $return_to)
* @param int $parent_id Category to display rules from; default: 0
* @return void
* @access public
* @throws \phpbb\boardrules\exception\base If stored rule data is invalid
* @throws \InvalidArgumentException If stored rule data is invalid
*/
public function add_rule($language, $parent_id = 0)
{
Expand Down Expand Up @@ -555,7 +555,7 @@ public function add_rule($language, $parent_id = 0)
* @param int $rule_id The rule identifier to edit
* @return void
* @access public
* @throws \phpbb\boardrules\exception\base If stored rule data is invalid
* @throws \InvalidArgumentException If stored rule data is invalid
*/
public function edit_rule($rule_id)
{
Expand Down Expand Up @@ -596,7 +596,7 @@ public function edit_rule($rule_id)
* @param array $data The form data to be processed
* @return void
* @access protected
* @throws \phpbb\boardrules\exception\base If stored rule data is invalid
* @throws \InvalidArgumentException If stored rule data is invalid
*/
protected function add_edit_rule_data($entity, $data)
{
Expand Down Expand Up @@ -632,6 +632,12 @@ protected function add_edit_rule_data($entity, $data)
'anchor' => $data['rule_anchor'],
'message' => $data['rule_message'],
);
$field_labels = array(
'language' => 'ACP_BOARDRULES_LANGUAGE',
'title' => 'ACP_RULE_TITLE',
'anchor' => 'ACP_RULE_ANCHOR',
'message' => 'ACP_RULE_MESSAGE',
);

// Set the rule's data in the entity
foreach ($rule_fields as $entity_function => $rule_data)
Expand All @@ -640,10 +646,10 @@ protected function add_edit_rule_data($entity, $data)
{
$entity->{'set_' . $entity_function}($rule_data);
}
catch (\phpbb\boardrules\exception\base $e)
catch (\InvalidArgumentException $e)
{
// Catch exceptions and add them to errors array
$errors[] = $e->get_message($this->lang);
$errors[] = $this->lang->lang($field_labels[$entity_function]) . $this->lang->lang('COLON') . ' ' . $this->lang->lang($e->getMessage());
}
}

Expand Down Expand Up @@ -687,9 +693,9 @@ protected function add_edit_rule_data($entity, $data)
{
$entity->save();
}
catch (\phpbb\boardrules\exception\out_of_bounds $e)
catch (\LogicException $e)
{
trigger_error($e->get_message($this->lang) . adm_back_link($this->u_action), E_USER_WARNING);
trigger_error($this->lang->lang('RULES_NESTEDSET_INVALID_ITEM') . adm_back_link($this->u_action), E_USER_WARNING);
}

// Change rule parent
Expand All @@ -699,9 +705,9 @@ protected function add_edit_rule_data($entity, $data)
{
$this->rule_operator->change_parent($entity->get_id(), $data['rule_parent_id']);
}
catch (\phpbb\boardrules\exception\out_of_bounds $e)
catch (\OutOfBoundsException $e)
{
trigger_error($e->get_message($this->lang) . adm_back_link($this->u_action), E_USER_WARNING);
trigger_error($this->get_rule_error_message($e) . adm_back_link($this->u_action), E_USER_WARNING);
}
catch (\Exception $e)
{
Expand All @@ -719,9 +725,12 @@ protected function add_edit_rule_data($entity, $data)
{
$this->rule_operator->add_rule($entity, $data['rule_language'], $data['rule_parent_id']);
}
catch (\phpbb\boardrules\exception\out_of_bounds $e)
catch (\OutOfBoundsException | \LogicException $e)
{
trigger_error($e->get_message($this->lang) . adm_back_link($this->u_action), E_USER_WARNING);
$message = $e instanceof \OutOfBoundsException
? $this->get_rule_error_message($e)
: $this->lang->lang('RULES_NESTEDSET_INVALID_ITEM');
trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
}
catch (\InvalidArgumentException|\RuntimeException $e)
{
Expand Down Expand Up @@ -754,13 +763,11 @@ protected function add_edit_rule_data($entity, $data)
'BBCODE_STATUS' => $this->lang->lang('BBCODE_IS_ON', '<a href="' . $this->controller_helper->route('phpbb_help_bbcode_controller') . '">', '</a>'),
'SMILIES_STATUS' => $this->lang->lang('SMILIES_ARE_ON'),
'IMG_STATUS' => $this->lang->lang('IMAGES_ARE_ON'),
'FLASH_STATUS' => $this->lang->lang('FLASH_IS_ON'),
'URL_STATUS' => $this->lang->lang('URL_IS_ON'),

'S_BBCODE_ALLOWED' => true,
'S_SMILIES_ALLOWED' => true,
'S_BBCODE_IMG' => true,
'S_BBCODE_FLASH' => true,
'S_LINKS_ALLOWED' => true,
));

Expand Down Expand Up @@ -789,9 +796,9 @@ public function delete_rule($rule_id)
{
$this->rule_operator->delete_rule($rule_id);
}
catch (\phpbb\boardrules\exception\out_of_bounds $e)
catch (\OutOfBoundsException $e)
{
trigger_error($e->get_message($this->lang) . adm_back_link($this->u_action), E_USER_WARNING);
trigger_error($this->get_rule_error_message($e) . adm_back_link($this->u_action), E_USER_WARNING);
}
catch (\Exception $e)
{
Expand Down Expand Up @@ -842,9 +849,9 @@ public function move_rule($rule_id, $direction, $amount = 1)
{
$moved = $this->rule_operator->move($rule_id, $direction, $amount);
}
catch (\phpbb\boardrules\exception\out_of_bounds $e)
catch (\OutOfBoundsException $e)
{
trigger_error($e->get_message($this->lang) . adm_back_link($this->u_action), E_USER_WARNING);
trigger_error($this->get_rule_error_message($e) . adm_back_link($this->u_action), E_USER_WARNING);
}
catch (\Exception $e)
{
Expand Down Expand Up @@ -926,12 +933,27 @@ protected function load_rule($rule_id)
{
return $this->container->get('phpbb.boardrules.entity')->load($rule_id);
}
catch (\phpbb\boardrules\exception\out_of_bounds $e)
catch (\OutOfBoundsException $e)
{
trigger_error($e->get_message($this->lang) . adm_back_link($this->u_action), E_USER_WARNING);
trigger_error($this->get_rule_error_message($e) . adm_back_link($this->u_action), E_USER_WARNING);
}
}

/**
* Translate a rule lookup or parent validation failure for ACP output.
*
* @param \OutOfBoundsException $exception
* @return string
*/
protected function get_rule_error_message(\OutOfBoundsException $exception)
{
$key = $exception->getMessage() === 'RULE_PARENT_INVALID'
? 'RULES_NESTEDSET_INVALID_PARENT'
: 'RULES_NESTEDSET_INVALID_ITEM';

return $this->lang->lang($key);
}

/**
* Assign installed language options and return their dashboard data.
*
Expand Down Expand Up @@ -1009,7 +1031,7 @@ protected function has_copy_source(array $languages, $target_language)
* @param int $parent_id Category to display rules from; default: 0
* @return void
* @access protected
* @throws \phpbb\boardrules\exception\base If stored rule data is invalid
* @throws \InvalidArgumentException If stored rule data is invalid
*/
protected function build_parent_select_menu($entity, $parent_id = 0)
{
Expand Down
10 changes: 5 additions & 5 deletions controller/admin_interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function set_ruleset_published($language, $published, $return_to = '');
* @param int $parent_id Category to display rules from; default: 0
* @return void
* @access public
* @throws \phpbb\boardrules\exception\base If stored rule data is invalid
* @throws \InvalidArgumentException If stored rule data is invalid
*/
public function display_rules($language, $parent_id = 0);

Expand All @@ -78,7 +78,7 @@ public function save_ruleset_intro($language);
* @param int $parent_id Category to display rules from; default: 0
* @return void
* @access public
* @throws \phpbb\boardrules\exception\base If stored rule data is invalid
* @throws \InvalidArgumentException If stored rule data is invalid
*/
public function add_rule($language, $parent_id = 0);

Expand All @@ -88,7 +88,7 @@ public function add_rule($language, $parent_id = 0);
* @param int $rule_id The rule identifier to edit
* @return void
* @access public
* @throws \phpbb\boardrules\exception\base If the rule does not exist or stored rule data is invalid
* @throws \InvalidArgumentException If the rule does not exist or stored rule data is invalid
*/
public function edit_rule($rule_id);

Expand All @@ -98,7 +98,7 @@ public function edit_rule($rule_id);
* @param int $rule_id The rule identifier to delete
* @return void
* @access public
* @throws \phpbb\boardrules\exception\out_of_bounds If the rule does not exist
* @throws \OutOfBoundsException If the rule does not exist
*/
public function delete_rule($rule_id);

Expand All @@ -110,7 +110,7 @@ public function delete_rule($rule_id);
* @param int $amount The number of places to move the rule
* @return void
* @access public
* @throws \phpbb\boardrules\exception\out_of_bounds If the rule does not exist after moving
* @throws \OutOfBoundsException If the rule does not exist after moving
*/
public function move_rule($rule_id, $direction, $amount = 1);

Expand Down
2 changes: 1 addition & 1 deletion controller/main_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct(\phpbb\config\config $config, \phpbb\controller\help
*
* @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
* @access public
* @throws \phpbb\boardrules\exception\base If stored rule data is invalid
* @throws \InvalidArgumentException If stored rule data is invalid
*/
public function display()
{
Expand Down
2 changes: 1 addition & 1 deletion controller/main_interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface main_interface
*
* @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
* @access public
* @throws \phpbb\boardrules\exception\base If stored rule data is invalid
* @throws \InvalidArgumentException If stored rule data is invalid
*/
public function display();
}
34 changes: 17 additions & 17 deletions entity/rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(\phpbb\db\driver\driver_interface $db, $boardrules_t
* @param int $id Rule identifier
* @return rule_interface $this object for chaining calls; load()->set()->save()
* @access public
* @throws \phpbb\boardrules\exception\out_of_bounds
* @throws \OutOfBoundsException
*/
public function load($id)
{
Expand All @@ -78,7 +78,7 @@ public function load($id)
if ($this->data === false)
{
// A rule does not exist
throw new \phpbb\boardrules\exception\out_of_bounds('rule_id');
throw new \OutOfBoundsException('RULE_NOT_FOUND');
}

return $this;
Expand All @@ -95,7 +95,7 @@ public function load($id)
* @param array $data Data array, typically from the database
* @return rule_interface $this object for chaining calls; load()->set()->save()
* @access public
* @throws \phpbb\boardrules\exception\base
* @throws \InvalidArgumentException
*/
public function import($data)
{
Expand Down Expand Up @@ -127,7 +127,7 @@ public function import($data)
// If the data wasn't sent to us, throw an exception
if (!isset($data[$field]))
{
throw new \phpbb\boardrules\exception\invalid_argument(array($field, 'FIELD_MISSING'));
throw new \InvalidArgumentException('RULE_FIELD_MISSING:' . $field);
}

// If the type is a method on this class, call it
Expand Down Expand Up @@ -161,7 +161,7 @@ public function import($data)
// If the data is less than 0, it's not unsigned and we'll throw an exception
if ($this->data[$field] < 0)
{
throw new \phpbb\boardrules\exception\out_of_bounds($field);
throw new \InvalidArgumentException('RULE_FIELD_NOT_UNSIGNED:' . $field);
}
}

Expand All @@ -176,14 +176,14 @@ public function import($data)
* @param string $language The language iso
* @return rule_interface $this object for chaining calls; load()->set()->save()
* @access public
* @throws \phpbb\boardrules\exception\out_of_bounds
* @throws \LogicException
*/
public function insert($language)
{
if (!empty($this->data['rule_id']))
{
// The rule already exists
throw new \phpbb\boardrules\exception\out_of_bounds('rule_id');
throw new \LogicException('RULE_ALREADY_INSERTED');
}

// Resets values required for the nested set system
Expand Down Expand Up @@ -216,14 +216,14 @@ public function insert($language)
*
* @return rule_interface $this object for chaining calls; load()->set()->save()
* @access public
* @throws \phpbb\boardrules\exception\out_of_bounds
* @throws \LogicException
*/
public function save()
{
if (empty($this->data['rule_id']))
{
// The rule does not exist
throw new \phpbb\boardrules\exception\out_of_bounds('rule_id');
throw new \LogicException('RULE_NOT_INSERTED');
}

// Copy the data array, filtering out the rule_id identifier
Expand Down Expand Up @@ -267,7 +267,7 @@ public function get_title()
* @param string $title
* @return rule_interface $this object for chaining calls; load()->set()->save()
* @access public
* @throws \phpbb\boardrules\exception\unexpected_value
* @throws \InvalidArgumentException
*/
public function set_title($title)
{
Expand All @@ -282,7 +282,7 @@ public function set_title($title)
// Enforce the database column length after storage encoding.
if (utf8_strlen($title) > 200)
{
throw new \phpbb\boardrules\exception\unexpected_value(array('title', 'TOO_LONG'));
throw new \InvalidArgumentException('TOO_LONG');
}

// Set the title on our data array
Expand Down Expand Up @@ -479,7 +479,7 @@ public function get_anchor()
* @param string $anchor Anchor text
* @return rule_interface $this object for chaining calls; load()->set()->save()
* @access public
* @throws \phpbb\boardrules\exception\unexpected_value
* @throws \InvalidArgumentException
*/
public function set_anchor($anchor)
{
Expand All @@ -499,12 +499,12 @@ public function set_anchor($anchor)
// Restrict them to BMP letters, marks, numbers, hyphens, and underscores.
if (!preg_match('/^(?!.*[\x{10000}-\x{10FFFF}])[\p{L}\p{N}_-][\p{L}\p{M}\p{N}_-]*$/u', $anchor))
{
throw new \phpbb\boardrules\exception\unexpected_value(array('anchor', 'ILLEGAL_CHARACTERS'));
throw new \InvalidArgumentException('ACP_BOARDRULES_VALIDATION_INVALID_CHARACTERS');
}

if (utf8_strlen($anchor) > 255)
{
throw new \phpbb\boardrules\exception\unexpected_value(array('anchor', 'TOO_LONG'));
throw new \InvalidArgumentException('TOO_LONG');
}

// Make sure the anchor is unique for the current language.
Expand All @@ -524,7 +524,7 @@ public function set_anchor($anchor)

if ($row)
{
throw new \phpbb\boardrules\exception\unexpected_value(array('anchor', 'NOT_UNIQUE'));
throw new \InvalidArgumentException('ACP_BOARDRULES_VALIDATION_NOT_UNIQUE');
}
}

Expand All @@ -551,7 +551,7 @@ public function get_language()
* @param string $language language iso
* @return rule_interface $this object for chaining calls; load()->set()->save()
* @access public
* @throws \phpbb\boardrules\exception\unexpected_value
* @throws \InvalidArgumentException
*/
public function set_language($language)
{
Expand All @@ -569,7 +569,7 @@ public function set_language($language)

if (!$lang_id)
{
throw new \phpbb\boardrules\exception\unexpected_value(array('rule_language', 'WRONG_DATA_LANG', 'UNEXPECTED_VALUE'));
throw new \InvalidArgumentException('ACP_BOARDRULES_INVALID_LANGUAGE');
}
}

Expand Down
Loading