PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_comments/models/config.php

https://github.com/joebushi/joomla
PHP | 100 lines | 56 code | 11 blank | 33 comment | 7 complexity | 03befacc1768f8ba2d078ad9e9fa6f6e MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package JXtended.Comments
  5. * @subpackage com_comments
  6. * @copyright Copyright (C) 2008 - 2009 JXtended, LLC. All rights reserved.
  7. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  8. * @link http://jxtended.com
  9. */
  10. defined('_JEXEC') or die;
  11. jimport('joomla.application.component.model');
  12. /**
  13. * The JXtended Comments configuration model
  14. *
  15. * @package JXtended.Comments
  16. * @version 1.0
  17. */
  18. class CommentsModelConfig extends JModel
  19. {
  20. /**
  21. * Method to block either an email address or an IP from submitting data
  22. *
  23. * @access public
  24. * @param string $type The type of entity to block (eg. email, ip)
  25. * @param array $ids The items to extract block data from
  26. * @return mixed Boolean true on success, or JException on failure
  27. * @since 1.0
  28. */
  29. function block($type, $ids)
  30. {
  31. // make sure we have addresses to block
  32. if (empty($ids)) {
  33. return new JException('No item(s) supplied');
  34. }
  35. // sanitize array
  36. jimport('joomla.utilities.arrayhelper');
  37. JArrayHelper::toInteger($ids);
  38. // get the data to set based on the block type
  39. switch ($type)
  40. {
  41. case 'address':
  42. // get a database connection object
  43. $db = &$this->getDBO();
  44. // get the list of addresses to block
  45. $db->setQuery(
  46. 'SELECT `address`' .
  47. ' FROM `#__jxcomments_comments`' .
  48. ' WHERE `id` IN ('.implode(',', $ids).')'
  49. );
  50. if ($list = $db->loadResultArray())
  51. {
  52. // load the component data for com_comments
  53. $table = &JTable::getInstance('component');
  54. if (!$table->loadByOption('com_comments')) {
  55. $this->setError($table->getError());
  56. return false;
  57. }
  58. // get the existing blocked addresses and add the new ones to it
  59. $params = new JParameter($table->params);
  60. $blocked = $params->get('blockips');
  61. foreach (explode(',', $blocked) as $ip)
  62. {
  63. if ($ip = trim($ip)) {
  64. $list[] = trim($ip);
  65. }
  66. }
  67. // remove duplicates and set the blocked addresses in the configuration object
  68. $list = array_unique($list);
  69. $params->set('blockips', implode(', ', $list));
  70. $table->set('params', $params->toString());
  71. // check the row.
  72. if (!$table->check()) {
  73. $this->setError($table->getError());
  74. return false;
  75. }
  76. // store the row.
  77. if (!$table->store()) {
  78. $this->setError($table->getError());
  79. return false;
  80. }
  81. return true;
  82. }
  83. break;
  84. default:
  85. return new JException('Unknown block type');
  86. break;
  87. }
  88. }
  89. }