PageRenderTime 48ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_redirect/models/link.php

https://github.com/dbxdnl/GitHub
PHP | 135 lines | 58 code | 16 blank | 61 comment | 6 complexity | 19c1b39f664f60c34ebe8676dee3329b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: link.php 18817 2010-09-08 10:47:15Z eddieajau $
  4. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. */
  7. // No direct access.
  8. defined('_JEXEC') or die;
  9. jimport('joomla.application.component.modeladmin');
  10. /**
  11. * Redirect link model.
  12. *
  13. * @package Joomla.Administrator
  14. * @subpackage com_redirect
  15. * @since 1.6
  16. */
  17. class RedirectModelLink extends JModelAdmin
  18. {
  19. /**
  20. * @var string The prefix to use with controller messages.
  21. * @since 1.6
  22. */
  23. protected $text_prefix = 'COM_REDIRECT';
  24. /**
  25. * Returns a reference to the a Table object, always creating it.
  26. *
  27. * @param type The table type to instantiate
  28. * @param string A prefix for the table class name. Optional.
  29. * @param array Configuration array for model. Optional.
  30. * @return JTable A database object
  31. * @since 1.6
  32. */
  33. public function getTable($type = 'Link', $prefix = 'RedirectTable', $config = array())
  34. {
  35. return JTable::getInstance($type, $prefix, $config);
  36. }
  37. /**
  38. * Method to get the record form.
  39. *
  40. * @param array $data Data for the form.
  41. * @param boolean $loadData True if the form is to load its own data (default case), false if not.
  42. * @return JForm A JForm object on success, false on failure
  43. * @since 1.6
  44. */
  45. public function getForm($data = array(), $loadData = true)
  46. {
  47. // Get the form.
  48. $form = $this->loadForm('com_redirect.link', 'link', array('control' => 'jform', 'load_data' => $loadData));
  49. if (empty($form)) {
  50. return false;
  51. }
  52. // Modify the form based on access controls.
  53. if (!$this->canEditState((object) $data)) {
  54. // Disable fields for display.
  55. $form->setFieldAttribute('published', 'disabled', 'true');
  56. // Disable fields while saving.
  57. // The controller has already verified this is a record you can edit.
  58. $form->setFieldAttribute('published', 'filter', 'unset');
  59. }
  60. return $form;
  61. }
  62. /**
  63. * Method to get the data that should be injected in the form.
  64. *
  65. * @return mixed The data for the form.
  66. * @since 1.6
  67. */
  68. protected function loadFormData()
  69. {
  70. // Check the session for previously entered form data.
  71. $data = JFactory::getApplication()->getUserState('com_redirect.edit.link.data', array());
  72. if (empty($data)) {
  73. $data = $this->getItem();
  74. }
  75. return $data;
  76. }
  77. /**
  78. * Method to activate links.
  79. *
  80. * @param array An array of link ids.
  81. * @param string The new URL to set for the redirect.
  82. * @param string A comment for the redirect links.
  83. * @return boolean Returns true on success, false on failure.
  84. * @since 1.6
  85. */
  86. public function activate(&$pks, $url, $comment = null)
  87. {
  88. // Initialise variables.
  89. $user = JFactory::getUser();
  90. $db = $this->getDbo();
  91. // Sanitize the ids.
  92. $pks = (array) $pks;
  93. JArrayHelper::toInteger($pks);
  94. // Populate default comment if necessary.
  95. $comment = (!empty($comment)) ? $comment : JText::sprintf('COM_REDIRECT_REDIRECTED_ON', JHTML::_('date',time()));
  96. // Access checks.
  97. if (!$user->authorise('core.edit', 'com_redirect')) {
  98. $pks = array();
  99. $this->setError(JText::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'));
  100. return false;
  101. }
  102. if (!empty($pks)) {
  103. // Update the link rows.
  104. $db->setQuery(
  105. 'UPDATE `#__redirect_links`' .
  106. ' SET `new_url` = '.$db->Quote($url).', `published` = 1, `comment` = '.$db->Quote($comment) .
  107. ' WHERE `id` IN ('.implode(',', $pks).')'
  108. );
  109. $db->query();
  110. // Check for a database error.
  111. if ($error = $this->_db->getErrorMsg())
  112. {
  113. $this->setError($error);
  114. return false;
  115. }
  116. }
  117. return true;
  118. }
  119. }