PageRenderTime 55ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_weblinks/views/weblink/view.html.php

https://github.com/joebushi/joomla
PHP | 172 lines | 102 code | 29 blank | 41 comment | 14 complexity | 4a88c93bb9675d1cd4a5bbca9be942e5 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  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.view');
  10. /**
  11. * HTML View class for the WebLinks component
  12. *
  13. * @package Joomla.Site
  14. * @subpackage com_weblinks
  15. * @since 1.5
  16. */
  17. class WeblinksViewWeblink extends JView
  18. {
  19. protected $state;
  20. protected $item;
  21. function display($tpl = null)
  22. {
  23. $app = &JFactory::getApplication();
  24. $params = &$app->getParams();
  25. // Get some data from the models
  26. $state = &$this->get('State');
  27. $item = &$this->get('Item');
  28. $category = &$this->get('Category');
  29. if ($this->getLayout() == 'edit') {
  30. $this->_displayEdit($tpl);
  31. return;
  32. }
  33. //get the weblink
  34. $weblink = &$this->get('data');
  35. if ($weblink->url) {
  36. // redirects to url if matching id found
  37. $app->redirect($weblink->url);
  38. }
  39. parent::display($tpl);
  40. }
  41. function _displayEdit($tpl)
  42. {
  43. // Get some objects from the JApplication
  44. $app = &JFactory::getApplication();
  45. $pathway = &$app->getPathway();
  46. $document = &JFactory::getDocument();
  47. $model = &$this->getModel();
  48. $user = &JFactory::getUser();
  49. $uri = &JFactory::getURI();
  50. $params = &$app->getParams();
  51. // Make sure you are logged in and have the necessary access rights
  52. if ($user->authorise('com_weblinks.edit')) {
  53. JResponse::setHeader('HTTP/1.0 403',true);
  54. JError::raiseWarning(403, JText::_('ALERTNOTAUTH'));
  55. return;
  56. }
  57. //get the weblink
  58. $weblink = &$this->get('data');
  59. $isNew = ($weblink->id < 1);
  60. // Edit or Create?
  61. if (!$isNew)
  62. {
  63. // Is this link checked out? If not by me fail
  64. //if ($model->isCheckedOut($user->get('id'))) {
  65. // $app->redirect("index.php?option=$option", "The weblink $weblink->title is currently being edited by another administrator.");
  66. //}
  67. // Set page title
  68. $menus = &JSite::getMenu();
  69. $menu = $menus->getActive();
  70. // because the application sets a default page title, we need to get it
  71. // right from the menu item itself
  72. if (is_object($menu)) {
  73. $menu_params = new JParameter($menu->params);
  74. if (!$menu_params->get('page_title')) {
  75. $params->set('page_title', JText::_('Web_Links'.' - '.JText::_('JEdit')));
  76. }
  77. } else {
  78. $params->set('page_title', JText::_('Web_Links'.' - '.JText::_('JEdit')));
  79. }
  80. $document->setTitle($params->get('page_title'));
  81. //set breadcrumbs
  82. if ($item->query['view'] != 'weblink')
  83. {
  84. switch ($item->query['view'])
  85. {
  86. case 'categories':
  87. $pathway->addItem($weblink->category, 'index.php?com_weblinks&view=categories&id='.$weblink->catid);
  88. $pathway->addItem(JText::_('JEdit').' '.$weblink->title, '');
  89. break;
  90. case 'category':
  91. $pathway->addItem($weblink->category, 'index.php?com_weblinks&view=category&id='.$weblink->catid);
  92. $pathway->addItem(JText::_('JEdit').' '.$weblink->title, '');
  93. break;
  94. }
  95. }
  96. }
  97. else
  98. {
  99. /*
  100. * The web link does not already exist so we are creating a new one. Here
  101. * we want to manipulate the pathway and pagetitle to indicate this. Also,
  102. * we need to initialise some values.
  103. */
  104. $weblink->published = 0;
  105. $weblink->approved = 1;
  106. $weblink->ordering = 0;
  107. // Set page title
  108. // Set page title
  109. $menus = &JSite::getMenu();
  110. $menu = $menus->getActive();
  111. // because the application sets a default page title, we need to get it
  112. // right from the menu item itself
  113. if (is_object($menu)) {
  114. $menu_params = new JParameter($menu->params);
  115. if (!$menu_params->get('page_title')) {
  116. $params->set('page_title', JText::_('Submit a Web Link'));
  117. }
  118. } else {
  119. $params->set('page_title', JText::_('Submit a Web Link'));
  120. }
  121. $document->setTitle($params->get('page_title'));
  122. // Add pathway item
  123. $pathway->addItem(JText::_('New'), '');
  124. }
  125. // build list of categories
  126. $lists['catid'] = JHtml::_('list.category', 'jform[catid]', 'com_weblinks', intval($weblink->catid));
  127. // build the html select list for ordering
  128. $query = 'SELECT ordering AS value, title AS text'
  129. . ' FROM #__weblinks'
  130. . ' WHERE catid = ' . (int) $weblink->catid
  131. . ' ORDER BY ordering';
  132. $lists['ordering'] = JHtml::_('list.specificordering', $weblink, $weblink->id, $query);
  133. // Radio Buttons: Should the article be published
  134. $lists['published'] = JHtml::_('select.booleanlist', 'jform[published]', 'class="inputbox"', $weblink->published);
  135. JFilterOutput::objectHTMLSafe($weblink, ENT_QUOTES, 'description');
  136. $this->assign('action', $uri->toString());
  137. $this->assignRef('lists' , $lists);
  138. $this->assignRef('weblink' , $weblink);
  139. $this->assignRef('params' , $params);
  140. parent::display($tpl);
  141. }
  142. }
  143. ?>