PageRenderTime 691ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_categories/views/category/view.html.php

https://github.com/sengann/iks-school.com
PHP | 152 lines | 88 code | 23 blank | 41 comment | 25 complexity | a7a76a48c895017c958398d02fabf483 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: view.html.php 19331 2010-11-02 17:32:30Z chdemko $
  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. // Check to ensure this file is included in Joomla!
  8. defined('_JEXEC') or die;
  9. jimport('joomla.application.component.view');
  10. /**
  11. * HTML View class for the Categories component
  12. *
  13. * @static
  14. * @package Joomla.Administrator
  15. * @subpackage com_categories
  16. */
  17. class CategoriesViewCategory extends JView
  18. {
  19. protected $form;
  20. protected $item;
  21. protected $state;
  22. /**
  23. * Display the view
  24. */
  25. public function display($tpl = null)
  26. {
  27. $this->form = $this->get('Form');
  28. $this->item = $this->get('Item');
  29. $this->state = $this->get('State');
  30. // Check for errors.
  31. if (count($errors = $this->get('Errors'))) {
  32. JError::raiseError(500, implode("\n", $errors));
  33. return false;
  34. }
  35. parent::display($tpl);
  36. JRequest::setVar('hidemainmenu', true);
  37. $this->addToolbar();
  38. }
  39. /**
  40. * Add the page title and toolbar.
  41. *
  42. * @since 1.6
  43. */
  44. protected function addToolbar()
  45. {
  46. // Initialise variables.
  47. $extension = JRequest::getCmd('extension');
  48. $user = JFactory::getUser();
  49. $userId = $user->get('id');
  50. $isNew = ($this->item->id == 0);
  51. $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $userId);
  52. // Avoid nonsense situation.
  53. if ($extension == 'com_categories') {
  54. return;
  55. }
  56. // The extension can be in the form com_foo.section
  57. $parts = explode('.',$extension);
  58. $component = $parts[0];
  59. $section = (count($parts) > 1) ? $parts[1] : null;
  60. // Need to load the menu language file as mod_menu hasn't been loaded yet.
  61. $lang = JFactory::getLanguage();
  62. $lang->load($component, JPATH_BASE, null, false, false)
  63. || $lang->load($component, JPATH_ADMINISTRATOR.'/components/'.$component, null, false, false)
  64. || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false)
  65. || $lang->load($component, JPATH_ADMINISTRATOR.'/components/'.$component, $lang->getDefault(), false, false);
  66. // Load the category helper.
  67. require_once JPATH_COMPONENT.'/helpers/categories.php';
  68. // Get the results for each action.
  69. $canDo = CategoriesHelper::getActions($component, $this->item->id);
  70. // If a component categories title string is present, let's use it.
  71. if ($lang->hasKey($component_title_key = $component.($section?"_$section":'').'_CATEGORY_'.($isNew?'ADD':'EDIT').'_TITLE')) {
  72. $title = JText::_($component_title_key);
  73. }
  74. // Else if the component section string exits, let's use it
  75. elseif ($lang->hasKey($component_section_key = $component.($section?"_$section":''))) {
  76. $title = JText::sprintf( 'COM_CATEGORIES_CATEGORY_'.($isNew?'ADD':'EDIT').'_TITLE', $this->escape(JText::_($component_section_key)));
  77. }
  78. // Else use the base title
  79. else {
  80. $title = JText::_('COM_CATEGORIES_CATEGORY_BASE_'.($isNew?'ADD':'EDIT').'_TITLE');
  81. }
  82. // Load specific css component
  83. JHtml::_('stylesheet',$component.'/administrator/categories.css', array(), true);
  84. // Prepare the toolbar.
  85. JToolBarHelper::title($title, substr($component,4).($section?"-$section":'').'-category-'.($isNew?'add':'edit').'.png');
  86. // For new records, check the create permission.
  87. if ($isNew && $canDo->get('core.create')) {
  88. JToolBarHelper::apply('category.apply', 'JTOOLBAR_APPLY');
  89. JToolBarHelper::save('category.save', 'JTOOLBAR_SAVE');
  90. JToolBarHelper::custom('category.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
  91. }
  92. // If not checked out, can save the item.
  93. else if (!$checkedOut && ($canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_user_id == $userId))) {
  94. JToolBarHelper::apply('category.apply', 'JTOOLBAR_APPLY');
  95. JToolBarHelper::save('category.save', 'JTOOLBAR_SAVE');
  96. if ($canDo->get('core.create')) {
  97. JToolBarHelper::custom('category.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
  98. }
  99. }
  100. // If an existing item, can save to a copy.
  101. if (!$isNew && $canDo->get('core.create')) {
  102. JToolBarHelper::custom('category.save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false);
  103. }
  104. if (empty($this->item->id)) {
  105. JToolBarHelper::cancel('category.cancel','JTOOLBAR_CANCEL');
  106. }
  107. else {
  108. JToolBarHelper::cancel('category.cancel', 'JTOOLBAR_CLOSE');
  109. }
  110. JToolBarHelper::divider();
  111. // Compute the ref_key if it does exist in the component
  112. if (!$lang->hasKey($ref_key = strtoupper($component.($section?"_$section":'')).'_CATEGORY_'.($isNew?'ADD':'EDIT').'_HELP_KEY')) {
  113. $ref_key = 'JHELP_COMPONENTS_'.strtoupper(substr($component,4).($section?"_$section":'')).'_CATEGORY_'.($isNew?'ADD':'EDIT');
  114. }
  115. // Get help for the category/section view for the component by
  116. // -remotely searching in a language defined dedicated URL: *component*_HELP_URL
  117. // -locally searching in a component help file if helpURL param exists in the component and is set to ''
  118. // -remotely searching in a component URL if helpURL param exists in the component and is NOT set to ''
  119. if ($lang->hasKey($lang_help_url = strtoupper($component).'_HELP_URL')) {
  120. $debug = $lang->setDebug(false);
  121. $url = JText::_($lang_help_url);
  122. $lang->setDebug($debug);
  123. }
  124. else {
  125. $url = null;
  126. }
  127. JToolBarHelper::help($ref_key, JComponentHelper::getParams( $component )->exists('helpURL'), $url, $component);
  128. }
  129. }