[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/components/com_content/views/article/ -> view.html.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: view.html.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla
   5   * @subpackage    Content
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant to the
   9   * GNU General Public License, and as distributed it includes or is derivative
  10   * of works licensed under the GNU General Public License or other free or open
  11   * source software licenses. See COPYRIGHT.php for copyright notices and
  12   * details.
  13   */
  14  
  15  // Check to ensure this file is included in Joomla!
  16  defined('_JEXEC') or die( 'Restricted access' );
  17  
  18  require_once (JPATH_COMPONENT.DS.'view.php');
  19  
  20  /**
  21   * HTML Article View class for the Content component
  22   *
  23   * @package        Joomla
  24   * @subpackage    Content
  25   * @since 1.5
  26   */
  27  class ContentViewArticle extends ContentView
  28  {
  29  	function display($tpl = null)
  30      {
  31          global $mainframe;
  32  
  33          $user        =& JFactory::getUser();
  34          $document    =& JFactory::getDocument();
  35          $dispatcher    =& JDispatcher::getInstance();
  36          $pathway    =& $mainframe->getPathway();
  37          $params        =& $mainframe->getParams('com_content');
  38  
  39          // Initialize variables
  40          $article    =& $this->get('Article');
  41          $aparams        =& $article->parameters;
  42          $params->merge($aparams);
  43  
  44          if($this->getLayout() == 'pagebreak') {
  45              $this->_displayPagebreak($tpl);
  46              return;
  47          }
  48  
  49          if($this->getLayout() == 'form') {
  50              $this->_displayForm($tpl);
  51              return;
  52          }
  53  
  54          if (($article->id == 0))
  55          {
  56              $id = JRequest::getVar( 'id', '', 'default', 'int' );
  57              return JError::raiseError( 404, JText::sprintf( 'Article # not found', $id ) );
  58          }
  59  
  60          $limitstart    = JRequest::getVar('limitstart', 0, '', 'int');
  61  
  62          if (!$params->get('intro_only') && ($this->getLayout() == 'default') && ($limitstart == 0))
  63          {
  64              $model =& $this->getModel();
  65              $model->hit();
  66          }
  67  
  68          // Create a user access object for the current user
  69          $access = new stdClass();
  70          $access->canEdit    = $user->authorize('com_content', 'edit', 'content', 'all');
  71          $access->canEditOwn    = $user->authorize('com_content', 'edit', 'content', 'own');
  72          $access->canPublish    = $user->authorize('com_content', 'publish', 'content', 'all');
  73  
  74          // Check to see if the user has access to view the full article
  75          $aid    = $user->get('aid');
  76  
  77          if ($article->access <= $aid) {
  78              $article->readmore_link = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->sectionid));;
  79          } else {
  80              if ( ! $aid )
  81              {
  82                  // Redirect to login
  83                  $uri        = JFactory::getURI();
  84                  $return        = $uri->toString();
  85  
  86                  $url  = 'index.php?option=com_user&view=login';
  87                  $url .= '&return='.base64_encode($return);;
  88  
  89                  //$url    = JRoute::_($url, false);
  90                  $mainframe->redirect($url, JText::_('You must login first') );
  91              }
  92              else{
  93                  JError::raiseWarning( 403, JText::_('ALERTNOTAUTH') );
  94                  return;
  95              }
  96          }
  97  
  98          /*
  99           * Process the prepare content plugins
 100           */
 101          JPluginHelper::importPlugin('content');
 102          $results = $dispatcher->trigger('onPrepareContent', array (& $article, & $params, $limitstart));
 103  
 104          /*
 105           * Handle the metadata
 106           */
 107          // because the application sets a default page title, we need to get it
 108          // right from the menu item itself
 109          // Get the menu item object
 110          $menus = &JSite::getMenu();
 111          $menu  = $menus->getActive();
 112  
 113          if (is_object( $menu ) && isset($menu->query['view']) && $menu->query['view'] == 'article' && isset($menu->query['id']) && $menu->query['id'] == $article->id) {
 114              $menu_params = new JParameter( $menu->params );
 115              if (!$menu_params->get( 'page_title')) {
 116                  $params->set('page_title',    $article->title);
 117              }
 118          } else {
 119              $params->set('page_title',    $article->title);
 120          }
 121          $document->setTitle( $params->get( 'page_title' ) );
 122  
 123          if ($article->metadesc) {
 124              $document->setDescription( $article->metadesc );
 125          }
 126          if ($article->metakey) {
 127              $document->setMetadata('keywords', $article->metakey);
 128          }
 129  
 130          if ($mainframe->getCfg('MetaTitle') == '1') {
 131              $mainframe->addMetaTag('title', $article->title);
 132          }
 133          if ($mainframe->getCfg('MetaAuthor') == '1') {
 134              $mainframe->addMetaTag('author', $article->author);
 135          }
 136  
 137          $mdata = new JParameter($article->metadata);
 138          $mdata = $mdata->toArray();
 139          foreach ($mdata as $k => $v)
 140          {
 141              if ($v) {
 142                  $document->setMetadata($k, $v);
 143              }
 144          }
 145  
 146          // If there is a pagebreak heading or title, add it to the page title
 147          if (!empty($article->page_title))
 148          {
 149              $article->title = $article->title .' - '. $article->page_title;
 150              $document->setTitle($article->page_title.' - '.JText::sprintf('Page %s', $limitstart + 1));
 151          }
 152  
 153          /*
 154           * Handle the breadcrumbs
 155           */
 156          if($menu && $menu->query['view'] != 'article')
 157          {
 158              switch ($menu->query['view'])
 159              {
 160                  case 'section':
 161                      $pathway->addItem($article->category, 'index.php?view=category&id='.$article->catslug);
 162                      $pathway->addItem($article->title, '');
 163                      break;
 164                  case 'category':
 165                      $pathway->addItem($article->title, '');
 166                      break;
 167              }
 168          }
 169  
 170          /*
 171           * Handle display events
 172           */
 173          $article->event = new stdClass();
 174          $results = $dispatcher->trigger('onAfterDisplayTitle', array (&$article, &$params, $limitstart));
 175          $article->event->afterDisplayTitle = trim(implode("\n", $results));
 176  
 177          $results = $dispatcher->trigger('onBeforeDisplayContent', array (&$article, &$params, $limitstart));
 178          $article->event->beforeDisplayContent = trim(implode("\n", $results));
 179  
 180          $results = $dispatcher->trigger('onAfterDisplayContent', array (&$article, &$params, $limitstart));
 181          $article->event->afterDisplayContent = trim(implode("\n", $results));
 182  
 183          $print = JRequest::getBool('print');
 184          if ($print) {
 185              $document->setMetaData('robots', 'noindex, nofollow');
 186          }
 187  
 188          $this->assignRef('article', $article);
 189          $this->assignRef('params' , $params);
 190          $this->assignRef('user'   , $user);
 191          $this->assignRef('access' , $access);
 192          $this->assignRef('print', $print);
 193  
 194          parent::display($tpl);
 195      }
 196  
 197  	function _displayForm($tpl)
 198      {
 199          global $mainframe;
 200  
 201          // Initialize variables
 202          $document    =& JFactory::getDocument();
 203          $user        =& JFactory::getUser();
 204          $uri        =& JFactory::getURI();
 205          $params        =& $mainframe->getParams('com_content');
 206  
 207          // Make sure you are logged in and have the necessary access rights
 208          if ($user->get('gid') < 19) {
 209              JResponse::setHeader('HTTP/1.0 403',true);
 210                JError::raiseWarning( 403, JText::_('ALERTNOTAUTH') );
 211              return;
 212          }
 213  
 214          // Initialize variables
 215          $article    =& $this->get('Article');
 216          $aparams    =& $article->parameters;
 217          $isNew        = ($article->id < 1);
 218  
 219          $params->merge($aparams);
 220  
 221          // At some point in the future this will come from a request object
 222          $limitstart    = JRequest::getVar('limitstart', 0, '', 'int');
 223  
 224          // Add the Calendar includes to the document <head> section
 225          JHTML::_('behavior.calendar');
 226  
 227          if ($isNew)
 228          {
 229              // TODO: Do we allow non-sectioned articles from the frontend??
 230              $article->sectionid = JRequest::getVar('sectionid', 0, '', 'int');
 231              $db = JFactory::getDBO();
 232              $db->setQuery('SELECT title FROM #__sections WHERE id = '.(int) $article->sectionid);
 233              $article->section = $db->loadResult();
 234          }
 235  
 236          // Get the lists
 237          $lists = $this->_buildEditLists();
 238  
 239          // Load the JEditor object
 240          $editor =& JFactory::getEditor();
 241  
 242          // Build the page title string
 243          $title = $article->id ? JText::_('Edit') : JText::_('New');
 244  
 245          // Set page title
 246          // because the application sets a default page title, we need to get it
 247          // right from the menu item itself
 248          // Get the menu item object
 249          $menus = &JSite::getMenu();
 250          $menu  = $menus->getActive();
 251          $params->set( 'page_title', $params->get( 'page_title' ) );
 252          if (is_object( $menu )) {
 253              $menu_params = new JParameter( $menu->params );
 254              if (!$menu_params->get( 'page_title')) {
 255                  $params->set('page_title',    JText::_( 'Submit an Article' ));
 256              }
 257          } else {
 258              $params->set('page_title', JText::_( 'Submit an Article' ));
 259          }
 260          $document->setTitle( $params->get( 'page_title' ) );
 261  
 262          // get pathway
 263          $pathway =& $mainframe->getPathWay();
 264          $pathway->addItem($title, '');
 265  
 266          // Unify the introtext and fulltext fields and separated the fields by the {readmore} tag
 267          if (JString::strlen($article->fulltext) > 1) {
 268              $article->text = $article->introtext."<hr id=\"system-readmore\" />".$article->fulltext;
 269          } else {
 270              $article->text = $article->introtext;
 271          }
 272  
 273          $this->assign('action',     $uri->toString());
 274  
 275          $this->assignRef('article',    $article);
 276          $this->assignRef('params',    $params);
 277          $this->assignRef('lists',    $lists);
 278          $this->assignRef('editor',    $editor);
 279          $this->assignRef('user',    $user);
 280  
 281  
 282          parent::display($tpl);
 283      }
 284  
 285  	function _buildEditLists()
 286      {
 287          // Get the article and database connector from the model
 288          $article = & $this->get('Article');
 289          $db      = & JFactory::getDBO();
 290  
 291          $javascript = "onchange=\"changeDynaList( 'catid', sectioncategories, document.adminForm.sectionid.options[document.adminForm.sectionid.selectedIndex].value, 0, 0);\"";
 292  
 293          $query = 'SELECT s.id, s.title' .
 294                  ' FROM #__sections AS s' .
 295                  ' ORDER BY s.ordering';
 296          $db->setQuery($query);
 297  
 298          $sections[] = JHTML::_('select.option', '-1', '- '.JText::_('Select Section').' -', 'id', 'title');
 299          $sections[] = JHTML::_('select.option', '0', JText::_('Uncategorized'), 'id', 'title');
 300          $sections = array_merge($sections, $db->loadObjectList());
 301          $lists['sectionid'] = JHTML::_('select.genericlist',  $sections, 'sectionid', 'class="inputbox" size="1" '.$javascript, 'id', 'title', intval($article->sectionid));
 302  
 303          foreach ($sections as $section)
 304          {
 305              $section_list[] = (int) $section->id;
 306              // get the type name - which is a special category
 307              if ($article->sectionid) {
 308                  if ($section->id == $article->sectionid) {
 309                      $contentSection = $section->title;
 310                  }
 311              } else {
 312                  if ($section->id == $article->sectionid) {
 313                      $contentSection = $section->title;
 314                  }
 315              }
 316          }
 317  
 318          $sectioncategories = array ();
 319          $sectioncategories[-1] = array ();
 320          $sectioncategories[-1][] = JHTML::_('select.option', '-1', JText::_( 'Select Category' ), 'id', 'title');
 321          $section_list = implode('\', \'', $section_list);
 322  
 323          $query = 'SELECT id, title, section' .
 324                  ' FROM #__categories' .
 325                  ' WHERE section IN ( \''.$section_list.'\' )' .
 326                  ' ORDER BY ordering';
 327          $db->setQuery($query);
 328          $cat_list = $db->loadObjectList();
 329  
 330          // Uncategorized category mapped to uncategorized section
 331          $uncat = new stdClass();
 332          $uncat->id = 0;
 333          $uncat->title = JText::_('Uncategorized');
 334          $uncat->section = 0;
 335          $cat_list[] = $uncat;
 336          foreach ($sections as $section)
 337          {
 338              $sectioncategories[$section->id] = array ();
 339              $rows2 = array ();
 340              foreach ($cat_list as $cat)
 341              {
 342                  if ($cat->section == $section->id) {
 343                      $rows2[] = $cat;
 344                  }
 345              }
 346              foreach ($rows2 as $row2) {
 347                  $sectioncategories[$section->id][] = JHTML::_('select.option', $row2->id, $row2->title, 'id', 'title');
 348              }
 349          }
 350  
 351          $categories = array();
 352          foreach ($cat_list as $cat) {
 353              if($cat->section == $article->sectionid)
 354                  $categories[] = $cat;
 355          }
 356  
 357          $categories[] = JHTML::_('select.option', '-1', JText::_( 'Select Category' ), 'id', 'title');
 358          $lists['sectioncategories'] = $sectioncategories;
 359          $lists['catid'] = JHTML::_('select.genericlist',  $categories, 'catid', 'class="inputbox" size="1"', 'id', 'title', intval($article->catid));
 360  
 361          // Select List: Category Ordering
 362          $query = 'SELECT ordering AS value, title AS text FROM #__content WHERE catid = '.(int) $article->catid.' AND state > ' .(int) "-1" . ' ORDER BY ordering';
 363          $lists['ordering'] = JHTML::_('list.specificordering', $article, $article->id, $query, 1);
 364  
 365          // Radio Buttons: Should the article be published
 366          $lists['state'] = JHTML::_('select.booleanlist', 'state', '', $article->state);
 367  
 368          // Radio Buttons: Should the article be added to the frontpage
 369          if($article->id) {
 370              $query = 'SELECT content_id FROM #__content_frontpage WHERE content_id = '. (int) $article->id;
 371              $db->setQuery($query);
 372              $article->frontpage = $db->loadResult();
 373          } else {
 374              $article->frontpage = 0;
 375          }
 376  
 377          $lists['frontpage'] = JHTML::_('select.booleanlist', 'frontpage', '', (boolean) $article->frontpage);
 378  
 379          // Select List: Group Access
 380          $lists['access'] = JHTML::_('list.accesslevel', $article);
 381  
 382          return $lists;
 383      }
 384  
 385  	function _displayPagebreak($tpl)
 386      {
 387          $document =& JFactory::getDocument();
 388          $document->setTitle(JText::_('PGB ARTICLE PAGEBRK'));
 389  
 390          parent::display($tpl);
 391      }
 392  }
 393  


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1